blob: 604c38d3dac676237945d3d18a6d02c561af229f [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2<html>
3<head>
4<!--
5Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved.
6DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7
8This code is free software; you can redistribute it and/or modify it
9under the terms of the GNU General Public License version 2 only, as
10published by the Free Software Foundation. Sun designates this
11particular file as subject to the "Classpath" exception as provided
12by Sun in the LICENSE file that accompanied this code.
13
14This code is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17version 2 for more details (a copy is included in the LICENSE file that
18accompanied this code).
19
20You should have received a copy of the GNU General Public License version
212 along with this work; if not, write to the Free Software Foundation,
22Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23
24Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
25CA 95054 USA or visit www.sun.com if you need additional information or
26have any questions.
27-->
28</head>
29<body bgcolor="white">
30
31Provides support for event notification when accessing naming and
32directory services.
33
34<p>
35This package defines the event notification operations of the Java Naming
36and Directory Interface<font size=-2><sup>TM</sup></font> (JNDI). &nbsp;
37JNDI provides naming and directory functionality to applications
38written in the Java programming language. It is designed to be
39independent of any specific naming or directory service
40implementation. Thus a variety of services--new, emerging, and
41already deployed ones--can be accessed in a common way.
42
43<h4>Naming Events</h4>
44<p>
45This package defines a <tt>NamingEvent</tt> class to represent an event
46that is generated by a naming/directory service.
47It also defines subinterfaces of <tt>Context</tt> and <tt>DirContext</tt>,
48called <tt>EventContext</tt> and <tt>EventDirContext</tt>,
49through which applications can register their interest in events
50fired by the context.
51<p>
52<tt>NamingEvent</tt> represents an event that occurs in a
53naming or directory service. There are two categories of naming events:
54<ul>
55<li>Those that affect the namespace (add/remove/rename an object)
56<li>Those that affect the objects' contents.
57</ul>
58Each category of events is handled by a corresponding listener:
59<tt>NamespaceChangeListener</tt>, <tt>ObjectChangeListener</tt>.
60<p>
61An application, for example, can register its interest in changes to
62objects in a context as follows:
63<blockquote>
64<pre>
65EventContext src =
66 (EventContext)(new InitialContext()).lookup("o=wiz,c=us");
67src.addNamingListener("ou=users", EventContext.ONELEVEL_SCOPE,
68 new ChangeHandler());
69...
70class ChangeHandler implements ObjectChangeListener {
71 public void objectChanged(NamingEvent evt) {
72 System.out.println(evt.getNewBinding());
73 }
74 public void namingExceptionThrown(NamingExceptionEvent evt) {
75 System.out.println(evt.getException());
76 }
77}
78</pre>
79</blockquote>
80
81<a name=THREADING></a>
82<h4>Threading Issues</h4>
83
84When an event is dispatched to a listener, the listener method (such
85as <tt>objectChanged()</tt>) may be executed in a thread other than the
86one in which the call to <tt>addNamingListener()</tt> was executed.
87The choice of which thread to use is made by the service provider.
88When an event is dispatched to multiple listeners, the service provider
89may choose (and is generally encouraged) to execute the listener methods
90concurrently in separate threads.
91<p>
92When a listener instance invokes <tt>NamingEvent.getEventContext()</tt>,
93it must take into account the possibility that other threads will be
94working with that context concurrently. Likewise, when a listener is
95registered via <tt>addNamingListener()</tt>, the registering thread
96must take into account the likely possibility that the service provider
97will later invoke the listeners in newly-created threads. As <tt>Context</tt>
98instances are not guaranteed to be thread-safe in general, all context
99operations must be synchronized as needed.
100
101<h4>Exception Handling</h4>
102
103When a listener registers for events with a context, the context might
104need to do some internal processing in order to collect information
105required to generate the events. The context, for example, might need
106to make a request to the server to register interest in changes
107on the server that will eventually be translated into events.
108If an exception occurs that prevents information about the events from
109being collected, the listener will never be notified of the events.
110When such an exception occurs, a <tt>NamingExceptionEvent</tt> is
111fired to notify the listener. The listener's
112<tt>namingExceptionThrown()</tt> method is invoked, as shown in the
113sample code above,
114and the listener is automatically deregistered.
115<p>
116
117<h2>Package Specification</h2>
118
119
120The JNDI API Specification and related documents can be found in the
121<a href="../../../../technotes/guides/jndi/index.html">JNDI documentation</a>.
122
123@since 1.3
124
125</body>
126</html>