Java Code Examples for com.google.api.client.googleapis.batch.BatchRequest#queue()

The following examples show how to use com.google.api.client.googleapis.batch.BatchRequest#queue() . 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: FirebaseMessagingClientImpl.java    From firebase-admin-java with Apache License 2.0 6 votes vote down vote up
private BatchRequest newBatchRequest(
    List<Message> messages, boolean dryRun, MessagingBatchCallback callback) throws IOException {

  BatchRequest batch = new BatchRequest(
      requestFactory.getTransport(), getBatchRequestInitializer());
  batch.setBatchUrl(new GenericUrl(FCM_BATCH_URL));

  final JsonObjectParser jsonParser = new JsonObjectParser(this.jsonFactory);
  final GenericUrl sendUrl = new GenericUrl(fcmSendUrl);
  for (Message message : messages) {
    // Using a separate request factory without authorization is faster for large batches.
    // A simple performance test showed a 400-500ms speed up for batches of 1000 messages.
    HttpRequest request = childRequestFactory.buildPostRequest(
        sendUrl,
        new JsonHttpContent(jsonFactory, message.wrapForTransport(dryRun)));
    request.setParser(jsonParser);
    setCommonFcmHeaders(request.getHeaders());
    batch.queue(
        request, MessagingServiceResponse.class, MessagingServiceErrorResponse.class, callback);
  }
  return batch;
}
 
Example 2
Source File: AbstractGoogleClientRequest.java    From google-api-java-client with Apache License 2.0 3 votes vote down vote up
/**
 * Queues the request into the specified batch request container using the specified error class.
 *
 * <p>
 * Batched requests are then executed when {@link BatchRequest#execute()} is called.
 * </p>
 *
 * @param batchRequest batch request container
 * @param errorClass data class the unsuccessful response will be parsed into or
 *        {@code Void.class} to ignore the content
 * @param callback batch callback
 */
public final <E> void queue(
    BatchRequest batchRequest, Class<E> errorClass, BatchCallback<T, E> callback)
    throws IOException {
  Preconditions.checkArgument(uploader == null, "Batching media requests is not supported");
  batchRequest.queue(buildHttpRequest(), getResponseClass(), errorClass, callback);
}