-
- Type Parameters:
T
- event implementation storing the data for sharing during exchange or parallel coordination of an event.
- All Superinterfaces:
EventHandlerIdentity
- All Known Implementing Classes:
AggregateEventHandler
public interface EventHandler<T>
Callback interface to be implemented for processing events as they become available in theRingBuffer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
onBatchStart(long batchSize, long queueDepth)
Invoked byBatchEventProcessor
prior to processing a batch of eventsvoid
onEvent(T event, long sequence, boolean endOfBatch)
Called when a publisher has published an event to theRingBuffer
.default void
onShutdown()
Called once just before the event processing thread is shutdown.default void
onStart()
Called once on thread start before first event is available.default void
onTimeout(long sequence)
default void
setSequenceCallback(Sequence sequenceCallback)
Used by theBatchEventProcessor
to set a callback allowing theEventHandler
to notify when it has finished consuming an event if this happens after theonEvent(Object, long, boolean)
call.
-
-
-
Method Detail
-
onEvent
void onEvent(T event, long sequence, boolean endOfBatch) throws java.lang.Exception
Called when a publisher has published an event to theRingBuffer
. TheBatchEventProcessor
will read messages from theRingBuffer
in batches, where a batch is all of the events available to be processed without having to wait for any new event to arrive. This can be useful for event handlers that need to do slower operations like I/O as they can group together the data from multiple events into a single operation. Implementations should ensure that the operation is always performed when endOfBatch is true as the time between that message and the next one is indeterminate.- Parameters:
event
- published to theRingBuffer
sequence
- of the event being processedendOfBatch
- flag to indicate if this is the last event in a batch from theRingBuffer
- Throws:
java.lang.Exception
- if the EventHandler would like the exception handled further up the chain.
-
setSequenceCallback
default void setSequenceCallback(Sequence sequenceCallback)
Used by theBatchEventProcessor
to set a callback allowing theEventHandler
to notify when it has finished consuming an event if this happens after theonEvent(Object, long, boolean)
call.Typically this would be used when the handler is performing some sort of batching operation such as writing to an IO device; after the operation has completed, the implementation should call
Sequence.set(long)
to update the sequence and allow other processes that are dependent on this handler to progress.- Parameters:
sequenceCallback
- callback on which to notify theBatchEventProcessor
that the sequence has progressed.
-
onBatchStart
default void onBatchStart(long batchSize, long queueDepth)
Invoked byBatchEventProcessor
prior to processing a batch of events- Parameters:
batchSize
- the size of the batch that is startingqueueDepth
- the total number of queued up events including the batch about to be processed
-
onStart
default void onStart()
Called once on thread start before first event is available.
-
onShutdown
default void onShutdown()
Called once just before the event processing thread is shutdown.Sequence event processing will already have stopped before this method is called. No events will be processed after this message.
-
onTimeout
default void onTimeout(long sequence) throws java.lang.Exception
- Parameters:
sequence
- - the last processed sequence.- Throws:
java.lang.Exception
- if the implementation is unable to handle this timeout.
-
-