- 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.
-
-
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 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.booleanisRunning()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.voidsetRewindStrategy(BatchRewindStrategy batchRewindStrategy)Set a newBatchRewindStrategyfor customizing how to handle aRewindableExceptionWhich can include whether the batch should be rewound and reattempted, or simply thrown and move on to the next sequence the default is aSimpleBatchRewindStrategywhich always rewinds
-
-
-
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- Returns:
- whether this event processor is running or not Implementations should ideally return false only when the associated thread is idle.
-
setExceptionHandler
public void setExceptionHandler(ExceptionHandler<? super T> exceptionHandler)
Set a newExceptionHandlerfor handling exceptions propagated out of theBatchEventProcessor.- Parameters:
exceptionHandler- to replace the existing exceptionHandler.
-
setRewindStrategy
public void setRewindStrategy(BatchRewindStrategy batchRewindStrategy)
Set a newBatchRewindStrategyfor customizing how to handle aRewindableExceptionWhich can include whether the batch should be rewound and reattempted, or simply thrown and move on to the next sequence the default is aSimpleBatchRewindStrategywhich always rewinds- Parameters:
batchRewindStrategy- to replace the existing rewindStrategy.
-
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
-
-