com.lmax.disruptor
Class WorkerPool<T>

java.lang.Object
  extended by com.lmax.disruptor.WorkerPool<T>
Type Parameters:
T - event to be processed by a pool of workers

public final class WorkerPool<T>
extends java.lang.Object

A pool of WorkProcessors that will consume sequences so jobs can be farmed out across a pool of workers which are implemented the WorkHandler interface.


Constructor Summary
WorkerPool(EventFactory<T> eventFactory, ClaimStrategy claimStrategy, WaitStrategy waitStrategy, ExceptionHandler exceptionHandler, WorkHandler<T>... workHandlers)
          Construct a work pool with an internal RingBuffer for convenience.
WorkerPool(RingBuffer<T> ringBuffer, SequenceBarrier sequenceBarrier, ExceptionHandler exceptionHandler, WorkHandler<T>... workHandlers)
          Create a worker pool to enable an array of WorkHandlers to consume published sequences.
 
Method Summary
 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 then end of their current cycle.
 RingBuffer<T> start(java.util.concurrent.Executor executor)
          Start the worker pool processing events in sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkerPool

public WorkerPool(RingBuffer<T> ringBuffer,
                  SequenceBarrier sequenceBarrier,
                  ExceptionHandler exceptionHandler,
                  WorkHandler<T>... workHandlers)
Create a worker pool to enable an array of WorkHandlers to consume published sequences. This option requires a pre-configured RingBuffer which must have Sequencer.setGatingSequences(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 the WorkHandlers.
workHandlers - to distribute the work load across.

WorkerPool

public WorkerPool(EventFactory<T> eventFactory,
                  ClaimStrategy claimStrategy,
                  WaitStrategy waitStrategy,
                  ExceptionHandler exceptionHandler,
                  WorkHandler<T>... workHandlers)
Construct a work pool with an internal RingBuffer for convenience. This option does not require Sequencer.setGatingSequences(Sequence...) to be called before the work pool is started.

Parameters:
eventFactory - for filling the RingBuffer
claimStrategy - for the RingBuffer
waitStrategy - for the RingBuffer
exceptionHandler - to callback when an error occurs which is not handled by the WorkHandlers.
workHandlers - to distribute the work load across.
Method Detail

getWorkerSequences

public Sequence[] getWorkerSequences()
Get an array of Sequences representing the progress of the workers.

Returns:
an array of Sequences representing the progress of the workers.

start

public RingBuffer<T> start(java.util.concurrent.Executor executor)
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:
java.lang.IllegalStateException - is the pool has already been started and not halted yet

drainAndHalt

public void drainAndHalt()
Wait for the RingBuffer to drain of published events then halt the workers.


halt

public void halt()
Halt all workers immediately at then end of their current cycle.



Copyright © 2011 LMAX Ltd. All Rights Reserved.