BatchRequestService

public class BatchRequestService extends AbstractIdleService

Batch multiple requests. Use add(AsyncRequest) to batch requests. Caller can use returned ListenableFuture to get result of batched request. Use isRunning() to determine if more requests can be batched. Set BatchPolicy to specify max batch request size or batching delay. Requests will be automatically flushed once flush policy is satisfied. Use flush() to flush current batched requests.

TODO(tvartak) : Use executor service to set values or exceptions on settable future with timeout. Caller can potentially add long running callback or listener with newDirectExecutorService(). These should not block other threads.

Nested Class Summary

class BatchRequestService.Builder  
interface BatchRequestService.ExecutorFactory Factory for obtaining ExecutorService instance. 
class BatchRequestService.ExecutorFactoryImpl  
class BatchRequestService.SystemTimeProvider  
interface BatchRequestService.TimeProvider Interface for classes that can provide the current time. 

Public Constructor Summary

Public Method Summary

<T> void
add(AsyncRequest<T> request)
Adds an request to batch request.
ListenableFuture<Integer>
flush()
int
getCurrentBatchSize()
Returns number of elements in batch.

Protected Method Summary

void
void

Inherited Method Summary

Public Constructors

public BatchRequestService (BatchRequestService.Builder builder)

Parameters
builder

Public Methods

public void add (AsyncRequest<T> request)

Adds an request to batch request. If current batch size is greater than or equal to getMaxBatchSize(), current batched requests will be automatically flushed. Operation might block if BatchRequestService can not accept more request immediately.

Parameters
request to be batched
Throws
InterruptedException

public ListenableFuture<Integer> flush ()

Throws
InterruptedException

public int getCurrentBatchSize ()

Returns number of elements in batch.

Returns
  • number of elements batch.

Protected Methods

protected void shutDown ()

Throws
Exception

protected void startUp ()

Throws
Exception

Send feedback about...

Cloud Search
Cloud Search