This package defines the event notification operations of the Java Naming and Directory Interface (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:
NamespaceChangeListener
, ObjectChangeListener
. 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()); } }
objectChanged()
) may be executed in a thread other than the one in which the call to addNamingListener()
was executed. The choice of which thread to use is made by the service provider. When an event is dispatched to multiple listeners, the service provider may choose (and is generally encouraged) to execute the listener methods concurrently in separate threads. 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.
NamingExceptionEvent
is fired to notify the listener. The listener's namingExceptionThrown()
method is invoked, as shown in the sample code above, and the listener is automatically deregistered. Class | Description |
---|---|
EventContext | Contains methods for registering/deregistering listeners to be notified of events fired when objects named in a context changes. |
EventDirContext | Contains methods for registering listeners to be notified of events fired when objects named in a directory context changes. |
NamespaceChangeListener | Specifies the methods that a listener interested in namespace changes must implement. |
NamingEvent | This class represents an event fired by a naming/directory service. |
NamingExceptionEvent | This class represents an event fired when the procedures/processes used to collect information for notifying listeners of NamingEvent s threw a NamingException . |
NamingListener | This interface is the root of listener interfaces that handle NamingEvent s. |
ObjectChangeListener | Specifies the method that a listener of a NamingEvent with event type of OBJECT_CHANGED must implement. |
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.naming/javax/naming/event/package-summary.html