Package com.lmax.disruptor
Class BatchEventProcessor<T>
- java.lang.Object
-
- 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 aRingBufferand delegating the available events to anEventHandler.If the
EventHandleralso implementsLifecycleAwareit will be notified just after the thread is started and just before the thread is shutdown.
-
-
Field Summary
Fields Modifier and Type Field Description private BatchStartAwarebatchStartAwareprivate DataProvider<T>dataProviderprivate EventHandler<? super T>eventHandlerprivate ExceptionHandler<? super T>exceptionHandlerprivate static intHALTEDprivate static intIDLEprivate java.util.concurrent.atomic.AtomicIntegerrunningprivate static intRUNNINGprivate Sequencesequenceprivate SequenceBarriersequenceBarrierprivate TimeoutHandlertimeoutHandler
-
Constructor Summary
Constructors Constructor Description BatchEventProcessor(DataProvider<T> dataProvider, SequenceBarrier sequenceBarrier, EventHandler<? super T> eventHandler)Construct aEventProcessorthat will automatically track the progress by updating its sequence when theEventHandler.onEvent(Object, long, boolean)method returns.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidearlyExit()private ExceptionHandler<? super T>getExceptionHandler()SequencegetSequence()Get a reference to theSequencebeing used by thisEventProcessor.voidhalt()Signal that this EventProcessor should stop when it has finished consuming at the next clean break.private voidhandleEventException(java.lang.Throwable ex, long sequence, T event)Delegate toExceptionHandler.handleEventException(Throwable, long, Object)on the delegate or the defaultExceptionHandlerif one has not been configured.private voidhandleOnShutdownException(java.lang.Throwable ex)Delegate toExceptionHandler.handleOnShutdownException(Throwable)on the delegate or the defaultExceptionHandlerif one has not been configured.private voidhandleOnStartException(java.lang.Throwable ex)Delegate toExceptionHandler.handleOnStartException(Throwable)on the delegate or the defaultExceptionHandlerif one has not been configured.booleanisRunning()private voidnotifyShutdown()Notifies the EventHandler immediately prior to this processor shutting downprivate voidnotifyStart()Notifies the EventHandler when this processor is starting upprivate voidnotifyTimeout(long availableSequence)private voidprocessEvents()voidrun()It is ok to have another thread rerun this method after a halt().voidsetExceptionHandler(ExceptionHandler<? super T> exceptionHandler)Set a newExceptionHandlerfor handling exceptions propagated out of theBatchEventProcessor
-
-
-
Field Detail
-
IDLE
private static final int IDLE
- See Also:
- Constant Field Values
-
HALTED
private static final int HALTED
- See Also:
- Constant Field Values
-
RUNNING
private static final int RUNNING
- See Also:
- Constant Field Values
-
running
private final java.util.concurrent.atomic.AtomicInteger running
-
exceptionHandler
private ExceptionHandler<? super T> exceptionHandler
-
dataProvider
private final DataProvider<T> dataProvider
-
sequenceBarrier
private final SequenceBarrier sequenceBarrier
-
eventHandler
private final EventHandler<? super T> eventHandler
-
sequence
private final Sequence sequence
-
timeoutHandler
private final TimeoutHandler timeoutHandler
-
batchStartAware
private final BatchStartAware batchStartAware
-
-
Constructor Detail
-
BatchEventProcessor
public BatchEventProcessor(DataProvider<T> dataProvider, SequenceBarrier sequenceBarrier, EventHandler<? super T> eventHandler)
Construct aEventProcessorthat will automatically track the progress by updating its sequence when theEventHandler.onEvent(Object, long, boolean)method returns.- Parameters:
dataProvider- 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: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
-
setExceptionHandler
public void setExceptionHandler(ExceptionHandler<? super T> exceptionHandler)
Set a newExceptionHandlerfor handling exceptions propagated out of theBatchEventProcessor- 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:
runin interfacejava.lang.Runnable- Throws:
java.lang.IllegalStateException- if this object instance is already running in a thread
-
processEvents
private void processEvents()
-
earlyExit
private void earlyExit()
-
notifyTimeout
private void notifyTimeout(long availableSequence)
-
notifyStart
private void notifyStart()
Notifies the EventHandler when this processor is starting up
-
notifyShutdown
private void notifyShutdown()
Notifies the EventHandler immediately prior to this processor shutting down
-
handleEventException
private void handleEventException(java.lang.Throwable ex, long sequence, T event)Delegate toExceptionHandler.handleEventException(Throwable, long, Object)on the delegate or the defaultExceptionHandlerif one has not been configured.
-
handleOnStartException
private void handleOnStartException(java.lang.Throwable ex)
Delegate toExceptionHandler.handleOnStartException(Throwable)on the delegate or the defaultExceptionHandlerif one has not been configured.
-
handleOnShutdownException
private void handleOnShutdownException(java.lang.Throwable ex)
Delegate toExceptionHandler.handleOnShutdownException(Throwable)on the delegate or the defaultExceptionHandlerif one has not been configured.
-
getExceptionHandler
private ExceptionHandler<? super T> getExceptionHandler()
-
-