use of com.amazonaws.services.cloudwatch.model.ListMetricsResult in project iep by Netflix.
the class PaginationTest method cloudwatch.
@Test
public void cloudwatch() throws Exception {
SortedSet<String> pages = newPageSet(5);
final Iterator<String> reqIt = pages.iterator();
final Iterator<String> resIt = pages.iterator();
Function<ListMetricsRequest, ListMetricsResult> f = r -> {
if (r.getNextToken() != null) {
Assert.assertEquals(reqIt.next(), r.getNextToken());
}
return new ListMetricsResult().withNextToken(resIt.hasNext() ? resIt.next() : null);
};
Publisher<ListMetricsResult> publisher = Pagination.createPublisher(new ListMetricsRequest(), f);
Iterable<String> iter = Flowable.fromPublisher(publisher).filter(r -> r.getNextToken() != null).map(ListMetricsResult::getNextToken).blockingIterable();
SortedSet<String> results = new TreeSet<>();
for (String s : iter) {
results.add(s);
}
Assert.assertEquals(pages, results);
Assert.assertFalse(reqIt.hasNext());
}
use of com.amazonaws.services.cloudwatch.model.ListMetricsResult in project aws-doc-sdk-examples by awsdocs.
the class ListMetrics method main.
public static void main(String[] args) {
final String USAGE = "To run this example, supply a metric name and metric namespace\n" + "Ex: ListMetrics <metric-name> <metric-namespace>\n";
if (args.length != 2) {
System.out.println(USAGE);
System.exit(1);
}
String name = args[0];
String namespace = args[1];
final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient();
boolean done = false;
while (!done) {
ListMetricsRequest request = new ListMetricsRequest().withMetricName(name).withNamespace(namespace);
ListMetricsResult response = cw.listMetrics(request);
for (Metric metric : response.getMetrics()) {
System.out.printf("Retrieved metric %s", metric.getMetricName());
}
request.setNextToken(response.getNextToken());
if (response.getNextToken() == null) {
done = true;
}
}
}
Aggregations