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
,java.lang.Runnable
public final class WorkProcessor<T> extends java.lang.Object implements EventProcessor
A
WorkProcessor
wraps a singleWorkHandler
, effectively consuming the sequence and ensuring appropriate barriers.Generally, this will be used as part of a
WorkerPool
.
-
-
Field Summary
Fields Modifier and Type Field Description private EventReleaser
eventReleaser
private ExceptionHandler<? super T>
exceptionHandler
private RingBuffer<T>
ringBuffer
private java.util.concurrent.atomic.AtomicBoolean
running
private Sequence
sequence
private SequenceBarrier
sequenceBarrier
private TimeoutHandler
timeoutHandler
private WorkHandler<? super T>
workHandler
private Sequence
workSequence
-
Constructor Summary
Constructors Constructor Description WorkProcessor(RingBuffer<T> ringBuffer, SequenceBarrier sequenceBarrier, WorkHandler<? super T> workHandler, ExceptionHandler<? super T> exceptionHandler, Sequence workSequence)
Construct aWorkProcessor
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Sequence
getSequence()
Get a reference to theSequence
being used by thisEventProcessor
.void
halt()
Signal that this EventProcessor should stop when it has finished consuming at the next clean break.boolean
isRunning()
private void
notifyShutdown()
private void
notifyStart()
private void
notifyTimeout(long availableSequence)
void
run()
It is ok to have another thread re-run this method after a halt().
-
-
-
Field Detail
-
running
private final java.util.concurrent.atomic.AtomicBoolean running
-
sequence
private final Sequence sequence
-
ringBuffer
private final RingBuffer<T> ringBuffer
-
sequenceBarrier
private final SequenceBarrier sequenceBarrier
-
workHandler
private final WorkHandler<? super T> workHandler
-
exceptionHandler
private final ExceptionHandler<? super T> exceptionHandler
-
workSequence
private final Sequence workSequence
-
eventReleaser
private final EventReleaser eventReleaser
-
timeoutHandler
private final TimeoutHandler timeoutHandler
-
-
Constructor Detail
-
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 Detail
-
getSequence
public Sequence getSequence()
Description copied from interface:EventProcessor
Get a reference to theSequence
being used by thisEventProcessor
.- Specified by:
getSequence
in interfaceEventProcessor
- Returns:
- reference to the
Sequence
for thisEventProcessor
-
halt
public void halt()
Description copied from interface:EventProcessor
Signal 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:
halt
in interfaceEventProcessor
-
isRunning
public boolean isRunning()
- Specified by:
isRunning
in interfaceEventProcessor
-
run
public void run()
It is ok to have another thread re-run this method after a halt().- Specified by:
run
in interfacejava.lang.Runnable
- Throws:
java.lang.IllegalStateException
- if this processor is already running
-
notifyTimeout
private void notifyTimeout(long availableSequence)
-
notifyStart
private void notifyStart()
-
notifyShutdown
private void notifyShutdown()
-
-