javax.naming.event
Interface EventContext

All Superinterfaces:
Context sample code for javax.naming.Context definition code for javax.naming.Context
All Known Subinterfaces:
EventDirContext sample code for javax.naming.event.EventDirContext definition code for javax.naming.event.EventDirContext

public interface EventContext
extends Context sample code for javax.naming.Context definition code for javax.naming.Context

Contains methods for registering/deregistering listeners to be notified of events fired when objects named in a context changes.

Target

The name parameter in the 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 a EventContext supports registration of nonexistent targets.

Event Source

The 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 a EventContext on which to perform the deregistration.

Lifetime of Registration

A registered listener becomes deregistered when: Until that point, a EventContext instance that has outstanding listeners will continue to exist and be maintained by the service provider.

Listener Implementations

The registration/deregistration methods accept an instance of 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.

Threading Issues

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

Since:
1.3

Field Summary
static int OBJECT_SCOPE sample code for javax.naming.event.EventContext.OBJECT_SCOPE definition code for javax.naming.event.EventContext.OBJECT_SCOPE
          Constant for expressing interest in events concerning the object named by the target.
static int ONELEVEL_SCOPE sample code for javax.naming.event.EventContext.ONELEVEL_SCOPE definition code for javax.naming.event.EventContext.ONELEVEL_SCOPE
          Constant for expressing interest in events concerning objects in the context named by the target, excluding the context named by the target.
static int SUBTREE_SCOPE sample code for javax.naming.event.EventContext.SUBTREE_SCOPE definition code for javax.naming.event.EventContext.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.
 
Fields inherited from interface javax.naming.Context sample code for javax.naming.Context definition code for javax.naming.Context
APPLET sample code for javax.naming.Context.APPLET definition code for javax.naming.Context.APPLET , AUTHORITATIVE sample code for javax.naming.Context.AUTHORITATIVE definition code for javax.naming.Context.AUTHORITATIVE , BATCHSIZE sample code for javax.naming.Context.BATCHSIZE definition code for javax.naming.Context.BATCHSIZE , DNS_URL sample code for javax.naming.Context.DNS_URL definition code for javax.naming.Context.DNS_URL , INITIAL_CONTEXT_FACTORY sample code for javax.naming.Context.INITIAL_CONTEXT_FACTORY definition code for javax.naming.Context.INITIAL_CONTEXT_FACTORY , LANGUAGE sample code for javax.naming.Context.LANGUAGE definition code for javax.naming.Context.LANGUAGE , OBJECT_FACTORIES sample code for javax.naming.Context.OBJECT_FACTORIES definition code for javax.naming.Context.OBJECT_FACTORIES , PROVIDER_URL sample code for javax.naming.Context.PROVIDER_URL definition code for javax.naming.Context.PROVIDER_URL , REFERRAL sample code for javax.naming.Context.REFERRAL definition code for javax.naming.Context.REFERRAL , SECURITY_AUTHENTICATION sample code for javax.naming.Context.SECURITY_AUTHENTICATION definition code for javax.naming.Context.SECURITY_AUTHENTICATION , SECURITY_CREDENTIALS sample code for javax.naming.Context.SECURITY_CREDENTIALS definition code for javax.naming.Context.SECURITY_CREDENTIALS , SECURITY_PRINCIPAL sample code for javax.naming.Context.SECURITY_PRINCIPAL definition code for javax.naming.Context.SECURITY_PRINCIPAL , SECURITY_PROTOCOL sample code for javax.naming.Context.SECURITY_PROTOCOL definition code for javax.naming.Context.SECURITY_PROTOCOL , STATE_FACTORIES sample code for javax.naming.Context.STATE_FACTORIES definition code for javax.naming.Context.STATE_FACTORIES , URL_PKG_PREFIXES sample code for javax.naming.Context.URL_PKG_PREFIXES definition code for javax.naming.Context.URL_PKG_PREFIXES
 
