Package com.lmax.disruptor
Class WorkProcessor<T>
java.lang.Object
com.lmax.disruptor.WorkProcessor<T>
- Type Parameters:
T- event implementation storing the details for the work to processed.
- All Implemented Interfaces:
EventProcessor,Runnable
A WorkProcessor wraps a single WorkHandler, effectively consuming the sequence
and ensuring appropriate barriers.
Generally, this will be used as part of a WorkerPool.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final EventReleaserprivate final ExceptionHandler<? super T> private final RingBuffer<T> private final AtomicBooleanprivate final Sequenceprivate final SequenceBarrierprivate final TimeoutHandlerprivate final WorkHandler<? super T> private final Sequence -
Constructor Summary
ConstructorsConstructorDescriptionWorkProcessor(RingBuffer<T> ringBuffer, SequenceBarrier sequenceBarrier, WorkHandler<? super T> workHandler, ExceptionHandler<? super T> exceptionHandler, Sequence workSequence) Construct aWorkProcessor. -
Method Summary
Modifier and TypeMethodDescriptionGet a reference to theSequencebeing used by thisEventProcessor.voidhalt()Signal that this EventProcessor should stop when it has finished consuming at the next clean break.booleanprivate voidprivate voidprivate voidnotifyTimeout(long availableSequence) voidrun()It is ok to have another thread re-run this method after a halt().
-
Field Details
-
running
-
sequence
-
ringBuffer
-
sequenceBarrier
-
workHandler
-
exceptionHandler
-
workSequence
-
eventReleaser
-
timeoutHandler
-
-
Constructor Details
-
WorkProcessor
public WorkProcessor(RingBuffer<T> ringBuffer, SequenceBarrier sequenceBarrier, WorkHandler<? super T> workHandler, ExceptionHandler<? super T> exceptionHandler, Sequence workSequence) Construct aWorkProcessor.- Parameters:
ringBuffer- to which events are published.sequenceBarrier- on which it is waiting.workHandler- is the delegate to which events are dispatched.exceptionHandler- to be called back when an error occursworkSequence- from which to claim the next event to be worked on. It should always be initialised asSequencer.INITIAL_CURSOR_VALUE
-
-
Method Details
-
getSequence
Description copied from interface:EventProcessorGet a reference to theSequencebeing used by thisEventProcessor.- Specified by:
getSequencein interfaceEventProcessor- Returns:
- reference to the
Sequencefor thisEventProcessor
-
halt
public void halt()Description copied from interface:EventProcessorSignal that this EventProcessor should stop when it has finished consuming at the next clean break. It will callSequenceBarrier.alert()to notify the thread to check status.- Specified by:
haltin interfaceEventProcessor
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceEventProcessor
-
run
public void run()It is ok to have another thread re-run this method after a halt().- Specified by:
runin interfaceRunnable- Throws:
IllegalStateException- if this processor is already running
-
notifyTimeout
private void notifyTimeout(long availableSequence) -
notifyStart
private void notifyStart() -
notifyShutdown
private void notifyShutdown()
-