Subject Re: [Firebird-Java] Events
Author Gabriel Reid
> > The relevant parts of the relevant interfaces are as follows:
> >
> > // -------------------------------------------------------------
> >
> > interface EventManager {
> >
> > void addEventListener(String eventName, EventListener listener);
> >
> > void removeEventListener(String eventName, EventListener listener);
> >
> > int waitForEvent(String eventName);
> > throws InterruptedException;
> >
> > int waitForEvent(String eventName, int timeout)
> > throws InterruptedException;
> >
> > void connect();
> >
> > void disconnect();
> >
> > // Getters and setters for connection info not shown
> > }
> >
>
> You should understand that these interfaces won't handle multiple events
> or return event counts that allow the application to detect multiple
> postings.

This is (mostly) true of the waitForEvent methods, but not true of the
methods that use an EventListener. A single object that implements
EventListener can be registered for multiple events, and will be called
asynchronously for each event notification on each of the separate
events. In the implementation of EventManager, the waitForEvent methods
are built on top of the EventListener-based methods, which does allow
for them to handle multiple postings in one event notification, if
that's how it's delivered.

> I'm not at all sure that an event interface built around single events
> is all that useful. If I were doing it, I'd want to ability to block on
> one of any number of events and the ability to get a callback from a
> dedicated listening thread.

As stated above, the implementation of the waitForEvent methods is based
upon waiting on an asynchronous call on an EventListener object. A
single EventListener could be registered for several events, and
notify() an object that is being waited on when it receives an event
notification, thereby allowing blocking on multiple events. If this is
interesting to users of Jaybird, I would be happy to add it to the
EventManager interface and implementation.

Gabriel