Class: javax.management.NotificationBroadcasterSupport
- public class NotificationBroadcasterSupport
- implements NotificationEmitter
Provides an implementation of NotificationEmitter interface. This can be used as the super class of an MBean that sends notifications.
By default, the notification dispatch model is synchronous.
That is, when a thread calls sendNotification, the
NotificationListener.handleNotification method of each listener
is called within that thread. You can override this default
by overriding handleNotification in a subclass, or by passing an
Executor to the constructor.
If the method call of a filter or listener throws an Exception, then that exception does not prevent other listeners from being invoked. However, if the method call of a filter or of Executor.execute or of handleNotification (when no Excecutor is specified) throws an Error, then that Error is propagated to the caller of sendNotification.
Remote listeners added using the JMX Remote API (see JMXConnector) are not usually called synchronously. That is, when sendNotification returns, it is not guaranteed that any remote listeners have yet received the notification.
Inheritance
Superclass tree:- java.lang.Object
- javax.management.NotificationBroadcasterSupport
Methods
-
NotificationBroadcasterSupporttop
public NotificationBroadcasterSupport()Constructs a NotificationBroadcasterSupport where each listener is invoked by the thread sending the notification. This constructor is equivalent to NotificationBroadcasterSupport(null, null). -
NotificationBroadcasterSupporttop
public NotificationBroadcasterSupport(Executor executor)Constructs a NotificationBroadcasterSupport where each listener is invoked using the given java.util.concurrent.Executor. When sendNotification is called, a listener is selected if it was added with a null javax.management.NotificationFilter, or if isNotificationEnabled returns true for the notification being sent. The call toNotificationFilter.isNotificationEnabledtakes place in the thread that calledsendNotification. Then, for each selected listener, executor.execute is called with a command that calls thehandleNotificationmethod. This constructor is equivalent to NotificationBroadcasterSupport(executor, null). -
NotificationBroadcasterSupporttop
public NotificationBroadcasterSupport(Executor executor, MBeanNotificationInfo... info)Constructs a NotificationBroadcasterSupport with information about the notifications that may be sent, and where each listener is invoked using the given java.util.concurrent.Executor.
When sendNotification is called, a listener is selected if it was added with a null javax.management.NotificationFilter, or if isNotificationEnabled returns true for the notification being sent. The call to
NotificationFilter.isNotificationEnabledtakes place in the thread that calledsendNotification. Then, for each selected listener, executor.execute is called with a command that calls thehandleNotificationmethod.If the
infoarray is not empty, then it is cloned by the constructor as if by info.clone(), and each call to javax.management.NotificationBroadcasterSupport.getNotificationInfo() returns a new clone. -
NotificationBroadcasterSupporttop
public NotificationBroadcasterSupport(MBeanNotificationInfo... info)Constructs a NotificationBroadcasterSupport with information about the notifications that may be sent. Each listener is invoked by the thread sending the notification. This constructor is equivalent to NotificationBroadcasterSupport(null, info).
If the
infoarray is not empty, then it is cloned by the constructor as if by info.clone(), and each call to javax.management.NotificationBroadcasterSupport.getNotificationInfo() returns a new clone. -
addNotificationListenertop
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)Adds a listener.- Specified by:
- addNotificationListener from NotificationBroadcaster
-
getNotificationInfotop
public 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.
- Specified by:
- getNotificationInfo from NotificationBroadcaster
-
handleNotificationtop
protected void handleNotification(NotificationListener listener, Notification notif, Object handback)This method is called by sendNotification for each listener in order to send the notification to that listener. It can be overridden in subclasses to change the behavior of notification delivery, for instance to deliver the notification in a separate thread.
The default implementation of this method is equivalent to
listener.handleNotification(notif, handback);
-
removeNotificationListenertop
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundExceptionRemoves a listener from this MBean. If the listener has been registered with different handback objects or notification filters, all entries corresponding to the listener will be removed.- Specified by:
- removeNotificationListener from NotificationBroadcaster
-
removeNotificationListenertop
public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundExceptionRemoves a listener from this MBean. The MBean must have a listener that exactly matches the given
listener,filter, andhandbackparameters. If there is more than one such listener, only one is removed.The
filterandhandbackparameters may be null if and only if they are null in a listener to be removed.- Specified by:
- removeNotificationListener from NotificationEmitter
-
sendNotificationtop
public void sendNotification(Notification notification)Sends a notification. If an Executor was specified in the constructor, it will be given one task per selected listener to deliver the notification to that listener.
