Class NotificationBroadcasterSupport
- All Implemented Interfaces:
NotificationBroadcaster
,NotificationEmitter
- Direct Known Subclasses:
JMXConnectorServer
,Monitor
,RelationService
,Timer
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 Executor
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.
- Since:
- 1.5
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a NotificationBroadcasterSupport where each listener is invoked by the thread sending the notification.NotificationBroadcasterSupport
(Executor executor) Constructs a NotificationBroadcasterSupport where each listener is invoked using the givenExecutor
.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 givenExecutor
.Constructs a NotificationBroadcasterSupport with information about the notifications that may be sent. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addNotificationListener
(NotificationListener listener, NotificationFilter filter, Object handback) Adds a listener.Returns an array indicating, for each notification this MBean may send, the name of the Java class of the notification and the notification type.protected void
handleNotification
(NotificationListener listener, Notification notif, Object handback) This method is called bysendNotification
for each listener in order to send the notification to that listener.void
Removes a listener from this MBean.void
removeNotificationListener
(NotificationListener listener, NotificationFilter filter, Object handback) Removes a listener from this MBean.void
sendNotification
(Notification notification) Sends a notification.
-
Constructor Details
-
NotificationBroadcasterSupport
public NotificationBroadcasterSupport()Constructs a NotificationBroadcasterSupport where each listener is invoked by the thread sending the notification. This constructor is equivalent toNotificationBroadcasterSupport(null, null)
. -
NotificationBroadcasterSupport
Constructs a NotificationBroadcasterSupport where each listener is invoked using the givenExecutor
. WhensendNotification
is called, a listener is selected if it was added with a nullNotificationFilter
, or ifisNotificationEnabled
returns true for the notification being sent. The call toNotificationFilter.isNotificationEnabled
takes place in the thread that calledsendNotification
. Then, for each selected listener,executor.execute
is called with a command that calls thehandleNotification
method. This constructor is equivalent toNotificationBroadcasterSupport(executor, null)
.- Parameters:
executor
- an executor used by the methodsendNotification
to send each notification. If it is null, the thread callingsendNotification
will invoke thehandleNotification
method itself.- Since:
- 1.6
-
NotificationBroadcasterSupport
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
info
array is not empty, then it is cloned by the constructor as if byinfo.clone()
, and each call togetNotificationInfo()
returns a new clone.- Parameters:
info
- an array indicating, for each notification this MBean may send, the name of the Java class of the notification and the notification type. Can be null, which is equivalent to an empty array.- Since:
- 1.6
-
NotificationBroadcasterSupport
Constructs a NotificationBroadcasterSupport with information about the notifications that may be sent, and where each listener is invoked using the given
Executor
.When
sendNotification
is called, a listener is selected if it was added with a nullNotificationFilter
, or ifisNotificationEnabled
returns true for the notification being sent. The call toNotificationFilter.isNotificationEnabled
takes place in the thread that calledsendNotification
. Then, for each selected listener,executor.execute
is called with a command that calls thehandleNotification
method.If the
info
array is not empty, then it is cloned by the constructor as if byinfo.clone()
, and each call togetNotificationInfo()
returns a new clone.- Parameters:
executor
- an executor used by the methodsendNotification
to send each notification. If it is null, the thread callingsendNotification
will invoke thehandleNotification
method itself.info
- an array indicating, for each notification this MBean may send, the name of the Java class of the notification and the notification type. Can be null, which is equivalent to an empty array.- Since:
- 1.6
-
-
Method Details
-
addNotificationListener
public void addNotificationListener(
-