|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.api.client.googleapis.batch.BatchRequest
public final class BatchRequest
An instance of this class represents a single batch of requests.
Sample use:
BatchRequest batch = new BatchRequest(transport, httpRequestInitializer); batch.queue(volumesList, Volumes.class, GoogleJsonErrorContainer.class, new BatchCallback<Volumes, GoogleJsonErrorContainer>() { public void onSuccess(Volumes volumes, GoogleHeaders responseHeaders) { log("Success"); printVolumes(volumes.getItems()); } public void onFailure(GoogleJsonErrorContainer e, GoogleHeaders responseHeaders) { log(e.getError().getMessage()); } }); batch.queue(volumesList, Volumes.class, GoogleJsonErrorContainer.class, new BatchCallback<Volumes, GoogleJsonErrorContainer>() { public void onSuccess(Volumes volumes, GoogleHeaders responseHeaders) { log("Success"); printVolumes(volumes.getItems()); } public void onFailure(GoogleJsonErrorContainer e, GoogleHeaders 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.
Constructor Summary | |
---|---|
BatchRequest(HttpTransport transport,
HttpRequestInitializer httpRequestInitializer)
Construct the BatchRequest . |
Method Summary | ||
---|---|---|
void |
execute()
Executes all queued HTTP requests in a single call, parses the responses and invokes callbacks. |
|
GenericUrl |
getBatchUrl()
Returns the URL that will be hit when execute() is called. |
|
|
queue(HttpRequest httpRequest,
Class<T> dataClass,
Class<E> errorClass,
BatchCallback<T,E> callback)
Queues the specified HttpRequest for batched execution. |
|
BatchRequest |
setBatchUrl(GenericUrl batchUrl)
Sets the URL that will be hit when execute() is called. |
|
int |
size()
Returns the number of queued requests in this batch request. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer)
BatchRequest
.
transport
- The transport to use for requestshttpRequestInitializer
- The initializer to use when creating an HttpRequest
or
null
for noneMethod Detail |
---|
public BatchRequest setBatchUrl(GenericUrl batchUrl)
execute()
is called. The default value is
https://www.googleapis.com/batch
.
public GenericUrl getBatchUrl()
execute()
is called.
public <T,E> BatchRequest queue(HttpRequest httpRequest, Class<T> dataClass, Class<E> errorClass, BatchCallback<T,E> callback) throws IOException
HttpRequest
for batched execution. Batched requests are executed
when execute()
is called.
T
- destination class typeE
- error class typehttpRequest
- HTTP RequestdataClass
- Data class the response will be parsed into or Void.class
to ignore
the contenterrorClass
- Data class the unsuccessful response will be parsed into or
Void.class
to ignore the contentcallback
- Batch Callback
IOException
- If building the HTTP Request failspublic int size()
public void execute() throws IOException
Calling execute()
executes and clears the queued requests. This means that the
BatchRequest
object can be reused to queue(com.google.api.client.http.HttpRequest, java.lang.Class
and execute()
requests
again.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |