Search in sources :

Example 1 with AsyncPage

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

Example 2 with AsyncPage

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

Example 3 with AsyncPage

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

Example 4 with AsyncPage

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

Example 5 with AsyncPage

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;
}
Also used : Metric(com.google.cloud.logging.Metric) 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