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