public class BatchHelper extends Object
BatchRequest was made a "final class" for some reason, making it
impossible to unittest. Instead, batch interactions with a Storage API client will be funneled
through this class, while unittests can inject a mock batch helper.
This class is thread-safe, because if numThreads is greater than 0, request callbacks
will be executed on a different thread(s) than a client thread that queues requests.
Expected usage is to create a new BatchHelper instance per client operation (copy, rename, delete, etc.) that represent logical grouping of requests.
Instance of this class can not be used again after flush() method call.
| Modifier and Type | Class and Description |
|---|---|
static class |
BatchHelper.Factory
Since each BatchHelper instance should be tied to a particular related set of requests, use
cases will generally interact via an injectable BatchHelper.Factory.
|
protected static interface |
BatchHelper.QueueRequestCallback
Callback that causes a single StorageRequest to be added to the
BatchRequest. |
| Modifier and Type | Method and Description |
|---|---|
void |
flush()
Sends any currently remaining requests in the batch; should be called at the end of any series
of batched requests to ensure everything has been sent.
|
boolean |
isEmpty()
Returns true if there are no currently queued entries in the batch helper.
|
<T> void |
queue(com.google.api.services.storage.StorageRequest<T> req,
com.google.api.client.googleapis.batch.json.JsonBatchCallback<T> callback)
Adds an additional request to the batch, and possibly flushes the current contents of the batch
if
maxRequestsPerBatch has been reached. |
public <T> void queue(com.google.api.services.storage.StorageRequest<T> req,
com.google.api.client.googleapis.batch.json.JsonBatchCallback<T> callback)
throws IOException
maxRequestsPerBatch has been reached.IOExceptionpublic void flush()
throws IOException
IOExceptionpublic boolean isEmpty()
Copyright © 2022. All rights reserved.