An EventProcessor waits for the arrival
of Events on the event queue. As Events are dequeued, they are processed
using the EventHandler associated with the
Event. The EventProcessor runs in a separate thread so
that event dispatching does not adversely affect the processing of events.
If an exception is thrown while processing an Event, it can be caught and processed by an error
handler. The error handler is a regular EventHandler. The Event generated when an error occurs contains an
array of 2 items (the exception and the original event that caused the
exception). This array is available via the data attribute of the Event.
An EventHandler to be used to process an
error that may be generated when an exception is thrown while processing
Events off of the event queue. This handler can use the data attribute of
the passed Event to gain access to the exception
and the original Event that caused the exception.
Creates an EventProcessor with the
- The queue where Events are consumed and processed. This same queue must be
passed to the constructor of the EventDispatcher. Furthermore, this queue
must support synchronization so multiple threads can access it
- An optional EventHandler to be used to
process an error that may be generated when an exception is thrown while
processing Events off the event queue. By default, errors are not caught.
Invoked repeatedly by the worker thread that continously processes Events
from the event queue. It overrides the default implementation in WorkerThread.
Stops the EventProcessor in a graceful
manner by generating an empty Event to wake up the
worker thread waiting on the event queue otherwise we end in a deadlock.
Process an Event from the event queue waiting
(forever possibly) for one to arrive. This method is called repeatedly by a
worker thread. It should be noted that when the worker thread is told to
stop running, it first generates an empty event so this thread will awaken
one final time.