This package defines the event notification operations of the Java Naming and Directory InterfaceTM (JNDI). JNDI provides naming and directory functionality to applications written in the Java programming language. It is designed to be independent of any specific naming or directory service implementation. Thus a variety of services--new, emerging, and already deployed ones--can be accessed in a common way.
This package defines a NamingEvent class to represent an event that is generated by a naming/directory service. It also defines subinterfaces of Context and DirContext, called EventContext and EventDirContext, through which applications can register their interest in events fired by the context.
NamingEvent represents an event that occurs in a naming or directory service. There are two categories of naming events:
An application, for example, can register its interest in changes to objects in a context as follows:
EventContext src = (EventContext)(new InitialContext()).lookup("o=wiz,c=us"); src.addNamingListener("ou=users", EventContext.ONELEVEL_SCOPE, new ChangeHandler()); ... class ChangeHandler implements ObjectChangeListener { public void objectChanged(NamingEvent evt) { System.out.println(evt.getNewBinding()); } public void namingExceptionThrown(NamingExceptionEvent evt) { System.out.println(evt.getException()); } }
When a listener instance invokes NamingEvent.getEventContext(), it must take into account the possibility that other threads will be working with that context concurrently. Likewise, when a listener is registered via addNamingListener(), the registering thread must take into account the likely possibility that the service provider will later invoke the listeners in newly-created threads. As Context instances are not guaranteed to be thread-safe in general, all context operations must be synchronized as needed.