Example #1
0
  @Override
  public PagedIterable<T> apply(ListPage<T> input) {
    if (input.nextMarker() == null) return PagedIterables.of(input);

    Optional<Object> project =
        tryFind(request.getCaller().get().getArgs(), instanceOf(String.class));

    Optional<Object> listOptions =
        tryFind(request.getInvocation().getArgs(), instanceOf(ListOptions.class));

    assert project.isPresent()
        : String.format(
            "programming error, method %s should have a string param for the " + "project",
            request.getCaller().get().getInvokable());

    return PagedIterables.advance(
        input,
        fetchNextPage(
            project.get().toString(),
            (String) input.nextMarker().orNull(),
            (ListOptions) listOptions.orNull()));
  }
Example #2
0
  /**
   * List metrics based on the criteria in the {@link ListMetricsOptions} passed in.
   *
   * @param metricApi the {@link MetricApi} to use for the request
   * @param options the {@link ListMetricsOptions} describing the ListMetrics request
   * @return iterable of metrics fitting the criteria
   */
  public static Iterable<Metric> listMetrics(
      final MetricApi metricApi, final ListMetricsOptions options) {
    return Iterables.concat(
        PagedIterables.advance(
            metricApi.list(options),
            new Function<Object, IterableWithMarker<Metric>>() {

              @Override
              public IterableWithMarker<Metric> apply(Object input) {
                return metricApi.list(options.clone().afterMarker(input));
              }

              @Override
              public String toString() {
                return "listMetrics(" + options + ")";
              }
            }));
  }