use of com.google.api.gax.paging.AsyncPage in project google-cloud-java by GoogleCloudPlatform.
the class LoggingSnippets method listLogEntriesAsync.
/**
* Example of asynchronously listing log entries for a specific log.
*/
// [TARGET listLogEntriesAsync(EntryListOption...)]
// [VARIABLE "logName=projects/my_project_id/logs/my_log_name"]
public Page<LogEntry> listLogEntriesAsync(String filter) throws ExecutionException, InterruptedException {
// [START listLogEntriesAsync]
Future<AsyncPage<LogEntry>> future = logging.listLogEntriesAsync(EntryListOption.filter(filter));
// ...
AsyncPage<LogEntry> entries = future.get();
for (LogEntry entry : entries.iterateAll()) {
// do something with the entry
}
// [END listLogEntriesAsync]
return entries;
}
use of com.google.api.gax.paging.AsyncPage in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImpl method listMonitoredResourceDescriptorsAsync.
private static ApiFuture<AsyncPage<MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsAsync(final LoggingOptions serviceOptions, final Map<Option.OptionType, ?> options) {
final ListMonitoredResourceDescriptorsRequest request = listMonitoredResourceDescriptorsRequest(options);
ApiFuture<ListMonitoredResourceDescriptorsResponse> list = serviceOptions.getLoggingRpcV2().list(request);
return transform(list, new Function<ListMonitoredResourceDescriptorsResponse, AsyncPage<MonitoredResourceDescriptor>>() {
@Override
public AsyncPage<MonitoredResourceDescriptor> apply(ListMonitoredResourceDescriptorsResponse listDescriptorsResponse) {
List<MonitoredResourceDescriptor> descriptors = listDescriptorsResponse.getResourceDescriptorsList() == null ? ImmutableList.<MonitoredResourceDescriptor>of() : Lists.transform(listDescriptorsResponse.getResourceDescriptorsList(), new Function<com.google.api.MonitoredResourceDescriptor, MonitoredResourceDescriptor>() {
@Override
public MonitoredResourceDescriptor apply(com.google.api.MonitoredResourceDescriptor monitoredResourceDescriptor) {
return MonitoredResourceDescriptor.FROM_PB_FUNCTION.apply(monitoredResourceDescriptor);
}
});
String cursor = listDescriptorsResponse.getNextPageToken().equals("") ? null : listDescriptorsResponse.getNextPageToken();
return new AsyncPageImpl<>(new MonitoredResourceDescriptorPageFetcher(serviceOptions, cursor, options), cursor, descriptors);
}
});
}
use of com.google.api.gax.paging.AsyncPage in project google-cloud-java by GoogleCloudPlatform.
the class LoggingImpl method listSinksAsync.
private static ApiFuture<AsyncPage<Sink>> listSinksAsync(final LoggingOptions serviceOptions, final Map<Option.OptionType, ?> options) {
final ListSinksRequest request = listSinksRequest(serviceOptions, options);
ApiFuture<ListSinksResponse> list = serviceOptions.getLoggingRpcV2().list(request);
return transform(list, new Function<ListSinksResponse, AsyncPage<Sink>>() {
@Override
public AsyncPage<Sink> apply(ListSinksResponse listSinksResponse) {
List<Sink> sinks = listSinksResponse.getSinksList() == null ? ImmutableList.<Sink>of() : Lists.transform(listSinksResponse.getSinksList(), Sink.fromPbFunction(serviceOptions.getService()));
String cursor = listSinksResponse.getNextPageToken().equals("") ? null : listSinksResponse.getNextPageToken();
return new AsyncPageImpl<>(new SinkPageFetcher(serviceOptions, cursor, options), cursor, sinks);
}
});
}
Aggregations