001 /*
002 * Copyright 1999-2005 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.management;
027
028 import java.util.concurrent.CopyOnWriteArrayList; // for Javadoc
029
030 /**
031 * <p>Interface implemented by an MBean that emits Notifications. It
032 * allows a listener to be registered with the MBean as a notification
033 * listener.</p>
034 *
035 * <h3>Notification dispatch</h3>
036 *
037 * <p>When an MBean emits a notification, it considers each listener that has been
038 * added with {@link #addNotificationListener addNotificationListener} and not
039 * subsequently removed with {@link #removeNotificationListener removeNotificationListener}.
040 * If a filter was provided with that listener, and if the filter's
041 * {@link NotificationFilter#isNotificationEnabled isNotificationEnabled} method returns
042 * false, the listener is ignored. Otherwise, the listener's
043 * {@link NotificationListener#handleNotification handleNotification} method is called with
044 * the notification, as well as the handback object that was provided to
045 * {@code addNotificationListener}.</p>
046 *
047 * <p>If the same listener is added more than once, it is considered as many times as it was
048 * added. It is often useful to add the same listener with different filters or handback
049 * objects.</p>
050 *
051 * <p>Implementations of this interface can differ regarding the thread in which the methods
052 * of filters and listeners are called.</p>
053 *
054 * <p>If the method call of a filter or listener throws an {@link Exception}, then that
055 * exception should not prevent other listeners from being invoked. However, if the method
056 * call throws an {@link Error}, then it is recommended that processing of the notification
057 * stop at that point, and if it is possible to propagate the {@code Error} to the sender of
058 * the notification, this should be done.</p>
059 *
060 * <p>New code should use the {@link NotificationEmitter} interface
061 * instead.</p>
062 *
063 * <p>Implementations of this interface and of {@code NotificationEmitter}
064 * should be careful about synchronization. In particular, it is not a good
065 * idea for an implementation to hold any locks while it is calling a
066 * listener. To deal with the possibility that the list of listeners might
067 * change while a notification is being dispatched, a good strategy is to
068 * use a {@link CopyOnWriteArrayList} for this list.
069 *
070 * @since 1.5
071 */
072 public interface NotificationBroadcaster {
073
074 /**
075 * Adds a listener to this MBean.
076 *
077 * @param listener The listener object which will handle the
078 * notifications emitted by the broadcaster.
079 * @param filter The filter object. If filter is null, no
080 * filtering will be performed before handling notifications.
081 * @param handback An opaque object to be sent back to the
082 * listener when a notification is emitted. This object cannot be
083 * used by the Notification broadcaster object. It should be
084 * resent unchanged with the notification to the listener.
085 *
086 * @exception IllegalArgumentException Listener parameter is null.
087 *
088 * @see #removeNotificationListener
089 */
090 public void addNotificationListener(NotificationListener listener,
091 NotificationFilter filter, Object handback)
092 throws java.lang.IllegalArgumentException;
093
094 /**
095 * Removes a listener from this MBean. If the listener
096 * has been registered with different handback objects or
097 * notification filters, all entries corresponding to the listener
098 * will be removed.
099 *
100 * @param listener A listener that was previously added to this
101 * MBean.
102 *
103 * @exception ListenerNotFoundException The listener is not
104 * registered with the MBean.
105 *
106 * @see #addNotificationListener
107 * @see NotificationEmitter#removeNotificationListener
108 */
109 public void removeNotificationListener(NotificationListener listener)
110 throws ListenerNotFoundException;
111
112 /**
113 * <p>Returns an array indicating, for each notification this
114 * MBean may send, the name of the Java class of the notification
115 * and the notification type.</p>
116 *
117 * <p>It is not illegal for the MBean to send notifications not
118 * described in this array. However, some clients of the MBean
119 * server may depend on the array being complete for their correct
120 * functioning.</p>
121 *
122 * @return the array of possible notifications.
123 */
124 public MBeanNotificationInfo[] getNotificationInfo();
125 }
|