public class Batcher<T>
extends java.lang.Object
| Constructor and Description |
|---|
Batcher(java.util.concurrent.ScheduledExecutorService workExecutor,
int capacity,
long delay,
BatchProcessor<T> processor)
Initializes a batcher.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Empties the queue without processing any of the objects in it.
|
int |
count()
The number of objects currently in the queue.
|
void |
flushAll(boolean waitForAllToFinish)
Sends _all_ the queued objects at once to the processor block.
|
void |
flushAllAndWait() |
int |
getCapacity()
Get capacity amount.
|
long |
getDelay()
Get delay amount.
|
boolean |
isEmpty() |
void |
queueObject(T object)
Adds an object to the queue.
|
void |
queueObjects(java.util.List<T> objects)
Adds multiple objects to the queue.
|
void |
waitForPendingFutures()
Wait for the **current** items in the queue to be all processed.
|
public Batcher(java.util.concurrent.ScheduledExecutorService workExecutor,
int capacity,
long delay,
BatchProcessor<T> processor)
workExecutor - the work executor that performs actual workcapacity - The maximum number of objects to batch up. If the queue reaches
this size, the queued objects will be sent to the processor
immediately.delay - The maximum waiting time in milliseconds to collect objects
before processing them. In some circumstances objects will be
processed sooner.processor - The callback/block that will be called to process the objects.public int getCapacity()
public long getDelay()
public boolean isEmpty()
public int count()
public void queueObject(T object)
public void queueObjects(java.util.List<T> objects)
public void flushAllAndWait()
public void flushAll(boolean waitForAllToFinish)
waitForAllToFinish - wait until all objects are processed. If set to True,
need to make sure not to call flushAll in the same
WorkExecutor used by the batcher as it will result to
deadlock.public void clear()
public void waitForPendingFutures()