ElementT - The type of each individual element to be batched.ElementResultT - The type of the result for each individual element.RequestT - The type of the request that will contain the accumulated elements.ResponseT - The type of the response that will unpack into individual element results.@BetaApi(value="The surface for batching is not stable yet and may change in the future.") @InternalApi public class BatcherImpl<ElementT,ElementResultT,RequestT,ResponseT> extends Object implements Batcher<ElementT,ElementResultT>
flush() is called; once batching is over, returned future
resolves.
This class is not thread-safe, and expects to be used from a single thread.
| Constructor and Description |
|---|
BatcherImpl(BatchingDescriptor<ElementT,ElementResultT,RequestT,ResponseT> batchingDescriptor,
UnaryCallable<RequestT,ResponseT> unaryCallable,
RequestT prototype) |
| Modifier and Type | Method and Description |
|---|---|
com.google.api.core.ApiFuture<ElementResultT> |
add(ElementT element)
Queues the passed in element to be sent at some point in the future.
|
void |
close()
Closes this Batcher by preventing new elements from being added and flushing the existing
elements.
|
void |
flush()
Synchronously sends any pending elements as a batch and waits for all outstanding batches to be
complete.
|
public BatcherImpl(BatchingDescriptor<ElementT,ElementResultT,RequestT,ResponseT> batchingDescriptor, UnaryCallable<RequestT,ResponseT> unaryCallable, RequestT prototype)
public com.google.api.core.ApiFuture<ElementResultT> add(ElementT element)
The element will be sent as part of a larger batch request at some point in the future. The
returned ApiFuture will be resolved once the result for the element has been extracted
from the batch response.
Note: Cancelling returned result simply marks the future cancelled, It would not stop the batch request.
add in interface Batcher<ElementT,ElementResultT>public void flush()
throws InterruptedException
flush in interface Batcher<ElementT,ElementResultT>InterruptedExceptionpublic void close()
throws InterruptedException
close in interface Batcher<ElementT,ElementResultT>close in interface AutoCloseableInterruptedException