jdk/src/share/classes/javax/management/NotificationBroadcaster.java
author sjiang
Thu, 31 Jul 2008 15:31:13 +0200
changeset 1004 5ba8217eb504
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
5108776: Add reliable event handling to the JMX API 6218920: API bug - impossible to delete last MBeanServerForwarder on a connector Reviewed-by: emcmanus
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2005 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package javax.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.concurrent.CopyOnWriteArrayList;  // for Javadoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <p>Interface implemented by an MBean that emits Notifications. It
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * allows a listener to be registered with the MBean as a notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * listener.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <h3>Notification dispatch</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>When an MBean emits a notification, it considers each listener that has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * added with {@link #addNotificationListener addNotificationListener} and not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * subsequently removed with {@link #removeNotificationListener removeNotificationListener}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * If a filter was provided with that listener, and if the filter's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * {@link NotificationFilter#isNotificationEnabled isNotificationEnabled} method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * false, the listener is ignored.  Otherwise, the listener's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * {@link NotificationListener#handleNotification handleNotification} method is called with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * the notification, as well as the handback object that was provided to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * {@code addNotificationListener}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>If the same listener is added more than once, it is considered as many times as it was
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * added.  It is often useful to add the same listener with different filters or handback
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * objects.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>Implementations of this interface can differ regarding the thread in which the methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * of filters and listeners are called.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>If the method call of a filter or listener throws an {@link Exception}, then that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * exception should not prevent other listeners from being invoked.  However, if the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * call throws an {@link Error}, then it is recommended that processing of the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * stop at that point, and if it is possible to propagate the {@code Error} to the sender of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * the notification, this should be done.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>New code should use the {@link NotificationEmitter} interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * instead.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>Implementations of this interface and of {@code NotificationEmitter}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * should be careful about synchronization.  In particular, it is not a good
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * idea for an implementation to hold any locks while it is calling a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * listener.  To deal with the possibility that the list of listeners might
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * change while a notification is being dispatched, a good strategy is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * use a {@link CopyOnWriteArrayList} for this list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
public interface NotificationBroadcaster {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Adds a listener to this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param listener The listener object which will handle the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * notifications emitted by the broadcaster.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param filter The filter object. If filter is null, no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * filtering will be performed before handling notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param handback An opaque object to be sent back to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * listener when a notification is emitted. This object cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * used by the Notification broadcaster object. It should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * resent unchanged with the notification to the listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @exception IllegalArgumentException Listener parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @see #removeNotificationListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public void addNotificationListener(NotificationListener listener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                        NotificationFilter filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                        Object handback)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            throws java.lang.IllegalArgumentException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Removes a listener from this MBean.  If the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * has been registered with different handback objects or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * notification filters, all entries corresponding to the listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * will be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param listener A listener that was previously added to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @exception ListenerNotFoundException The listener is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * registered with the MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @see #addNotificationListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @see NotificationEmitter#removeNotificationListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public void removeNotificationListener(NotificationListener listener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            throws ListenerNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * <p>Returns an array indicating, for each notification this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * MBean may send, the name of the Java class of the notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * and the notification type.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <p>It is not illegal for the MBean to send notifications not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * described in this array.  However, some clients of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * server may depend on the array being complete for their correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * functioning.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @return the array of possible notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public MBeanNotificationInfo[] getNotificationInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}