- java.lang.Object
-
- javax.management.NotificationBroadcasterSupport
-
- All Implemented Interfaces:
- NotificationBroadcaster, NotificationEmitter
- Direct Known Subclasses:
- JMXConnectorServer, Monitor, RelationService, Timer
public class NotificationBroadcasterSupport extends Object 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 overridinghandleNotification
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 ofExecutor.execute
or ofhandleNotification
(when noExcecutor
is specified) throws anError
, then thatError
is propagated to the caller ofsendNotification
.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
Constructors Constructor and Description NotificationBroadcasterSupport()
Constructs 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
.NotificationBroadcasterSupport(MBeanNotificationInfo... info)
Constructs a NotificationBroadcasterSupport with information about the notifications that may be sent.
-
Method Summary
Methods Modifier and Type Method and Description void
addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
Adds a listener.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.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
removeNotificationListener(NotificationListener listener)
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 Detail
-
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
public NotificationBroadcasterSupport(Executor executor)
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
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
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
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
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 Detail
-
addNotificationListener
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
Adds a listener.- Specified by:
addNotificationListener
in interfaceNotificationBroadcaster
- Parameters:
listener
- The listener to receive notifications.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.- Throws:
IllegalArgumentException
- thrown if the listener is null.- See Also:
removeNotificationListener(javax.management.NotificationListener)
-
removeNotificationListener
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException
Description copied from interface:NotificationBroadcaster
Removes 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
in interfaceNotificationBroadcaster
- Parameters:
listener
- A listener that was previously added to this MBean.- Throws:
ListenerNotFoundException
- The listener is not registered with the MBean.- See Also:
NotificationBroadcaster.addNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object)
,NotificationEmitter.removeNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object)
-
removeNotificationListener
public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException
Description copied from interface:NotificationEmitter
Removes a listener from this MBean. The MBean must have a listener that exactly matches the given
listener
,filter
, andhandback
parameters. If there is more than one such listener, only one is removed.The
filter
andhandback
parameters may be null if and only if they are null in a listener to be removed.- Specified by:
removeNotificationListener
in interfaceNotificationEmitter
- Parameters:
listener
- A listener that was previously added to this MBean.filter
- The filter that was specified when the listener was added.handback
- The handback that was specified when the listener was added.- Throws:
ListenerNotFoundException
- The listener is not registered with the MBean, or it is not registered with the given filter and handback.
-
getNotificationInfo
public MBeanNotificationInfo[] getNotificationInfo()
Description copied from interface:NotificationBroadcaster
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
in interfaceNotificationBroadcaster
- Returns:
- the array of possible notifications.
-
sendNotification
public void sendNotification(Notification notification)
Sends a notification. If anExecutor
was specified in the constructor, it will be given one task per selected listener to deliver the notification to that listener.- Parameters:
notification
- The notification to send.
-
handleNotification
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);
- Parameters:
listener
- the listener to which the notification is being delivered.notif
- the notification being delivered to the listener.handback
- the handback object that was supplied when the listener was added.
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-javax/management/notificationbroadcastersupport.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.