Event Notification
In addition to finding, browsing, searching, and altering
objects stored in a naming or directory service, the JNDI API also
supports the concept of event notification . This involves registering listeners for various types
of events that may occur in a naming/directory server. This
functionality is provided through the javax.naming.event
package.
Essentially, JNDI event notification is similar to other event models in the Java platform: you obtain a reference to an event source and then register an event listener with the source. When the specified events fire in the event source, notifications are made by invoking callback methods on the event listeners.
Event Sources
Event sources in JNDI are represented by special
subclasses of Context
and
DirContext
: EventContext
and EventDirContext
, both from the javax.naming.event
package. These
interfaces provide the additional functionality required to register
event listeners with a naming/directory service. Acquiring a
reference to an event source is simply a matter of casting a
returned Context
or DirContext
. For example, if we wanted to
get an event source for the "person"
branch of a directory
service:
Context ctx = new InitialContext(props).lookup("ou=person"); EventDirContext evCtx = (EventDirContext)ctx;
In order to take advantage of event notification, the JNDI
provider (and the underlying naming or directory service) needs to
support event notification, and its Context
implementations need to implement
the EventContext ...
Get Java Enterprise in a Nutshell, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.