E - task payload type.public interface WorkQueue<E> extends SyncPrimitive
Work queue serves as a buffer allowing producers to add tasks and consumers
to take tasks to process.
In the system each task is tracked via its unique task identifier which is returned when a task is taken.
Work queue guarantees that a task can be taken by only one consumer at a time. Once it finishes processing a
consumer must invoke the complete method to mark the task(s) as completed.
Tasks thus completed are removed from the queue. If a consumer unexpectedly terminates before it can complete
all its tasks are returned back to the queue so that other consumers can pick them up. Since there is a distinct
possibility that tasks could be processed more than once (under failure conditions), care should be taken to ensure
task processing logic is idempotent.
DEFAULT_OPERATION_TIMEOUT_MILLIS| Modifier and Type | Method and Description |
|---|---|
void |
addMultiple(Collection<E> items)
Adds a collection of tasks to the work queue.
|
default void |
addOne(E item)
Adds a single task to the work queue.
|
AsyncWorkQueue<E> |
async()
Returns the underlying asynchronous primitive.
|
void |
complete(Collection<String> taskIds)
Completes a collection of tasks.
|
default void |
complete(String... taskIds)
Completes a collection of tasks.
|
void |
registerTaskProcessor(Consumer<E> taskProcessor,
int parallelism,
Executor executor)
Registers a task processing callback to be automatically invoked when new tasks are
added to the work queue.
|
WorkQueueStats |
stats()
Returns work queue statistics.
|
void |
stopProcessing()
Stops automatically processing tasks from work queue.
|
default Task<E> |
take()
Picks up a single task from the work queue to work on.
|
Collection<Task<E>> |
take(int maxItems)
Picks up multiple tasks from the work queue to work on.
|
close, deleteaddStateChangeListener, name, protocol, removeStateChangeListener, typevoid addMultiple(Collection<E> items)
items - collection of task itemsCollection<Task<E>> take(int maxItems)
Tasks that are taken remain invisible to other consumers as long as the consumer stays alive.
If a consumer unexpectedly terminates before completing the task,
the task becomes visible again to other consumers to process.
maxItems - maximum number of items to take from the queue. The actual number of tasks returned
can be at the max this numbervoid complete(Collection<String> taskIds)
taskIds - ids of tasks to completevoid registerTaskProcessor(Consumer<E> taskProcessor, int parallelism, Executor executor)
taskProcessor - task processing callbackparallelism - max tasks that can be processed in parallelexecutor - executor to use for processing the tasksvoid stopProcessing()
registerTaskProcessor call.WorkQueueStats stats()
default void complete(String... taskIds)
taskIds - var arg list of task idsdefault void addOne(E item)
item - task itemdefault Task<E> take()
Tasks that are taken remain invisible to other consumers as long as the consumer stays alive.
If a consumer unexpectedly terminates before completing the task,
the task becomes visible again to other consumers to process.
AsyncWorkQueue<E> async()
SyncPrimitiveasync in interface SyncPrimitiveCopyright © 2013–2018. All rights reserved.