APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.jndi.ldap

pack-priv final Class EventSupport

extends Object
Class Inheritance
Imports
java.util.Hashtable, .Vector, .EventObject, .Iterator, .Map, java.util.concurrent.locks.ReentrantLock, javax.naming.*, javax.naming.event.*, javax.naming.directory.SearchControls, javax.naming.ldap.UnsolicitedNotificationListener, .UnsolicitedNotificationEvent, .UnsolicitedNotification

This is a utility class that can be used by a context that supports event notification. You can use an instance of this class as a member field of your context and delegate various work to it. It is currently structured so that each context should have its own EventSupport (instead of static version shared by all contexts of a service provider).

This class supports two types of listeners: those that register for NamingEvents, and those for UnsolicitedNotificationEvents (they can be mixed into the same listener). For NamingEvent listeners, it maintains a hashtable that maps registration requests--the key--to notifiers--the value. Each registration request consists of:

A notifier (NamingEventNotifier) is a worker thread that is responsible for gathering information for generating events requested by its listeners. Each notifier maintains its own list of listeners; these listeners have all made the same registration request (at different times) and implements the same NamingListener interfaces.

For unsolicited listeners, this class maintains a vector, unsolicited. When an unsolicited listener is registered, this class adds itself to the context's LdapClient. When LdapClient receives an unsolicited notification, it notifies this EventSupport to fire an event to the the listeners. Special handling in LdapClient is done for the DISCONNECT notification. [It results in the EventSupport firing also a NamingExceptionEvent to the unsolicited listeners.]

When a context no longer needs this EventSupport, it should invoke cleanup() on it.

Registration

When a registration request is made, this class attempts to find an existing notifier that's already working on the request. If one is found, the listener is added to the notifier's list. If one is not found, a new notifier is created for the listener.

Deregistration

When a deregistration request is made, this class attempts to find its corresponding notifier. If the notifier is found, the listener is removed from the notifier's list. If the listener is the last listener on the list, the notifier's thread is terminated and removed from this class's hashtable. Nothing happens if the notifier is not found.

Event Dispatching

The notifiers are responsible for gather information for generating events requested by their respective listeners. When a notifier gets sufficient information to generate an event, it creates invokes the appropriate fireXXXEvent on this class with the information and list of listeners. This causes an event and the list of listeners to be added to the event queue. This class maintains an event queue and a dispatching thread that dequeues events from the queue and dispatches them to the listeners.

Synchronization

This class is used by the main thread (LdapCtx) to add/remove listeners. It is also used asynchronously by NamingEventNotifiers threads and the context's Connection thread. It is used by the notifier threads to queue events and to update the notifiers list when the notifiers exit. It is used by the Connection thread to fire unsolicited notifications. Methods that access/update the 'unsolicited' and 'notifiers' lists are thread-safe.
Author
Rosanna Lee

Field Summary

Modifier and TypeField and Description
private LdapCtx
private static final boolean
private EventQueue
pack-priv final ReentrantLock
private Hashtable<NotifierArgs, NamingEventNotifier>
notifiers

NamingEventNotifiers; hashed by search arguments;

private Vector<UnsolicitedNotificationListener>
unsolicited

List of unsolicited notification listeners.

Constructor Summary

AccessConstructor and Description
pack-priv
EventSupport(LdapCtx ctx)

Constructs EventSupport for ctx.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addNamingListener(String nm, int scope, NamingListener l)

Adds l to list of listeners interested in nm.

pack-priv void
addNamingListener(String nm, String filter, SearchControls ctls, NamingListener l)

Adds l to list of listeners interested in nm and filter.

pack-priv void
cleanup()

Stops notifier threads that are collecting event data and stops the event queue from dispatching events.

pack-priv void
fireUnsolicited(Object obj)

Fire an event to unsolicited listeners.

pack-priv boolean
pack-priv void
queueEvent(EventObject event, Vector<? extends NamingListener> vector)

Add the event and vector of listeners to the queue to be delivered.

pack-priv void
removeDeadNotifier(NotifierArgs info)

package private; Called by NamingEventNotifier to remove itself when it encounters a NamingException.

pack-priv void
removeNamingListener(NamingListener l)

Removes l from all notifiers in this context.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ctxback to summary
private LdapCtx ctx
debugback to summary
private static final boolean debug
eventQueueback to summary
private EventQueue eventQueue
lockback to summary
pack-priv final ReentrantLock lock
notifiersback to summary
private Hashtable<NotifierArgs, NamingEventNotifier> notifiers

NamingEventNotifiers; hashed by search arguments;

unsolicitedback to summary
private Vector<UnsolicitedNotificationListener> unsolicited

List of unsolicited notification listeners.

Constructor Detail

EventSupportback to summary
pack-priv EventSupport(LdapCtx ctx)

Constructs EventSupport for ctx. Do we need to record the name of the target context? Or can we assume that EventSupport is called on a resolved context? Do we need other add/remove-NamingListener methods? package private;

Method Detail

addNamingListenerback to summary
pack-priv void addNamingListener(String nm, int scope, NamingListener l) throws NamingException

Adds l to list of listeners interested in nm.

addNamingListenerback to summary
pack-priv void addNamingListener(String nm, String filter, SearchControls ctls, NamingListener l) throws NamingException

Adds l to list of listeners interested in nm and filter.

cleanupback to summary
pack-priv void cleanup()

Stops notifier threads that are collecting event data and stops the event queue from dispatching events. Package private; used by LdapCtx.

fireUnsolicitedback to summary
pack-priv void fireUnsolicited(Object obj)

Fire an event to unsolicited listeners. package private; Called by LdapCtx when its clnt receives an unsolicited notification.

hasUnsolicitedback to summary
pack-priv boolean hasUnsolicited()
queueEventback to summary
pack-priv void queueEvent(EventObject event, Vector<? extends NamingListener> vector)

Add the event and vector of listeners to the queue to be delivered. An event dispatcher thread dequeues events from the queue and dispatches them to the registered listeners. Package private; used by NamingEventNotifier to fire events

removeDeadNotifierback to summary
pack-priv void removeDeadNotifier(NotifierArgs info)

package private; Called by NamingEventNotifier to remove itself when it encounters a NamingException.

removeNamingListenerback to summary
pack-priv void removeNamingListener(NamingListener l)

Removes l from all notifiers in this context.