Class EventProcessor<T>

java.lang.Object
org.apache.drill.common.EventProcessor<T>
Type Parameters:
T - the event class

public abstract class EventProcessor<T> extends Object
Process events serially.

Our use of listeners that deliver events directly can sometimes cause problems when events are delivered recursively in the middle of event handling by the same object. This helper class can be used to serialize events in such cases.

All events are queued until start() is called. The thread that calls start() will process all events in the order they were added until the queue is empty. Other threads will just enqueue their events.
When the queue is empty, the first thread that adds an event will start processing the queue until it's empty again.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    processEvent(T event)
    Process a single event.
    void
    sendEvent(T newEvent)
    Send an event to the processor.
    void
    Start processing events as soon as the queue isn't empty.
    If the queue is not empty, this method will process all events already in the queue and any event that will be added while the queue is being processed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EventProcessor

      public EventProcessor()
  • Method Details

    • sendEvent

      public void sendEvent(T newEvent)
      Send an event to the processor. the event will be queued to be processed after any prior events are processed, once processing actually starts.

      If an event's processing causes an exception, it will be added to any previous exceptions as a suppressed exception. Once all the currently queued events have been processed, a single exception will be thrown.

      Parameters:
      newEvent - the new event
      Throws:
      RuntimeException - if any exception is thrown while events are being processed
    • start

      public void start()
      Start processing events as soon as the queue isn't empty.
      If the queue is not empty, this method will process all events already in the queue and any event that will be added while the queue is being processed.
      Throws:
      RuntimeException - if any exception is thrown while events are being processed
    • processEvent

      protected abstract void processEvent(T event)
      Process a single event. Derived classes provide the implementation of this to process events.
      Parameters:
      event - the event to process