Interface EventContext
- All Superinterfaces:
Context
- All Known Subinterfaces:
EventDirContext
Target
The name parameter in theaddNamingListener()
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.
Event Source
TheEventContext
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:
When an object named "x/y" is subsequently deleted, the correspondingNamespaceChangeListener listener = ...; src.addNamingListener("x", SUBTREE_SCOPE, listener);
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.
Lifetime of Registration
A registered listener becomes deregistered when:- It is removed using
removeNamingListener()
. - An exception is thrown while collecting information about the events.
That is, when the listener receives a
NamingExceptionEvent
. Context.close()
is invoked on theEventContext
instance with which it has registered.
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 ofNamingListener
. 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
LikeContext
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
FieldsModifier and TypeFieldDescriptionstatic final int
Constant for expressing interest in events concerning the object named by the target.static final int
Constant for expressing interest in events concerning objects in the context named by the target, excluding the context named by the target.static final int
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 declared in interface Context
AUTHORITATIVE, BATCHSIZE, DNS_URL, INITIAL_CONTEXT_FACTORY, LANGUAGE, OBJECT_FACTORIES, PROVIDER_URL, REFERRAL, SECURITY_AUTHENTICATION, SECURITY_CREDENTIALS, SECURITY_PRINCIPAL, SECURITY_PROTOCOL, STATE_FACTORIES, URL_PKG_PREFIXES
Modifier and TypeFieldDescriptionstatic final String
Constant that holds the name of the environment property for specifying the authoritativeness of the service requested.static final String
Constant that holds the name of the environment property for specifying the batch size to use when returning data via the service's protocol.static final String
Constant that holds the name of the environment property for specifying the DNS host and domain names to use for the JNDI URL context (for example, "dns://somehost/wiz.com").static final String
Constant that holds the name of the environment property for specifying the initial context factory to use.static final String
Constant that holds the name of the environment property for specifying the preferred language to use with the service.static final String
Constant that holds the name of the environment property for specifying the list of object factories to use.static final String
Constant that holds the name of the environment property for specifying configuration information for the service provider to use.static final String
Constant that holds the name of the environment property for specifying how referrals encountered by the service provider are to be processed.static final String
Constant that holds the name of the environment property for specifying the security level to use.static final String
Constant that holds the name of the environment property for specifying the credentials of the principal for authenticating the caller to the service.static final String
Constant that holds the name of the environment property for specifying the identity of the principal for authenticating the caller to the service.static final String
Constant that holds the name of the environment property for specifying the security protocol to use.static final String
Constant that holds the name of the environment property for specifying the list of state factories to use.static final String
Constant that holds the name of the environment property for specifying the list of package prefixes to use when loading in URL context factories. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addNamingListener
(String target, int scope, NamingListener l) Adds a listener for receiving naming events fired when the object named by the string target name and scope changes.void
addNamingListener
(Name target, int scope, NamingListener l) Adds a listener for receiving naming events fired when the object(s) identified by a target and scope changes.void
Removes a listener from receiving naming events fired by thisEventContext
.boolean
Determines whether a listener can register interest in a target that does not exist.Methods declared in interface Context
addToEnvironment, bind, bind, close, composeName, composeName, createSubcontext, createSubcontext, destroySubcontext, destroySubcontext, getEnvironment, getNameInNamespace, getNameParser, getNameParser, list, list, listBindings, listBindings, lookup, lookup, lookupLink, lookupLink, rebind, rebind, removeFromEnvironment, rename, rename, unbind, unbind
Modifier and TypeMethodDescriptionaddToEnvironment
(String propName, Object propVal) Adds a new environment property to the environment of this context.void
Binds a name to an object.void
Binds a name to an object.void
close()
Closes this context.composeName
(String name, String prefix) Composes the name of this context with a name relative to this context.composeName
(Name name, Name prefix) Composes the name of this context with a name relative to this context.createSubcontext
(String name) Creates and binds a new context.createSubcontext
(Name name) Creates and binds a new context.void
destroySubcontext
(String name) Destroys the named context and removes it from the namespace.void
destroySubcontext
(Name name) Destroys the named context and removes it from the namespace.Hashtable
<?, ?> Retrieves the environment in effect for this context.Retrieves the full name of this context within its own namespace.getNameParser
(String name) Retrieves the parser associated with the named context.getNameParser
(Name name) Retrieves the parser associated with the named context.Enumerates the names bound in the named context, along with the class names of objects bound to them.Enumerates the names bound in the named context, along with the class names of objects bound to them.listBindings
(String name) Enumerates the names bound in the named context, along with the objects bound to them.listBindings
(Name name) Enumerates the names bound in the named context, along with the objects bound to them.Retrieves the named object.Retrieves the named object.lookupLink
(String name) Retrieves the named object, following links except for the terminal atomic component of the name.lookupLink
(Name name) Retrieves the named object, following links except for the terminal atomic component of the name.void
Binds a name to an object, overwriting any existing binding.void
Binds a name to an object, overwriting any existing binding.removeFromEnvironment
(String propName) Removes an environment property from the environment of this context.void
Binds a new name to the object bound to an old name, and unbinds the old name.void
Binds a new name to the object bound to an old name, and unbinds the old name.void
Unbinds the named object.void
Unbinds the named object.
-
Field Details
-
OBJECT_SCOPE
static final int OBJECT_SCOPEConstant for expressing interest in events concerning the object named by the target.The value of this constant is
0
.- See Also:
-
ONELEVEL_SCOPE
static final int ONELEVEL_SCOPEConstant 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:
-
SUBTREE_SCOPE
static final int SUBTREE_SCOPEConstant 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:
-
-
Method Details
-
addNamingListener
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 constantsOBJECT_SCOPE
,ONELEVEL_SCOPE
, andSUBTREE_SCOPE
to see howscope
affects the registration.target
needs to name a context only whenscope
isONELEVEL_SCOPE
.target
may name a non-context ifscope
is eitherOBJECT_SCOPE
orSUBTREE_SCOPE
. UsingSUBTREE_SCOPE
for a non-context might be useful, for example, if the caller does not know in advance whethertarget
is a context and just wants to register interest in the (possibly degenerate subtree) rooted attarget
.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 sameEventContext
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 ofOBJECT_SCOPE
,ONELEVEL_SCOPE
, orSUBTREE_SCOPE
.l
- The nonnull listener.- Throws:
NamingException
- If a problem was encountered while adding the listener.- See Also:
-
addNamingListener
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 aName
for details.- Parameters:
target
- The nonnull string name of the object resolved relative to this context.scope
- One ofOBJECT_SCOPE
,ONELEVEL_SCOPE
, orSUBTREE_SCOPE
.l
- The nonnull listener.- Throws:
NamingException
- If a problem was encountered while adding the listener.- See Also:
-
removeNamingListener
Removes a listener from receiving naming events fired by thisEventContext
. The listener may have registered more than once with thisEventContext
, perhaps with different target/scope arguments. After this method is invoked, the listener will no longer receive events with thisEventContext
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 thisEventContext
instance, this method does not do anything.- Parameters:
l
- The nonnull listener.- Throws:
NamingException
- If a problem was encountered while removing the listener.- See Also:
-
targetMustExist
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
- If the context's behavior in this regard cannot be determined.
-