Method Summary
 void addNamingListener sample code for javax.naming.event.EventContext.addNamingListener(javax.naming.Name, int, javax.naming.event.NamingListener) definition code for javax.naming.event.EventContext.addNamingListener(javax.naming.Name, int, javax.naming.event.NamingListener) (Name sample code for javax.naming.Name definition code for javax.naming.Name  target, int scope, NamingListener sample code for javax.naming.event.NamingListener definition code for javax.naming.event.NamingListener  l)
          Adds a listener for receiving naming events fired when the object(s) identified by a target and scope changes.
 void addNamingListener sample code for javax.naming.event.EventContext.addNamingListener(java.lang.String, int, javax.naming.event.NamingListener) definition code for javax.naming.event.EventContext.addNamingListener(java.lang.String, int, javax.naming.event.NamingListener) (String sample code for java.lang.String definition code for java.lang.String  target, int scope, NamingListener sample code for javax.naming.event.NamingListener definition code for javax.naming.event.NamingListener  l)
          Adds a listener for receiving naming events fired when the object named by the string target name and scope changes.
 void removeNamingListener sample code for javax.naming.event.EventContext.removeNamingListener(javax.naming.event.NamingListener) definition code for javax.naming.event.EventContext.removeNamingListener(javax.naming.event.NamingListener) (NamingListener sample code for javax.naming.event.NamingListener definition code for javax.naming.event.NamingListener  l)
          Removes a listener from receiving naming events fired by this EventContext.
 boolean targetMustExist sample code for javax.naming.event.EventContext.targetMustExist() definition code for javax.naming.event.EventContext.targetMustExist() ()
          Determines whether a listener can register interest in a target that does not exist.
 
