ModelMBean
, ModelMBeanNotificationBroadcaster
, NotificationEmitter
CounterMonitor
, GaugeMonitor
, JMXConnectorServer
, MBeanServerDelegate
, Monitor
, NotificationBroadcasterSupport
, RelationService
, RequiredModelMBean
, RMIConnectorServer
, StandardEmitterMBean
, StringMonitor
, Timer
public interface NotificationBroadcaster
Interface implemented by an MBean that emits Notifications. It allows a listener to be registered with the MBean as a notification listener.
When an MBean emits a notification, it considers each listener that has been added with addNotificationListener
and not subsequently removed with removeNotificationListener
. If a filter was provided with that listener, and if the filter's isNotificationEnabled
method returns false, the listener is ignored. Otherwise, the listener's handleNotification
method is called with the notification, as well as the handback object that was provided to addNotificationListener
.
If the same listener is added more than once, it is considered as many times as it was added. It is often useful to add the same listener with different filters or handback objects.
Implementations of this interface can differ regarding the thread in which the methods of filters and listeners are called.
If the method call of a filter or listener throws an Exception
, then that exception should not prevent other listeners from being invoked. However, if the method call throws an Error
, then it is recommended that processing of the notification stop at that point, and if it is possible to propagate the Error
to the sender of the notification, this should be done.
New code should use the NotificationEmitter
interface instead.
Implementations of this interface and of NotificationEmitter
should be careful about synchronization. In particular, it is not a good idea for an implementation to hold any locks while it is calling a listener. To deal with the possibility that the list of listeners might change while a notification is being dispatched, a good strategy is to use a CopyOnWriteArrayList
for this list.
Modifier and Type | Method | Description |
---|---|---|
void |
addNotificationListener |
Adds a listener to this MBean. |
MBeanNotificationInfo[] |
getNotificationInfo() |
Returns an array indicating, for each notification this MBean may send, the name of the Java class of the notification and the notification type. |
void |
removeNotificationListener |
Removes a listener from this MBean. |
void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws IllegalArgumentException
listener
- The listener object which will handle the notifications emitted by the broadcaster.filter
- The filter object. If filter is null, no filtering will be performed before handling notifications.handback
- An opaque object to be sent back to the listener when a notification is emitted. This object cannot be used by the Notification broadcaster object. It should be resent unchanged with the notification to the listener.IllegalArgumentException
- Listener parameter is null.void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException
listener
- A listener that was previously added to this MBean.ListenerNotFoundException
- The listener is not registered with the MBean.MBeanNotificationInfo[] getNotificationInfo()
Returns an array indicating, for each notification this MBean may send, the name of the Java class of the notification and the notification type.
It is not illegal for the MBean to send notifications not described in this array. However, some clients of the MBean server may depend on the array being complete for their correct functioning.
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.management/javax/management/NotificationBroadcaster.html