While discussing some ongoing work,
Pascal came up with a very interesting idea: why won't we create a generic
mechanism for "declarative" registration of listeners?
The proposed event notification mechanism
based on the "whiteboard"
pattern , plus
a declarative way to register listeners,
ideas and implementation pieces from
OSGi's EventAdmin .
To me, this sounds like a great idea.
Listeners are ubiquitous and so are the problems associated with their
In theory, OSGi's EventAdmin service
should help work with listeners. Implementations details aside (it is not
in the SDK and needs to be tested for scalability), it suffers from the
same problem as OSGi services in general: a listener's bundle has to be
started and needs to register listener with OSGi. This creates startup
order problems and works against lazy activation of bundles. For OSGi services
add-on pieces that allow declarative registration of services (Declarative
Servieces, SPring, This startup problem sounds similar to the OSGi services
registration problem for which we are starting to get "declarative"
adds-ons such as DS and Springs.
The solution to the listener mechanism
proposed here is similar – to have a declarative way to describe listeners
via XML or manifest file.
In this model listeners are likely would
have to be singletons ("simple" approach), or we could support
user-provided factories to create listeners ("advanced" approach).
We could add a flag to the declaration of the listener to indicate if it
should receive events in case its bundle has not been activated yet. Most
likely we'll need to support both synchronous and asynchronous events,
just like EventAdmin does.
To me, the declarative event processing
mechanism truly sounds like a component that would be used by a number
of projects. What do you think about this idea?
 The description of the "whiteboard"
pattern can be found at http://www.osgi.org/documents/osgi_technology/whiteboard.pdf
 The OSGi specification can be downloaded
from http://www.osgi.org/ ; EventAdmin’s Javadoc can be found at http://www2.osgi.org/javadoc/r4/org/osgi/service/event/EventAdmin.html