Package com.google.cloud.hadoop.gcsio
Class BatchHelper
- java.lang.Object
-
- com.google.cloud.hadoop.gcsio.BatchHelper
-
public class BatchHelper extends Object
BatchHelper abstracts out the logic for maximum requests per batch, and also allows a workaround for the fact thatBatchRequestwas 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
numThreadsis 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBatchHelper.FactorySince 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 interfaceBatchHelper.QueueRequestCallbackCallback that causes a single StorageRequest to be added to theBatchRequest.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidflush()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.booleanisEmpty()Returns true if there are no currently queued entries in the batch helper.<T> voidqueue(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 ifmaxRequestsPerBatchhas been reached.
-
-
-
Method Detail
-
queue
public <T> void queue(com.google.api.services.storage.StorageRequest<T> req, com.google.api.client.googleapis.batch.json.JsonBatchCallback<T> callback) throws IOExceptionAdds an additional request to the batch, and possibly flushes the current contents of the batch ifmaxRequestsPerBatchhas been reached.- Throws:
IOException
-
flush
public void flush() throws IOExceptionSends 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.- Throws:
IOException
-
isEmpty
public boolean isEmpty()
Returns true if there are no currently queued entries in the batch helper.
-
-