use of com.arm.mbed.cloud.sdk.internal.statistics.model.SuccessfulResponse in project mbed-cloud-sdk-java by ARMmbed.
the class Connect method listMetrics.
/**
* Lists metrics.
* <p>
* Example:
*
* <pre>
* {@code
* try {
* Calendar startDate = GregorianCalendar(2017,10,30,10,20,56);
* Calendar endDate = GregorianCalendar(2017,11,31,10,20,56);
*
* MetricsStartEndListOptions listOptions = new MetricsStartEndListOptions();
* listOptions.setStart(startDate.getTime());
* listOptions.setEnd(endDate.getTime());
* listOptions.setInterval(new TimePeriod(360)); //Once an hour
*
* ListResponse<Metric> metrics = connectApi.listMetrics(listOptions);
* //Iterates over a page
* for (Metric metric : metrics.getData()) {
* System.out.println("Time: " + dateFormat.format(metric.getTimestamp()));
* System.out.println("Successful bootstraps: " + metric.getSuccessfulBootstraps());
* System.out.println("Successful api calls: " + metric.getSuccessfulApiCalls());
* System.out.println("");
* }
* } catch (MbedCloudException e) {
* e.printStackTrace();
* }
* }
* </pre>
*
* @param options
* metrics options.
* @param <T>
* Type of metrics list options
* @return list of metrics for the corresponding options.
* @throws MbedCloudException
* if a problem occurred during request processing.
*/
@API
@Nullable
public <T extends AbstractMetricsListOptions> ListResponse<Metric> listMetrics(@NonNull T options) throws MbedCloudException {
checkNotNull(options, TAG_METRIC_OPTIONS);
final T finalOptions = options;
final Date finalStart = options instanceof MetricsStartEndListOptions ? ((MetricsStartEndListOptions) options).getStart() : null;
final Date finalEnd = options instanceof MetricsStartEndListOptions ? ((MetricsStartEndListOptions) options).getEnd() : null;
final String finalPeriod = options instanceof MetricsPeriodListOptions ? ((MetricsPeriodListOptions) options).getPeriod().toString() : null;
return CloudCaller.call(this, "listMetrics()", MetricAdapter.getListMapper(), new CloudCall<SuccessfulResponse>() {
@Override
public Call<SuccessfulResponse> call() {
return endpoint.getStatistic().v3MetricsGet(MetricAdapter.mapIncludes(finalOptions.getInclude()), finalOptions.getInterval().toString(), TranslationUtils.toLocalDate(finalStart), TranslationUtils.toLocalDate(finalEnd), finalPeriod, finalOptions.getLimit(), finalOptions.getAfter(), finalOptions.getOrder().toString());
}
});
}
use of com.arm.mbed.cloud.sdk.internal.statistics.model.SuccessfulResponse in project mbed-cloud-sdk-java by ARMmbed.
the class MetricAdapter method mapList.
/**
* Maps a list of metrics.
*
* @param list
* of metrics.
* @return list of metrics
*/
public static ListResponse<Metric> mapList(SuccessfulResponse list) {
final SuccessfulResponse metricsList = list;
final RespList<com.arm.mbed.cloud.sdk.internal.statistics.model.Metric> respList = new RespList<com.arm.mbed.cloud.sdk.internal.statistics.model.Metric>() {
@Override
public Boolean getHasMore() {
return (metricsList == null) ? null : metricsList.isHasMore();
}
@Override
public Integer getTotalCount() {
return (metricsList == null) ? null : metricsList.getTotalCount();
}
@Override
public String getAfter() {
return (metricsList == null) ? null : metricsList.getAfter();
}
@Override
public Integer getLimit() {
return (metricsList == null) ? null : metricsList.getLimit();
}
@Override
public String getOrder() {
return Order.getDefault().getString();
}
@Override
public List<com.arm.mbed.cloud.sdk.internal.statistics.model.Metric> getData() {
return (metricsList == null) ? null : metricsList.getData();
}
};
return GenericAdapter.mapList(respList, getMapper());
}
Aggregations