T - event implementation storing the data for sharing during exchange or parallel coordination of an event.public final class BatchEventProcessor<T> extends java.lang.Object implements EventProcessor
RingBuffer
and delegating the available events to an EventHandler.
If the EventHandler also implements LifecycleAware it will be notified just after the thread
is started and just before the thread is shutdown.
| Modifier and Type | Field and Description |
|---|---|
private DataProvider<T> |
dataProvider |
private EventHandler<? super T> |
eventHandler |
private ExceptionHandler<? super T> |
exceptionHandler |
private java.util.concurrent.atomic.AtomicBoolean |
running |
private Sequence |
sequence |
private SequenceBarrier |
sequenceBarrier |
private TimeoutHandler |
timeoutHandler |
| Constructor and Description |
|---|
BatchEventProcessor(DataProvider<T> dataProvider,
SequenceBarrier sequenceBarrier,
EventHandler<? super T> eventHandler)
Construct a
EventProcessor that will automatically track the progress by updating its sequence when
the EventHandler.onEvent(Object, long, boolean) method returns. |
| Modifier and Type | Method and Description |
|---|---|
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.
|
boolean |
isRunning() |
private void |
notifyShutdown()
Notifies the EventHandler immediately prior to this processor shutting down
|
private void |
notifyStart()
Notifies the EventHandler when this processor is starting up
|
private void |
notifyTimeout(long availableSequence) |
void |
run()
It is ok to have another thread rerun this method after a halt().
|
void |
setExceptionHandler(ExceptionHandler<? super T> exceptionHandler)
Set a new
ExceptionHandler for handling exceptions propagated out of the BatchEventProcessor |
private final java.util.concurrent.atomic.AtomicBoolean running
private ExceptionHandler<? super T> exceptionHandler
private final DataProvider<T> dataProvider
private final SequenceBarrier sequenceBarrier
private final EventHandler<? super T> eventHandler
private final Sequence sequence
private final TimeoutHandler timeoutHandler
public BatchEventProcessor(DataProvider<T> dataProvider, SequenceBarrier sequenceBarrier, EventHandler<? super T> eventHandler)
EventProcessor that will automatically track the progress by updating its sequence when
the EventHandler.onEvent(Object, long, boolean) method returns.dataProvider - to which events are published.sequenceBarrier - on which it is waiting.eventHandler - is the delegate to which events are dispatched.public Sequence getSequence()
EventProcessorSequence being used by this EventProcessor.getSequence in interface EventProcessorSequence for this EventProcessorpublic void halt()
EventProcessorSequenceBarrier.alert() to notify the thread to check status.halt in interface EventProcessorpublic boolean isRunning()
isRunning in interface EventProcessorpublic void setExceptionHandler(ExceptionHandler<? super T> exceptionHandler)
ExceptionHandler for handling exceptions propagated out of the BatchEventProcessorexceptionHandler - to replace the existing exceptionHandler.public void run()
run in interface java.lang.Runnablejava.lang.IllegalStateException - if this object instance is already running in a threadprivate void notifyTimeout(long availableSequence)
private void notifyStart()
private void notifyShutdown()