Class 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 single WorkHandler, effectively consuming the sequence and ensuring appropriate barriers.

    Generally, this will be used as part of a WorkerPool.

    • Field Detail

      • running

        private final java.util.concurrent.atomic.AtomicBoolean running
      • sequence

        private final Sequence sequence
      • workHandler

        private final WorkHandler<? super T> workHandler
      • workSequence

        private final Sequence workSequence
    • Constructor Detail

      • WorkProcessor

        public WorkProcessor​(RingBuffer<T> ringBuffer,
                             SequenceBarrier sequenceBarrier,
                             WorkHandler<? super T> workHandler,
                             ExceptionHandler<? super T> exceptionHandler,
                             Sequence workSequence)
        Construct a WorkProcessor.
        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 occurs
        workSequence - from which to claim the next event to be worked on. It should always be initialised as Sequencer.INITIAL_CURSOR_VALUE
    • Method Detail

      • 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 call SequenceBarrier.alert() to notify the thread to check status.
        Specified by:
        halt in interface EventProcessor
      • run

        public void run()
        It is ok to have another thread re-run this method after a halt().
        Specified by:
        run in interface java.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()