com.google.api.client.googleapis.batch.json.JsonBatchCallback Java Examples
The following examples show how to use
com.google.api.client.googleapis.batch.json.JsonBatchCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleWebmasterDataFetcherImpl.java From incubator-gobblin with Apache License 2.0 | 6 votes |
@Override public void performSearchAnalyticsQueryInBatch(List<ProducerJob> jobs, List<ArrayList<ApiDimensionFilter>> filterList, List<JsonBatchCallback<SearchAnalyticsQueryResponse>> callbackList, List<Dimension> requestedDimensions, int rowLimit) throws IOException { BatchRequest batchRequest = _client.createBatch(); for (int i = 0; i < jobs.size(); ++i) { ProducerJob job = jobs.get(i); ArrayList<ApiDimensionFilter> filters = filterList.get(i); JsonBatchCallback<SearchAnalyticsQueryResponse> callback = callbackList.get(i); _client.createSearchAnalyticsQuery(_siteProperty, job.getStartDate(), job.getEndDate(), requestedDimensions, GoogleWebmasterFilter.andGroupFilters(filters), rowLimit, 0).queue(batchRequest, callback); } batchRequest.execute(); }
Example #2
Source File: BatchHelper.java From hadoop-connectors with Apache License 2.0 | 6 votes |
/** * Adds an additional request to the batch, and possibly flushes the current contents of the batch * if {@code maxRequestsPerBatch} has been reached. */ public <T> void queue(StorageRequest<T> req, JsonBatchCallback<T> callback) throws IOException { checkState( !requestsExecutor.isShutdown() && !requestsExecutor.isTerminated(), "requestsExecutor should not be terminated to queue batch requests"); if (maxRequestsPerBatch == 1) { responseFutures.add( requestsExecutor.submit( () -> { execute(req, callback); return null; })); } else { pendingRequests.add(batch -> req.queue(batch, callback)); flushIfPossibleAndRequired(); } }
Example #3
Source File: BatchHelperTest.java From hadoop-connectors with Apache License 2.0 | 6 votes |
@Test public void queue_throwsException_afterFlushMethodWasCalled() throws IOException { String objectName1 = OBJECT_NAME + "-01"; StorageObject object1 = newStorageObject(BUCKET_NAME, objectName1); MockHttpTransport transport = mockBatchTransport(/* requestsPerBatch= */ 1, jsonDataResponse(object1)); Storage storage = new Storage(transport, JSON_FACTORY, httpRequestInitializer); BatchHelper batchHelper = batchFactory.newBatchHelper(httpRequestInitializer, storage, /* maxRequestsPerBatch= */ 1); batchHelper.flush(); Storage.Objects.Get request = storage.objects().get(BUCKET_NAME, objectName1); JsonBatchCallback<StorageObject> callback = assertCallback(object1); IllegalStateException e = assertThrows(IllegalStateException.class, () -> batchHelper.queue(request, callback)); assertThat(e) .hasMessageThat() .startsWith("requestsExecutor should not be terminated to queue batch requests"); assertThat(httpRequestInitializer.getAllRequests()).isEmpty(); }
Example #4
Source File: BatchRequestService.java From connector-sdk with Apache License 2.0 | 5 votes |
<T> void queue( BatchRequest batchRequest, AbstractGoogleJsonClientRequest<T> request, JsonBatchCallback<T> jsonCallback) throws IOException { request.queue(batchRequest, jsonCallback); }
Example #5
Source File: BatchHelper.java From hadoop-connectors with Apache License 2.0 | 5 votes |
private static <T> void execute(StorageRequest<T> req, JsonBatchCallback<T> callback) throws IOException { try { T result = req.execute(); callback.onSuccess(result, req.getLastResponseHeaders()); } catch (IOException e) { GoogleJsonResponseException jsonException = ApiErrorExtractor.getJsonResponseException(e); if (jsonException == null) { throw e; } callback.onFailure(jsonException.getDetails(), jsonException.getHeaders()); } }
Example #6
Source File: GoogleWebmasterDataFetcher.java From incubator-gobblin with Apache License 2.0 | 4 votes |
/** * Call API in batches */ public abstract void performSearchAnalyticsQueryInBatch(List<ProducerJob> jobs, List<ArrayList<ApiDimensionFilter>> filterList, List<JsonBatchCallback<SearchAnalyticsQueryResponse>> callbackList, List<GoogleWebmasterFilter.Dimension> requestedDimensions, int rowLimit) throws IOException;
Example #7
Source File: AbstractGoogleJsonClientRequest.java From google-api-java-client with Apache License 2.0 | votes |
/** * Queues the request into the specified batch request container. * * <p> * Batched requests are then executed when {@link BatchRequest#execute()} is called. * </p> * <p> * Example usage: * </p> * * <pre> request.queue(batchRequest, new JsonBatchCallback<SomeResponseType>() { public void onSuccess(SomeResponseType content, HttpHeaders responseHeaders) { log("Success"); } public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) { log(e.getMessage()); } }); * </pre> * * * @param batchRequest batch request container * @param callback batch callback */ public final void queue(BatchRequest batchRequest, JsonBatchCallback<T> callback) throws IOException { super.queue(batchRequest, GoogleJsonErrorContainer.class, callback); }