- 所有父级接口:
NotificationBroadcaster
- 所有已知的实现类:
CounterMonitor
,GaugeMonitor
,JMXConnectorServer
,MBeanServerDelegate
,Monitor
,NotificationBroadcasterSupport
,RelationService
,RequiredModelMBean
,RMIConnectorServer
,StandardEmitterMBean
,StringMonitor
,Timer
由发出通知的 MBean 实现的接口。它允许监听器作为通知监听器向 MBean 注册。
通知派发
当 MBean 发出通知时,它会考虑已使用 addNotificationListener
添加但随后未使用 removeNotificationListener
删除的每个监听器。如果为该监听器提供了过滤器,并且如果过滤器的 isNotificationEnabled
方法返回 false,则忽略该监听器。否则,将调用监听器的 handleNotification
方法以及通知以及提供给 addNotificationListener
的交回对象。
如果多次添加同一个监听,则认为它的添加次数与添加的次数一样多。添加具有不同过滤器或 handback 对象的相同监听通常很有用。
此接口的实现可能因调用过滤器和监听方法的线程而异。
如果过滤器或监听器的方法调用抛出 Exception
,则该异常不应阻止调用其他监听器。但是,如果方法调用抛出 Error
,则建议在该点停止处理通知,如果可以将 Error
传播给通知的发送者,则应该这样做。
新代码应优先使用此接口而不是 NotificationBroadcaster
接口。
此接口和 NotificationBroadcaster
的实现应注意同步。特别是,实现在调用监听器时持有任何锁不是一个好主意。为了处理在发送通知时监听器列表可能发生变化的可能性,一个好的策略是对该列表使用 CopyOnWriteArrayList
。
- 自从:
- 1.5
-
方法总结
修饰符和类型方法描述void
removeNotificationListener
(NotificationListener listener, NotificationFilter filter, Object handback) 从此 MBean 中移除监听。在接口 javax.management.NotificationBroadcaster 中声明的方法
addNotificationListener, getNotificationInfo, removeNotificationListener
-
方法详情
-
removeNotificationListener
void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException 从此 MBean 中移除监听器。 MBean 必须具有与给定的
listener
、filter
和handback
参数完全匹配的监听器。如果有多个这样的监听器,则只删除一个。当且仅当它们在要删除的监听器中为空时,
filter
和handback
参数可以为空。- 参数:
listener
- 先前添加到此 MBean 的监听器。filter
- 添加监听器时指定的过滤器。handback
- 添加监听器时指定的交接。- 抛出:
ListenerNotFoundException
- 监听器未在 MBean 中注册,或者未在给定的过滤器和 handback 中注册。
-