Methods inherited from interface javax.naming.Context sample code for javax.naming.Context definition code for javax.naming.Context
addToEnvironment sample code for javax.naming.Context.addToEnvironment(java.lang.String, java.lang.Object) definition code for javax.naming.Context.addToEnvironment(java.lang.String, java.lang.Object) , bind sample code for javax.naming.Context.bind(javax.naming.Name, java.lang.Object) definition code for javax.naming.Context.bind(javax.naming.Name, java.lang.Object) , bind sample code for javax.naming.Context.bind(java.lang.String, java.lang.Object) definition code for javax.naming.Context.bind(java.lang.String, java.lang.Object) , close sample code for javax.naming.Context.close() definition code for javax.naming.Context.close() , composeName sample code for javax.naming.Context.composeName(javax.naming.Name, javax.naming.Name) definition code for javax.naming.Context.composeName(javax.naming.Name, javax.naming.Name) , composeName sample code for javax.naming.Context.composeName(java.lang.String, java.lang.String) definition code for javax.naming.Context.composeName(java.lang.String, java.lang.String) , createSubcontext sample code for javax.naming.Context.createSubcontext(javax.naming.Name) definition code for javax.naming.Context.createSubcontext(javax.naming.Name) , createSubcontext sample code for javax.naming.Context.createSubcontext(java.lang.String) definition code for javax.naming.Context.createSubcontext(java.lang.String) , destroySubcontext sample code for javax.naming.Context.destroySubcontext(javax.naming.Name) definition code for javax.naming.Context.destroySubcontext(javax.naming.Name) , destroySubcontext sample code for javax.naming.Context.destroySubcontext(java.lang.String) definition code for javax.naming.Context.destroySubcontext(java.lang.String) , getEnvironment sample code for javax.naming.Context.getEnvironment() definition code for javax.naming.Context.getEnvironment() , getNameInNamespace sample code for javax.naming.Context.getNameInNamespace() definition code for javax.naming.Context.getNameInNamespace() , getNameParser sample code for javax.naming.Context.getNameParser(javax.naming.Name) definition code for javax.naming.Context.getNameParser(javax.naming.Name) , getNameParser sample code for javax.naming.Context.getNameParser(java.lang.String) definition code for javax.naming.Context.getNameParser(java.lang.String) , list sample code for javax.naming.Context.list(javax.naming.Name) definition code for javax.naming.Context.list(javax.naming.Name) , list sample code for javax.naming.Context.list(java.lang.String) definition code for javax.naming.Context.list(java.lang.String) , listBindings sample code for javax.naming.Context.listBindings(javax.naming.Name) definition code for javax.naming.Context.listBindings(javax.naming.Name) , listBindings sample code for javax.naming.Context.listBindings(java.lang.String) definition code for javax.naming.Context.listBindings(java.lang.String) , lookup sample code for javax.naming.Context.lookup(javax.naming.Name) definition code for javax.naming.Context.lookup(javax.naming.Name) , lookup sample code for javax.naming.Context.lookup(java.lang.String) definition code for javax.naming.Context.lookup(java.lang.String) , lookupLink sample code for javax.naming.Context.lookupLink(javax.naming.Name) definition code for javax.naming.Context.lookupLink(javax.naming.Name) , lookupLink sample code for javax.naming.Context.lookupLink(java.lang.String) definition code for javax.naming.Context.lookupLink(java.lang.String) , rebind sample code for javax.naming.Context.rebind(javax.naming.Name, java.lang.Object) definition code for javax.naming.Context.rebind(javax.naming.Name, java.lang.Object) , rebind sample code for javax.naming.Context.rebind(java.lang.String, java.lang.Object) definition code for javax.naming.Context.rebind(java.lang.String, java.lang.Object) , removeFromEnvironment sample code for javax.naming.Context.removeFromEnvironment(java.lang.String) definition code for javax.naming.Context.removeFromEnvironment(java.lang.String) , rename sample code for javax.naming.Context.rename(javax.naming.Name, javax.naming.Name) definition code for javax.naming.Context.rename(javax.naming.Name, javax.naming.Name) , rename sample code for javax.naming.Context.rename(java.lang.String, java.lang.String) definition code for javax.naming.Context.rename(java.lang.String, java.lang.String) , unbind sample code for javax.naming.Context.unbind(javax.naming.Name) definition code for javax.naming.Context.unbind(javax.naming.Name) , unbind sample code for javax.naming.Context.unbind(java.lang.String) definition code for javax.naming.Context.unbind(java.lang.String)
 

Field Detail

OBJECT_SCOPE sample code for javax.naming.event.EventContext.OBJECT_SCOPE

static final int OBJECT_SCOPE
Constant for expressing interest in events concerning the object named by the target.

The value of this constant is 0.

See Also:
Constant Field Values

ONELEVEL_SCOPE sample code for javax.naming.event.EventContext.ONELEVEL_SCOPE

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

See Also:
Constant Field Values

SUBTREE_SCOPE sample code for javax.naming.event.EventContext.SUBTREE_SCOPE

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

See Also:
Constant Field Values
Method Detail

addNamingListener sample code for javax.naming.event.EventContext.addNamingListener(javax.naming.Name, int, javax.naming.event.NamingListener) definition code for javax.naming.event.EventContext.addNamingListener(javax.naming.Name, int, javax.naming.event.NamingListener)

void addNamingListener(Name sample code for javax.naming.Name definition code for javax.naming.Name  target,
                       int scope,
                       NamingListener sample code for javax.naming.event.NamingListener definition code for javax.naming.event.NamingListener  l)
                       throws NamingException sample code for javax.naming.NamingException definition code for javax.naming.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 OBJECT_SCOPE, ONELEVEL_SCOPE, and SUBTREE_SCOPE to see how scope affects the registration.

target needs to name a context only when scope is ONELEVEL_SCOPE. target may name a non-context if scope is either OBJECT_SCOPE or SUBTREE_SCOPE. Using SUBTREE_SCOPE for a non-context might be useful, for example, if the caller does not know in advance whether target is a context and just wants to register interest in the (possibly degenerate subtree) rooted at target.

