Package com.lmax.disruptor
Interface EventHandler<T>
- Type Parameters:
T- event implementation storing the data for sharing during exchange or parallel coordination of an event.
- All Superinterfaces:
EventHandlerBase<T>,EventHandlerIdentity
- All Known Subinterfaces:
SequenceReportingEventHandler<T>
- All Known Implementing Classes:
AggregateEventHandler
Callback interface to be implemented for processing events as they become available in the
RingBuffer- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidCalled when a publisher has published an event to theRingBuffer.default voidsetSequenceCallback(Sequence sequenceCallback) Used by theBatchEventProcessorto set a callback allowing theEventHandlerto notify when it has finished consuming an event if this happens after theonEvent(Object, long, boolean)call.Methods inherited from interface com.lmax.disruptor.EventHandlerBase
onBatchStart, onShutdown, onStart, onTimeout
-
Method Details
-
onEvent
Called when a publisher has published an event to theRingBuffer. TheBatchEventProcessorwill read messages from theRingBufferin 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.- Specified by:
onEventin interfaceEventHandlerBase<T>- Parameters:
event- published to theRingBuffersequence- of the event being processedendOfBatch- flag to indicate if this is the last event in a batch from theRingBuffer- Throws:
Exception- if the EventHandler would like the exception handled further up the chain.
-
setSequenceCallback
Used by theBatchEventProcessorto set a callback allowing theEventHandlerto 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 theBatchEventProcessorthat the sequence has progressed.
-