ElementT - The type of each individual element to be batched.ElementResultT - The type of the result for each individual element.@BetaApi(value="The surface for batching is not stable yet and may change in the future.") public interface Batcher<ElementT,ElementResultT> extends AutoCloseable
| Modifier and Type | Method and Description |
|---|---|
com.google.api.core.ApiFuture<ElementResultT> |
add(ElementT entry)
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.
|
com.google.api.core.ApiFuture<ElementResultT> add(ElementT entry)
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.
void flush()
throws InterruptedException
InterruptedExceptionvoid sendOutstanding()
Note: This method can be invoked concurrently unlike add(ElementT) and close(), which
can only be called from a single user thread. Please take caution to avoid race condition.
void close()
throws InterruptedException
close in interface AutoCloseableInterruptedException