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