Package com.lmax.disruptor
Class WorkerPool<T>
java.lang.Object
com.lmax.disruptor.WorkerPool<T>
- Type Parameters:
T
- event to be processed by a pool of workers
WorkerPool contains a pool of
WorkProcessor
s that will consume sequences so jobs can be farmed out across a pool of workers.
Each of the WorkProcessor
s manage and calls a WorkHandler
to process the events.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RingBuffer
<T> private final AtomicBoolean
private final WorkProcessor<?>[]
private final Sequence
-
Constructor Summary
ConstructorsConstructorDescriptionWorkerPool
(EventFactory<T> eventFactory, ExceptionHandler<? super T> exceptionHandler, WorkHandler<? super T>... workHandlers) Construct a work pool with an internalRingBuffer
for convenience.WorkerPool
(RingBuffer<T> ringBuffer, SequenceBarrier sequenceBarrier, ExceptionHandler<? super T> exceptionHandler, WorkHandler<? super T>... workHandlers) Create a worker pool to enable an array ofWorkHandler
s to consume published sequences. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Wait for theRingBuffer
to drain of published events then halt the workers.Sequence[]
Get an array ofSequence
s representing the progress of the workers.void
halt()
Halt all workers immediately at the end of their current cycle.boolean
Start the worker pool processing events in sequence.
-
Field Details
-
started
-
workSequence
-
ringBuffer
-
workProcessors
-
-
Constructor Details
-
WorkerPool
@SafeVarargs public WorkerPool(RingBuffer<T> ringBuffer, SequenceBarrier sequenceBarrier, ExceptionHandler<? super T> exceptionHandler, WorkHandler<? super T>... workHandlers) Create a worker pool to enable an array ofWorkHandler
s to consume published sequences.This option requires a pre-configured
RingBuffer
which must haveRingBuffer.addGatingSequences(Sequence...)
called before the work pool is started.- Parameters:
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 theWorkHandler
s.workHandlers
- to distribute the work load across.
-
WorkerPool
@SafeVarargs public WorkerPool(EventFactory<T> eventFactory, ExceptionHandler<? super T> exceptionHandler, WorkHandler<? super T>... workHandlers) Construct a work pool with an internalRingBuffer
for convenience.This option does not require
RingBuffer.addGatingSequences(Sequence...)
to be called before the work pool is started.- Parameters:
eventFactory
- for filling theRingBuffer
exceptionHandler
- to callback when an error occurs which is not handled by theWorkHandler
s.workHandlers
- to distribute the work load across.
-
-
Method Details
-
getWorkerSequences
Get an array ofSequence
s representing the progress of the workers.- Returns:
- an array of
Sequence
s representing the progress of the workers.
-
start
Start the worker pool processing events in sequence.- Parameters:
executor
- providing threads for running the workers.- Returns:
- the
RingBuffer
used for the work queue. - Throws:
IllegalStateException
- if the pool has already been started and not halted yet
-
drainAndHalt
public void drainAndHalt()Wait for theRingBuffer
to drain of published events then halt the workers. -
halt
public void halt()Halt all workers immediately at the end of their current cycle. -
isRunning
public boolean isRunning()
-