Merge pull request #622 from jcscoobyrs/master

Issue 922: Create CloudWatch.listMetrics(MetricClient, ListMetricsOptions) API.
This commit is contained in:
Adrian Cole 2012-05-09 18:29:35 -07:00
commit c7f949d1c1
1 changed files with 17 additions and 14 deletions

View File

@ -33,24 +33,13 @@ import java.util.Iterator;
*/ */
public class CloudWatch { public class CloudWatch {
/** public static Iterable<Metric> listMetrics(final MetricClient metricClient, final ListMetricsOptions options) {
* List metrics based on the criteria in the {@link ListMetricsOptions} passed in.
*
* @param cloudWatchClient the CloudWatch client
* @param region the region to list metrics in
* @param options the options describing the ListMetrics request
*
* @return iterable of metrics fitting the criteria
*/
public static Iterable<Metric> listMetrics(CloudWatchClient cloudWatchClient, String region,
final ListMetricsOptions options) {
final MetricClient metricClientForRegion = cloudWatchClient.getMetricClientForRegion(region);
return new Iterable<Metric>() { return new Iterable<Metric>() {
public Iterator<Metric> iterator() { public Iterator<Metric> iterator() {
return new AbstractIterator<Metric>() { return new AbstractIterator<Metric>() {
private ListMetricsOptions lastOptions = options; private ListMetricsOptions lastOptions = options;
private ListMetricsResponse response = metricClientForRegion.listMetrics(lastOptions); private ListMetricsResponse response = metricClient.listMetrics(lastOptions);
private Iterator<Metric> iterator = response.iterator(); private Iterator<Metric> iterator = response.iterator();
/** /**
@ -66,7 +55,7 @@ public class CloudWatch {
.namespace(lastOptions.getNamespace()) .namespace(lastOptions.getNamespace())
.nextToken(response.getNextToken()) .nextToken(response.getNextToken())
.build(); .build();
response = metricClientForRegion.listMetrics(lastOptions); response = metricClient.listMetrics(lastOptions);
iterator = response.iterator(); iterator = response.iterator();
} }
if (iterator.hasNext()) { if (iterator.hasNext()) {
@ -84,4 +73,18 @@ public class CloudWatch {
}; };
} }
/**
* List metrics based on the criteria in the {@link ListMetricsOptions} passed in.
*
* @param cloudWatchClient the CloudWatch client
* @param region the region to list metrics in
* @param options the options describing the ListMetrics request
*
* @return iterable of metrics fitting the criteria
*/
public static Iterable<Metric> listMetrics(CloudWatchClient cloudWatchClient, String region,
final ListMetricsOptions options) {
return listMetrics(cloudWatchClient.getMetricClientForRegion(region), options);
}
} }