Package org.apache.drill.common
Class EventProcessor<T>
java.lang.Object
org.apache.drill.common.EventProcessor<T>
- Type Parameters:
T
- the event class
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
When the queue is empty, the first thread that adds an event will start processing the queue until it's empty again.
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
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
processEvent
(T event) Process a single event.void
Send an event to the processor.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.
-
Constructor Details
-
EventProcessor
public EventProcessor()
-
-
Method Details
-
sendEvent
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
Process a single event. Derived classes provide the implementation of this to process events.- Parameters:
event
- the event to process
-