Class 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 a BatchEventProcessor, 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.
    • Constructor Detail

      • EventPoller

        public EventPoller​(DataProvider<T> dataProvider,
                           Sequencer sequencer,
                           Sequence sequence,
                           Sequence gatingSequence)
        Creates an event poller. Most users will want RingBuffer.newPoller(Sequence...) which will set up the poller automatically
        Parameters:
        dataProvider - from which events are drawn
        sequencer - the main sequencer which handles ordering of events
        sequence - the sequence which will be used by this event poller
        gatingSequence - 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 or EventPoller.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 want RingBuffer.newPoller(Sequence...) which will set up the poller automatically
        Type Parameters:
        T - the type of the event
        Parameters:
        dataProvider - from which events are drawn
        sequencer - the main sequencer which handles ordering of events
        sequence - the sequence which will be used by this event poller
        cursorSequence - the cursor sequence, usually of the ring buffer
        gatingSequences - additional sequences to gate on
        Returns:
        the event poller
      • getSequence

        public Sequence getSequence()
        Get the Sequence being used by this event poller
        Returns:
        the sequence used by the event poller