T - event implementation storing the details for the work to processed.public final class WorkProcessor<T> extends java.lang.Object implements EventProcessor
A WorkProcessor wraps a single WorkHandler, effectively consuming the sequence
and ensuring appropriate barriers.
Generally, this will be used as part of a WorkerPool.
| Modifier and Type | Field and 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 and Description |
|---|
WorkProcessor(RingBuffer<T> ringBuffer,
SequenceBarrier sequenceBarrier,
WorkHandler<? super T> workHandler,
ExceptionHandler<? super T> exceptionHandler,
Sequence workSequence)
Construct a
WorkProcessor. |
| Modifier and Type | Method and Description |
|---|---|
Sequence |
getSequence()
Get a reference to the
Sequence being used by this EventProcessor. |
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().
|
private final java.util.concurrent.atomic.AtomicBoolean running
private final Sequence sequence
private final RingBuffer<T> ringBuffer
private final SequenceBarrier sequenceBarrier
private final WorkHandler<? super T> workHandler
private final ExceptionHandler<? super T> exceptionHandler
private final Sequence workSequence
private final EventReleaser eventReleaser
private final TimeoutHandler timeoutHandler
public WorkProcessor(RingBuffer<T> ringBuffer, SequenceBarrier sequenceBarrier, WorkHandler<? super T> workHandler, ExceptionHandler<? super T> exceptionHandler, Sequence workSequence)
WorkProcessor.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
as Sequencer.INITIAL_CURSOR_VALUEpublic Sequence getSequence()
EventProcessorSequence being used by this EventProcessor.getSequence in interface EventProcessorSequence for this EventProcessorpublic void halt()
EventProcessorSequenceBarrier.alert() to notify the thread to check status.halt in interface EventProcessorpublic boolean isRunning()
isRunning in interface EventProcessorpublic void run()
run in interface java.lang.Runnablejava.lang.IllegalStateException - if this processor is already runningprivate void notifyTimeout(long availableSequence)
private void notifyStart()
private void notifyShutdown()