When the listener is notified of an event, the listener may in invoked in a thread other than the one in which addNamingListener() is executed. Care must be taken when multiple threads are accessing the same EventContext concurrently. See the package description for more information on threading issues.

Parameters:
target - A nonnull name to be resolved relative to this context.
scope - One of OBJECT_SCOPE, ONELEVEL_SCOPE, or SUBTREE_SCOPE.
l - The nonnull listener.
Throws:
NamingException sample code for javax.naming.NamingException definition code for javax.naming.NamingException - If a problem was encountered while adding the listener.
See Also:
removeNamingListener(javax.naming.event.NamingListener) sample code for javax.naming.event.EventContext.removeNamingListener(javax.naming.event.NamingListener) definition code for javax.naming.event.EventContext.removeNamingListener(javax.naming.event.NamingListener)

addNamingListener sample code for javax.naming.event.EventContext.addNamingListener(java.lang.String, int, javax.naming.event.NamingListener) definition code for javax.naming.event.EventContext.addNamingListener(java.lang.String, int, javax.naming.event.NamingListener)

void addNamingListener(String sample code for java.lang.String definition code for java.lang.String  target,
                       int scope,
                       NamingListener sample code for javax.naming.event.NamingListener definition code for javax.naming.event.NamingListener  l)
                       throws NamingException sample code for javax.naming.NamingException definition code for javax.naming.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 Name for details.

Parameters:
target - The nonnull string name of the object resolved relative to this context.
scope - One of OBJECT_SCOPE, ONELEVEL_SCOPE, or SUBTREE_SCOPE.
l - The nonnull listener.
Throws:
NamingException sample code for javax.naming.NamingException definition code for javax.naming.NamingException - If a problem was encountered while adding the listener.
See Also:
removeNamingListener(javax.naming.event.NamingListener) sample code for javax.naming.event.EventContext.removeNamingListener(javax.naming.event.NamingListener) definition code for javax.naming.event.EventContext.removeNamingListener(javax.naming.event.NamingListener)

removeNamingListener sample code for javax.naming.event.EventContext.removeNamingListener(javax.naming.event.NamingListener) definition code for javax.naming.event.EventContext.removeNamingListener(javax.naming.event.NamingListener)

void removeNamingListener(NamingListener sample code for javax.naming.event.NamingListener definition code for javax.naming.event.NamingListener  l)
                          throws NamingException sample code for javax.naming.NamingException definition code for javax.naming.NamingException 
Removes a listener from receiving naming events fired by this EventContext. The listener may have registered more than once with this EventContext, perhaps with different target/scope arguments. After this method is invoked, the listener will no longer receive events with this EventContext instance as the event source (except for those events already in the process of being dispatched). If the listener was not, or is no longer, registered with this EventContext instance, this method does not do anything.

Parameters:
l - The nonnull listener.
Throws:
NamingException sample code for javax.naming.NamingException definition code for javax.naming.NamingException - If a problem was encountered while removing the listener.
See Also:
addNamingListener(javax.naming.Name, int, javax.naming.event.NamingListener) sample code for javax.naming.event.EventContext.addNamingListener(javax.naming.Name, int, javax.naming.event.NamingListener) definition code for javax.naming.event.EventContext.addNamingListener(javax.naming.Name, int, javax.naming.event.NamingListener)

targetMustExist sample code for javax.naming.event.EventContext.targetMustExist() definition code for javax.naming.event.EventContext.targetMustExist()

boolean targetMustExist()
                        throws NamingException sample code for javax.naming.NamingException definition code for javax.naming.NamingException 
Determines whether a listener can register interest in a target that does not exist.

Returns:
true if the target must exist; false if the target need not exist.
Throws:
NamingException sample code for javax.naming.NamingException definition code for javax.naming.NamingException - If the context's behavior in this regard cannot be determined.