- java.lang.Object
-
- com.lmax.disruptor.EventPoller<T>
-
- Type Parameters:
T
- the type of event used.
public class EventPoller<T> extends java.lang.Object
Experimental poll-based interface for the Disruptor. Unlike aBatchEventProcessor
, an event poller allows the user to control the flow of execution. This makes it ideal for interoperability with existing threads whose lifecycle is not controlled by the disruptor DSL.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
EventPoller.Handler<T>
A callback used to process eventsstatic class
EventPoller.PollState
Indicates the result of a call topoll(Handler)
-
Constructor Summary
Constructors Constructor Description EventPoller(DataProvider<T> dataProvider, Sequencer sequencer, Sequence sequence, Sequence gatingSequence)
Creates an event poller.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Sequence
getSequence()
Get theSequence
being used by this event pollerstatic <T> EventPoller<T>
newInstance(DataProvider<T> dataProvider, Sequencer sequencer, Sequence sequence, Sequence cursorSequence, Sequence... gatingSequences)
Creates an event poller.EventPoller.PollState
poll(EventPoller.Handler<T> eventHandler)
Polls for events using the given handler.
-
-
-
Constructor Detail
-
EventPoller
public EventPoller(DataProvider<T> dataProvider, Sequencer sequencer, Sequence sequence, Sequence gatingSequence)
Creates an event poller. Most users will wantRingBuffer.newPoller(Sequence...)
which will set up the poller automatically- Parameters:
dataProvider
- from which events are drawnsequencer
- the main sequencer which handles ordering of eventssequence
- the sequence which will be used by this event pollergatingSequence
- the sequences to gate on
-
-
Method Detail
-
poll
public EventPoller.PollState poll(EventPoller.Handler<T> eventHandler) throws java.lang.Exception
Polls for events using the given handler.
This poller will continue to feed events to the given handler until known available events are consumed orEventPoller.Handler.onEvent(Object, long, boolean)
returns false.
Note that it is possible for more events to become available while the current events are being processed. A further call to this method will process such events.- Parameters:
eventHandler
- the handler used to consume events- Returns:
- the state of the event poller after the poll is attempted
- Throws:
java.lang.Exception
- exceptions thrown from the event handler are propagated to the caller
-
newInstance
public static <T> EventPoller<T> newInstance(DataProvider<T> dataProvider, Sequencer sequencer, Sequence sequence, Sequence cursorSequence, Sequence... gatingSequences)
Creates an event poller. Most users will wantRingBuffer.newPoller(Sequence...)
which will set up the poller automatically- Type Parameters:
T
- the type of the event- Parameters:
dataProvider
- from which events are drawnsequencer
- the main sequencer which handles ordering of eventssequence
- the sequence which will be used by this event pollercursorSequence
- the cursor sequence, usually of the ring buffergatingSequences
- additional sequences to gate on- Returns:
- the event poller
-
-