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 {
/**
* 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);
public static Iterable<Metric> listMetrics(final MetricClient metricClient, final ListMetricsOptions options) {
return new Iterable<Metric>() {
public Iterator<Metric> iterator() {
return new AbstractIterator<Metric>() {
private ListMetricsOptions lastOptions = options;
private ListMetricsResponse response = metricClientForRegion.listMetrics(lastOptions);
private ListMetricsResponse response = metricClient.listMetrics(lastOptions);
private Iterator<Metric> 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<Metric> listMetrics(CloudWatchClient cloudWatchClient, String region,
final ListMetricsOptions options) {
return listMetrics(cloudWatchClient.getMetricClientForRegion(region), options);
}
}