addNamingListener() methods is referred
to as the target. The target, along with the scope, identify
the object(s) that the listener is interested in.
It is possible to register interest in a target that does not exist, but
there might be limitations in the extent to which this can be
supported by the service provider and underlying protocol/service.
If a service only supports registration for existing
targets, an attempt to register for a nonexistent target
results in a NameNotFoundException being thrown as early as possible,
preferably at the time addNamingListener() is called, or if that is
not possible, the listener will receive the exception through the
NamingExceptionEvent.
Also, for service providers that only support registration for existing
targets, when the target that a listener has registered for is
subsequently removed from the namespace, the listener is notified
via a NamingExceptionEvent (containing a
NameNotFoundException).
An application can use the method targetMustExist() to check
whether an EventContext supports registration
of nonexistent targets.
EventContext instance on which you invoke the
registration methods is the event source of the events that are
(potentially) generated.
The source is not necessarily the object named by the target.
Only when the target is the empty name is the object named by the target
the source.
In other words, the target,
along with the scope parameter, are used to identify
the object(s) that the listener is interested in, but the event source
is the EventContext instance with which the listener
has registered.
For example, suppose a listener makes the following registration:
NamespaceChangeListener listener = ...;
src.addNamingListener("x", SUBTREE_SCOPE, listener);
When an object named "x/y" is subsequently deleted, the corresponding
NamingEvent (evt) must contain:
evt.getEventContext() == src
evt.getOldBinding().getName().equals("x/y")
Furthermore, listener registration/deregistration is with
the EventContext
instance, and not with the corresponding object in the namespace.
If the program intends at some point to remove a listener, then it needs to
keep a reference to the EventContext instance on
which it invoked addNamingListener() (just as
it needs to keep a reference to the listener in order to remove it
later). It cannot expect to do a lookup() and get another instance of
an EventContext on which to perform the deregistration.
removeNamingListener().
NamingExceptionEvent.
Context.close() is invoked on the EventContext
instance with which it has registered.
EventContext instance that has outstanding
listeners will continue to exist and be maintained by the service provider.
NamingListener. There are subinterfaces of NamingListener
for different of event types of NamingEvent.
For example, the ObjectChangeListener
interface is for the NamingEvent.OBJECT_CHANGED event type.
To register interest in multiple event types, the listener implementation
should implement multiple NamingListener subinterfaces and use a
single invocation of addNamingListener().
In addition to reducing the number of method calls and possibly the code size
of the listeners, this allows some service providers to optimize the
registration.
Context instances in general, instances of
EventContext are not guaranteed to be thread-safe.
Care must be taken when multiple threads are accessing the same
EventContext concurrently.
See the
package description
for more information on threading issues.
| Modifier and Type | Field and Description |
|---|---|
| public static final int | OBJECT_SCOPE
Constant for expressing interest in events concerning the object named by the target. |
| public static final int | ONELEVEL_SCOPE
Constant for expressing interest in events concerning objects in the context named by the target, excluding the context named by the target. |
| public static final int | SUBTREE_SCOPE
Constant for expressing interest in events concerning objects in the subtree of the object named by the target, including the object named by the target. |
| Modifier and Type | Method and Description |
|---|---|
| public void | addNamingListener(Name
A nonnull name to be resolved relative to this context. target, int One of scope, NamingListener OBJECT_SCOPE, ONELEVEL_SCOPE, or
SUBTREE_SCOPE.The nonnull listener. l)Adds a listener for receiving naming events fired when the object(s) identified by a target and scope changes. |
| public void | addNamingListener(String
The nonnull string name of the object resolved relative
to this context. target, int One of scope, NamingListener OBJECT_SCOPE, ONELEVEL_SCOPE, or
SUBTREE_SCOPE.The nonnull listener. l)Adds a listener for receiving naming events fired when the object named by the string target name and scope changes. |
| public void | removeNamingListener(NamingListener
The nonnull listener. l)Removes a listener from receiving naming events fired
by this |
| public boolean | Returns: true if the target must exist; false if the target need not exist.Determines whether a listener can register interest in a target that does not exist. |
| OBJECT_SCOPE | back to summary |
|---|---|
| public static final int OBJECT_SCOPE Constant for expressing interest in events concerning the object named by the target.
The value of this constant is | |
| ONELEVEL_SCOPE | back to summary |
|---|---|
| public static final int ONELEVEL_SCOPE Constant for expressing interest in events concerning objects in the context named by the target, excluding the context named by the target.
The value of this constant is | |
| SUBTREE_SCOPE | back to summary |
|---|---|
| public static final int SUBTREE_SCOPE Constant for expressing interest in events concerning objects in the subtree of the object named by the target, including the object named by the target.
The value of this constant is | |
| addNamingListener | back to summary |
|---|---|
| public void addNamingListener(Name target, int scope, NamingListener l) throws NamingException Adds a listener for receiving naming events fired
when the object(s) identified by a target and scope changes.
The event source of those events is this context. See the
class description for a discussion on event source and target.
See the descriptions of the constants
When the listener is notified of an event, the listener may
in invoked in a thread other than the one in which
| |
| addNamingListener | back to summary |
|---|---|
| public void addNamingListener(String target, int scope, NamingListener l) throws NamingException Adds a listener for receiving naming events fired
when the object named by the string target name and scope changes.
See the overload that accepts a
| |
| removeNamingListener | back to summary |
|---|---|
| public void removeNamingListener(NamingListener l) throws NamingException Removes a listener from receiving naming events fired
by this
| |
| targetMustExist | back to summary |
|---|---|
| public boolean targetMustExist() throws NamingException Determines whether a listener can register interest in a target that does not exist.
| |