Search in sources :

Example 6 with AsyncPage

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;
}
Also used : AsyncPage(com.google.api.gax.paging.AsyncPage) LogEntry(com.google.cloud.logging.LogEntry)

Example 7 with AsyncPage

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);
        }
    });
}
Also used : MonitoredResourceDescriptor(com.google.cloud.MonitoredResourceDescriptor) AsyncPage(com.google.api.gax.paging.AsyncPage) ListMonitoredResourceDescriptorsResponse(com.google.logging.v2.ListMonitoredResourceDescriptorsResponse) ListMonitoredResourceDescriptorsRequest(com.google.logging.v2.ListMonitoredResourceDescriptorsRequest) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Example 8 with AsyncPage

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);
        }
    });
}
Also used : ListSinksResponse(com.google.logging.v2.ListSinksResponse) ListSinksRequest(com.google.logging.v2.ListSinksRequest) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) AsyncPage(com.google.api.gax.paging.AsyncPage)

Aggregations

AsyncPage (com.google.api.gax.paging.AsyncPage)8 ImmutableList (com.google.common.collect.ImmutableList)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 MonitoredResourceDescriptor (com.google.cloud.MonitoredResourceDescriptor)2 LogEntry (com.google.cloud.logging.LogEntry)1 Metric (com.google.cloud.logging.Metric)1 Sink (com.google.cloud.logging.Sink)1 ListLogEntriesRequest (com.google.logging.v2.ListLogEntriesRequest)1 ListLogEntriesResponse (com.google.logging.v2.ListLogEntriesResponse)1 ListLogMetricsRequest (com.google.logging.v2.ListLogMetricsRequest)1 ListLogMetricsResponse (com.google.logging.v2.ListLogMetricsResponse)1 ListMonitoredResourceDescriptorsRequest (com.google.logging.v2.ListMonitoredResourceDescriptorsRequest)1 ListMonitoredResourceDescriptorsResponse (com.google.logging.v2.ListMonitoredResourceDescriptorsResponse)1 ListSinksRequest (com.google.logging.v2.ListSinksRequest)1 ListSinksResponse (com.google.logging.v2.ListSinksResponse)1