com.lmax.disruptor
Class BatchEventProcessor<T>

java.lang.Object
  extended by com.lmax.disruptor.BatchEventProcessor<T>
Type Parameters:
T - event implementation storing the data for sharing during exchange or parallel coordination of an event.
All Implemented Interfaces:
EventProcessor, java.lang.Runnable

public final class BatchEventProcessor<T>
extends java.lang.Object
implements EventProcessor

Convenience class for handling the batching semantics of consuming entries from a RingBuffer and delegating the available events to a EventHandler. If the EventHandler also implements LifecycleAware it will be notified just after the thread is started and just before the thread is shutdown.


Constructor Summary
BatchEventProcessor(RingBuffer<T> ringBuffer, SequenceBarrier sequenceBarrier, EventHandler<T> eventHandler)
          Construct a EventProcessor that will automatically track the progress by updating its sequence when the EventHandler.onEvent(Object, long, boolean) method returns.
 
Method Summary
 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.
 void run()
          It is ok to have another thread rerun this method after a halt().
 void setExceptionHandler(ExceptionHandler exceptionHandler)
          Set a new ExceptionHandler for handling exceptions propagated out of the BatchEventProcessor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BatchEventProcessor

public BatchEventProcessor(RingBuffer<T> ringBuffer,
                           SequenceBarrier sequenceBarrier,
                           EventHandler<T> eventHandler)
Construct a EventProcessor that will automatically track the progress by updating its sequence when the EventHandler.onEvent(Object, long, boolean) method returns.

Parameters:
ringBuffer - to which events are published.
sequenceBarrier - on which it is waiting.
eventHandler - is the delegate to which events are dispatched.
Method Detail

getSequence

public Sequence getSequence()
Description copied from interface: EventProcessor
Get a reference to the Sequence being used by this EventProcessor.

Specified by:
getSequence in interface EventProcessor
Returns:
reference to the Sequence for this EventProcessor

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

setExceptionHandler

public void setExceptionHandler(ExceptionHandler exceptionHandler)
Set a new ExceptionHandler for handling exceptions propagated out of the BatchEventProcessor

Parameters:
exceptionHandler - to replace the existing exceptionHandler.

run

public void run()
It is ok to have another thread rerun this method after a halt().

Specified by:
run in interface java.lang.Runnable


Copyright © 2011 LMAX Ltd. All Rights Reserved.