diff --git a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatch.java b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatch.java index e544a8a411..32f1bcec1f 100644 --- a/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatch.java +++ b/apis/cloudwatch/src/main/java/org/jclouds/cloudwatch/CloudWatch.java @@ -33,24 +33,13 @@ import java.util.Iterator; */ 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 listMetrics(CloudWatchClient cloudWatchClient, String region, - final ListMetricsOptions options) { - final MetricClient metricClientForRegion = cloudWatchClient.getMetricClientForRegion(region); + public static Iterable listMetrics(final MetricClient metricClient, final ListMetricsOptions options) { return new Iterable() { public Iterator iterator() { return new AbstractIterator() { private ListMetricsOptions lastOptions = options; - private ListMetricsResponse response = metricClientForRegion.listMetrics(lastOptions); + private ListMetricsResponse response = metricClient.listMetrics(lastOptions); private Iterator iterator = response.iterator(); /** @@ -66,7 +55,7 @@ public class CloudWatch { .namespace(lastOptions.getNamespace()) .nextToken(response.getNextToken()) .build(); - response = metricClientForRegion.listMetrics(lastOptions); + response = metricClient.listMetrics(lastOptions); iterator = response.iterator(); } 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 listMetrics(CloudWatchClient cloudWatchClient, String region, + final ListMetricsOptions options) { + return listMetrics(cloudWatchClient.getMetricClientForRegion(region), options); + } + }