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,Runnable
Convenience class for handling the batching semantics of consuming entries from a
RingBuffer
and delegating the available events to an EventHandler.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final DataProvider<T> private final EventHandlerBase<? super T> private ExceptionHandler<? super T> private static final intprivate static final intprivate intprivate final RewindHandlerprivate final AtomicIntegerprivate static final intprivate final Sequenceprivate final SequenceBarrier -
Constructor Summary
ConstructorsConstructorDescriptionBatchEventProcessor(DataProvider<T> dataProvider, SequenceBarrier sequenceBarrier, EventHandlerBase<? super T> eventHandler, int maxBatchSize, BatchRewindStrategy batchRewindStrategy) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate ExceptionHandler<? super T> 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(Throwable ex, long sequence, T event) Delegate toExceptionHandler.handleEventException(Throwable, long, Object)on the delegate or the defaultExceptionHandlerif one has not been configured.private voidDelegate toExceptionHandler.handleOnShutdownException(Throwable)on the delegate or the defaultExceptionHandlerif one has not been configured.private voidDelegate toExceptionHandler.handleOnStartException(Throwable)on the delegate or the defaultExceptionHandlerif one has not been configured.booleanprivate voidNotifies the EventHandler immediately prior to this processor shutting down.private voidNotifies the EventHandler when this processor is starting up.private voidnotifyTimeout(long availableSequence) private voidvoidrun()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 Details
-
IDLE
private static final int IDLE- See Also:
-
HALTED
private static final int HALTED- See Also:
-
RUNNING
private static final int RUNNING- See Also:
-
running
-
exceptionHandler
-
dataProvider
-
sequenceBarrier
-
eventHandler
-
batchLimitOffset
private final int batchLimitOffset -
sequence
-
rewindHandler
-
retriesAttempted
private int retriesAttempted
-
-
Constructor Details
-
BatchEventProcessor
BatchEventProcessor(DataProvider<T> dataProvider, SequenceBarrier sequenceBarrier, EventHandlerBase<? super T> eventHandler, int maxBatchSize, BatchRewindStrategy batchRewindStrategy)
-
-
Method Details
-
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- Returns:
- whether this event processor is running or not Implementations should ideally return false only when the associated thread is idle.
-
setExceptionHandler
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 interfaceRunnable- Throws:
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
Delegate toExceptionHandler.handleEventException(Throwable, long, Object)on the delegate or the defaultExceptionHandlerif one has not been configured. -
handleOnStartException
Delegate toExceptionHandler.handleOnStartException(Throwable)on the delegate or the defaultExceptionHandlerif one has not been configured. -
handleOnShutdownException
Delegate toExceptionHandler.handleOnShutdownException(Throwable)on the delegate or the defaultExceptionHandlerif one has not been configured. -
getExceptionHandler
-