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
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.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RingBuffer<T> private final AtomicBooleanprivate 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 internalRingBufferfor convenience.WorkerPool(RingBuffer<T> ringBuffer, SequenceBarrier sequenceBarrier, ExceptionHandler<? super T> exceptionHandler, WorkHandler<? super T>... workHandlers) Create a worker pool to enable an array ofWorkHandlers to consume published sequences. -
Method Summary
Modifier and TypeMethodDescriptionvoidWait for theRingBufferto drain of published events then halt the workers.Sequence[]Get an array ofSequences representing the progress of the workers.voidhalt()Halt all workers immediately at the end of their current cycle.booleanStart 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 ofWorkHandlers to consume published sequences.This option requires a pre-configured
RingBufferwhich 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 theWorkHandlers.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 internalRingBufferfor convenience.This option does not require
RingBuffer.addGatingSequences(Sequence...)to be called before the work pool is started.- Parameters:
eventFactory- for filling theRingBufferexceptionHandler- to callback when an error occurs which is not handled by theWorkHandlers.workHandlers- to distribute the work load across.
-
-
Method Details
-
getWorkerSequences
Get an array ofSequences representing the progress of the workers.- Returns:
- an array of
Sequences 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
RingBufferused for the work queue. - Throws:
IllegalStateException- if the pool has already been started and not halted yet
-
drainAndHalt
public void drainAndHalt()Wait for theRingBufferto 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()
-