Package com.google.api.client.googleapis.batch (2.0.1)

Batch for Google API's.

Classes

BatchRequest

An instance of this class represents a single batch of requests.

Sample use:


 // client is a AbstractGoogleClient (e.g.
 // com.google.api.services.books.Books)
 BatchRequest batch = client.batch(httpRequestInitializer);
 batch.queue(volumesList, Volumes.class, GoogleJsonErrorContainer.class,
     new BatchCallback<Volumes, GoogleJsonErrorContainer>() {

       public void onSuccess(Volumes volumes, HttpHeaders responseHeaders) {
         log("Success");
         printVolumes(volumes.getItems());
       }

       public void onFailure(GoogleJsonErrorContainer e, HttpHeaders responseHeaders) {
         log(e.getError().getMessage());
       }
     });
 batch.queue(volumesList, Volumes.class, GoogleJsonErrorContainer.class,
     new BatchCallback<Volumes, GoogleJsonErrorContainer>() {

       public void onSuccess(Volumes volumes, HttpHeaders responseHeaders) {
         log("Success");
         printVolumes(volumes.getItems());
       }

       public void onFailure(GoogleJsonErrorContainer e, HttpHeaders responseHeaders) {
         log(e.getError().getMessage());
       }
     });
 batch.execute();
 

The content of each individual response is stored in memory. There is thus a potential of encountering an OutOfMemoryError for very large responses.

Redirects are currently not followed in BatchRequest.

Implementation is not thread-safe.

Note: When setting an HttpUnsuccessfulResponseHandler by calling to HttpRequest#setUnsuccessfulResponseHandler, the handler is called for each unsuccessful part. As a result it's not recommended to use HttpBackOffUnsuccessfulResponseHandler on a batch request, since the back-off policy is invoked for each unsuccessful part.

Interfaces

BatchCallback<T,E>

Callback for an individual batch response.

Sample use:


 batch.queue(volumesList.buildHttpRequest(), Volumes.class, GoogleJsonErrorContainer.class,
     new BatchCallback<Volumes, GoogleJsonErrorContainer>() {

       public void onSuccess(Volumes volumes, HttpHeaders responseHeaders) {
         log("Success");
         printVolumes(volumes.getItems());
       }

       public void onFailure(GoogleJsonErrorContainer e, HttpHeaders responseHeaders) {
         log(e.getError().getMessage());
       }
     });