use of com.google.api.gax.paging.AsyncPage in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImpl method listLogEntriesAsync.
private static ApiFuture<AsyncPage<LogEntry>> listLogEntriesAsync(final LoggingOptions serviceOptions, final Map<Option.OptionType, ?> options) {
final ListLogEntriesRequest request = listLogEntriesRequest(serviceOptions, options);
ApiFuture<ListLogEntriesResponse> list = serviceOptions.getLoggingRpcV2().list(request);
return transform(list, new Function<ListLogEntriesResponse, AsyncPage<LogEntry>>() {
@Override
public AsyncPage<LogEntry> apply(ListLogEntriesResponse listLogEntrysResponse) {
List<LogEntry> entries = listLogEntrysResponse.getEntriesList() == null ? ImmutableList.<LogEntry>of() : Lists.transform(listLogEntrysResponse.getEntriesList(), LogEntry.FROM_PB_FUNCTION);
String cursor = listLogEntrysResponse.getNextPageToken().equals("") ? null : listLogEntrysResponse.getNextPageToken();
return new AsyncPageImpl<>(new LogEntryPageFetcher(serviceOptions, cursor, options), cursor, entries);
}
});
}
use of com.google.api.gax.paging.AsyncPage in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImpl method listMetricsAsync.
private static ApiFuture<AsyncPage<Metric>> listMetricsAsync(final LoggingOptions serviceOptions, final Map<Option.OptionType, ?> options) {
final ListLogMetricsRequest request = listMetricsRequest(serviceOptions, options);
ApiFuture<ListLogMetricsResponse> list = serviceOptions.getLoggingRpcV2().list(request);
return transform(list, new Function<ListLogMetricsResponse, AsyncPage<Metric>>() {
@Override
public AsyncPage<Metric> apply(ListLogMetricsResponse listMetricsResponse) {
List<Metric> metrics = listMetricsResponse.getMetricsList() == null ? ImmutableList.<Metric>of() : Lists.transform(listMetricsResponse.getMetricsList(), Metric.fromPbFunction(serviceOptions.getService()));
String cursor = listMetricsResponse.getNextPageToken().equals("") ? null : listMetricsResponse.getNextPageToken();
return new AsyncPageImpl<>(new MetricPageFetcher(serviceOptions, cursor, options), cursor, metrics);
}
});
}
use of com.google.api.gax.paging.AsyncPage in project google-cloud-java by GoogleCloudPlatform.
the class LoggingSnippets method listMonitoredResourceDescriptorsAsync.
/**
* Example of asynchronously listing monitored resource descriptors, specifying the page size.
*/
// [TARGET listMonitoredResourceDescriptorsAsync(ListOption...)]
public Page<MonitoredResourceDescriptor> listMonitoredResourceDescriptorsAsync() throws ExecutionException, InterruptedException {
// [START listMonitoredResourceDescriptorsAsync]
Future<AsyncPage<MonitoredResourceDescriptor>> future = logging.listMonitoredResourceDescriptorsAsync(ListOption.pageSize(100));
// ...
AsyncPage<MonitoredResourceDescriptor> descriptors = future.get();
for (MonitoredResourceDescriptor descriptor : descriptors.iterateAll()) {
// do something with the descriptor
}
// [END listMonitoredResourceDescriptorsAsync]
return descriptors;
}
use of com.google.api.gax.paging.AsyncPage in project google-cloud-java by GoogleCloudPlatform.
the class LoggingSnippets method listSinksAsync.
/**
* Example of asynchronously listing sinks, specifying the page size.
*/
// [TARGET listSinksAsync(ListOption...)]
public Page<Sink> listSinksAsync() throws ExecutionException, InterruptedException {
// [START listSinksAsync]
Future<AsyncPage<Sink>> future = logging.listSinksAsync(ListOption.pageSize(100));
// ...
AsyncPage<Sink> sinks = future.get();
for (Sink sink : sinks.iterateAll()) {
// do something with the sink
}
// [END listSinksAsync]
return sinks;
}
use of com.google.api.gax.paging.AsyncPage in project google-cloud-java by GoogleCloudPlatform.
the class LoggingSnippets method listMetricsAsync.
/**
* Example of asynchronously listing metrics, specifying the page size.
*/
// [TARGET listMetricsAsync(ListOption...)]
public Page<Metric> listMetricsAsync() throws ExecutionException, InterruptedException {
// [START listMetricsAsync]
Future<AsyncPage<Metric>> future = logging.listMetricsAsync(ListOption.pageSize(100));
// ...
AsyncPage<Metric> metrics = future.get();
for (Metric metric : metrics.iterateAll()) {
// do something with the metric
}
// [END listMetricsAsync]
return metrics;
}
Aggregations