JavaTM 2 Platform
Standard Ed. 6

javax.management
接口 NotificationEmitter

所有超级接口:
NotificationBroadcaster
所有已知实现类:
CounterMonitor, GaugeMonitor, JMXConnectorServer, MBeanServerDelegate, Monitor, NotificationBroadcasterSupport, RelationService, RequiredModelMBean, RMIConnectorServer, StandardEmitterMBean, StringMonitor, Timer

public interface NotificationEmitter
extends NotificationBroadcaster

由发出 Notifications 的 MBean 实现的接口。它允许某个侦听器向该 MBean 注册为通知侦听器。

通知调度

MBean 发出通知时,它会考虑每个已经使用 addNotificationListener 添加、且之后没有使用 removeNotificationListener 移除的侦听器。如果该侦听器同时提供一个过滤器,且过滤器的 isNotificationEnabled 方法返回 false,则忽略该侦听器。否则,将利用通知调用侦听器的 handleNotification 方法,同时向 addNotificationListener 提供 handback 对象。

如果多次添加同一个侦听器,则认为该侦听器被添加的次数等于实际被添加的次数。在添加相同的侦听器的同时使用不同的过滤器或 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 必须有一个与给定 listenerfilterhandback 参数完全匹配的侦听器。如果有多个此类侦听器,则只移除一个侦听器。

当且仅当在要移除的侦听器中 filterhandback 参数为 null 时,这两个参数才可以为 null。

参数:
listener - 以前添加到此 MBean 中的侦听器。
filter - 添加侦听器时指定的过滤器。
handback - 添加侦听器时指定的回送。
抛出:
ListenerNotFoundException - 如果没有在该 MBean 中注册侦听器,或者没有用给定的过滤器和回送注册它。

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only