T - event to be processed by a pool of workerspublic final class WorkerPool<T>
extends java.lang.Object
WorkProcessors that will consume sequences so jobs can be farmed out across a pool of workers.
Each of the WorkProcessors manage and calls a WorkHandler to process the events.| Constructor and Description |
|---|
WorkerPool(EventFactory<T> eventFactory,
ExceptionHandler<? super T> exceptionHandler,
WorkHandler<? super T>... workHandlers)
Construct a work pool with an internal
RingBuffer for convenience. |
WorkerPool(RingBuffer<T> ringBuffer,
SequenceBarrier sequenceBarrier,
ExceptionHandler<? super T> exceptionHandler,
WorkHandler<? super T>... workHandlers)
Create a worker pool to enable an array of
WorkHandlers to consume published sequences. |
| Modifier and Type | Method and Description |
|---|---|
void |
drainAndHalt()
Wait for the
RingBuffer to drain of published events then halt the workers. |
Sequence[] |
getWorkerSequences()
Get an array of
Sequences representing the progress of the workers. |
void |
halt()
Halt all workers immediately at the end of their current cycle.
|
boolean |
isRunning() |
RingBuffer<T> |
start(java.util.concurrent.Executor executor)
Start the worker pool processing events in sequence.
|
@SafeVarargs public WorkerPool(RingBuffer<T> ringBuffer, SequenceBarrier sequenceBarrier, ExceptionHandler<? super T> exceptionHandler, WorkHandler<? super T>... workHandlers)
WorkHandlers to consume published sequences.
This option requires a pre-configured RingBuffer which must have RingBuffer.addGatingSequences(Sequence...)
called before the work pool is started.
ringBuffer - of events to be consumed.sequenceBarrier - on which the workers will depend.exceptionHandler - to callback when an error occurs which is not handled by the WorkHandlers.workHandlers - to distribute the work load across.@SafeVarargs public WorkerPool(EventFactory<T> eventFactory, ExceptionHandler<? super T> exceptionHandler, WorkHandler<? super T>... workHandlers)
RingBuffer for convenience.
This option does not require RingBuffer.addGatingSequences(Sequence...) to be called before the work pool is started.
eventFactory - for filling the RingBufferexceptionHandler - to callback when an error occurs which is not handled by the WorkHandlers.workHandlers - to distribute the work load across.public Sequence[] getWorkerSequences()
Sequences representing the progress of the workers.Sequences representing the progress of the workers.public RingBuffer<T> start(java.util.concurrent.Executor executor)
executor - providing threads for running the workers.RingBuffer used for the work queue.java.lang.IllegalStateException - if the pool has already been started and not halted yetpublic void drainAndHalt()
RingBuffer to drain of published events then halt the workers.public void halt()
public boolean isRunning()
Copyright © 2011 - 2018 LMAX Ltd. All Rights Reserved.