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(value="For google-cloud-java client use only") 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,
BatchingSettings batchingSettings,
ScheduledExecutorService executor) |
BatcherImpl(BatchingDescriptor<ElementT,ElementResultT,RequestT,ResponseT> batchingDescriptor,
UnaryCallable<RequestT,ResponseT> unaryCallable,
RequestT prototype,
BatchingSettings batchingSettings,
ScheduledExecutorService executor,
FlowController flowController) |
| 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.
|
void |
sendOutstanding()
Sends accumulated elements asynchronously for batching.
|
public BatcherImpl(BatchingDescriptor<ElementT,ElementResultT,RequestT,ResponseT> batchingDescriptor, UnaryCallable<RequestT,ResponseT> unaryCallable, RequestT prototype, BatchingSettings batchingSettings, ScheduledExecutorService executor)
batchingDescriptor - a BatchingDescriptor for transforming individual elements
into wrappers request and responseunaryCallable - a UnaryCallable objectprototype - a RequestT objectbatchingSettings - a BatchingSettings with configuration of thresholdspublic BatcherImpl(BatchingDescriptor<ElementT,ElementResultT,RequestT,ResponseT> batchingDescriptor, UnaryCallable<RequestT,ResponseT> unaryCallable, RequestT prototype, BatchingSettings batchingSettings, ScheduledExecutorService executor, @Nullable FlowController flowController)
batchingDescriptor - a BatchingDescriptor for transforming individual elements
into wrappers request and responseunaryCallable - a UnaryCallable objectprototype - a RequestT objectbatchingSettings - a BatchingSettings with configuration of thresholdsflowController - a FlowController for throttling requests. If it's null, create a
FlowController object from BatchingSettings.getFlowControlSettings().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 sendOutstanding()
Note: This method can be invoked concurrently unlike Batcher.add(ElementT) and Batcher.close(), which
can only be called from a single user thread. Please take caution to avoid race condition.
sendOutstanding in interface Batcher<ElementT,ElementResultT>public void close()
throws InterruptedException
close in interface Batcher<ElementT,ElementResultT>close in interface AutoCloseableInterruptedException