O'Reilly logo

Java Enterprise in a Nutshell, Third Edition by William Crawford, Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required