JavaTM 2 Platform
Standard Ed. 6

javax.management
类 NotificationFilterSupport

java.lang.Object
  继承者 javax.management.NotificationFilterSupport
所有已实现的接口:
Serializable, NotificationFilter
直接已知子类:
MBeanServerNotificationFilter

public class NotificationFilterSupport
extends Object
implements NotificationFilter

提供 NotificationFilter 接口的实现。针对通知类型这一属性执行过滤。

管理一个已启用的通知类型列表。方法允许用户根据需要启用/禁用多个通知类型。

然后在向侦听器(已向某个过滤器注册过)发送通知前,该通知广播器会比较此通知类型和该过滤器所允许的所有通知类型。仅在该侦听器的过滤器允许此通知类型的情况下才将通知发送到该侦听器。

示例:

 NotificationFilterSupport myFilter = new NotificationFilterSupport();
 myFilter.enableType("my_example.my_type");
 myBroadcaster.addListener(myListener, myFilter, null);
 
侦听器 myListener 仅接收类型等于 "my_example.my_type" 或以其开头的通知。

从以下版本开始:
1.5
另请参见:
NotificationBroadcaster.addNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object), 序列化表格

构造方法摘要
NotificationFilterSupport()
           
 
方法摘要
 void disableAllTypes()
          禁止所有通知类型。
 void disableType(String prefix)
          从前缀列表中移除给定的前缀。
 void enableType(String prefix)
          允许将其类型以指定前缀开始的所有通知发送到该侦听器。
 Vector<String> getEnabledTypes()
          获得此过滤器的所有允许通知类型。
 boolean isNotificationEnabled(Notification notification)
          向侦听器发送指定的通知前调用。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

NotificationFilterSupport

public NotificationFilterSupport()
方法详细信息

isNotificationEnabled

public boolean isNotificationEnabled(Notification notification)
向侦听器发送指定的通知前调用。
此过滤器把指定的通知的类型和所有允许的类型相比较。如果通知类型与某个允许类型匹配,则应该将该通知发送到侦听器并且此方法返回 true

指定者:
接口 NotificationFilter 中的 isNotificationEnabled
参数:
notification - 要发送的通知。
返回:
如果应该将通知发送到侦听器,则返回 true;否则返回 false

enableType

public void enableType(String prefix)
                throws IllegalArgumentException
允许将其类型以指定前缀开始的所有通知发送到该侦听器。
如果指定的前缀已经在允许通知类型的列表中,则此方法无效。

示例:

 // Enables all notifications the type of which starts with "my_example" to be sent.
 myFilter.enableType("my_example");
 // Enables all notifications the type of which is "my_example.my_type" to be sent.
 myFilter.enableType("my_example.my_type");
 
注:
myFilter.enableType("my_example.*");
不匹配任何通知类型。

参数:
prefix - 前缀。
抛出:
IllegalArgumentException - 如果 prefix 参数为 null。

disableType

public void disableType(String prefix)
从前缀列表中移除给定的前缀。
如果指定的前缀不在允许的通知类型的列表中,则此方法无效。

参数:
prefix - 前缀。

disableAllTypes

public void disableAllTypes()
禁止所有通知类型。


getEnabledTypes

public Vector<String> getEnabledTypes()
获得此过滤器的所有允许通知类型。

返回:
包含所有允许的通知类型的列表。

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

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