类 MBeanServerNotification

java.lang.Object
java.util.EventObject
javax.management.Notification
javax.management.MBeanServerNotification
所有已实现的接口:
Serializable

public class MBeanServerNotification extends Notification
表示 MBean Server 通过 MBeanServerDelegate MBean 发出的通知。 MBean Server 发出以下类型的通知:MBean 注册、MBean 注销。

要接收 MBeanServerNotifications,您需要向代表 MBeanServer 的 MBeanServerDelegate MBean 注册一个监听器。 MBeanServerDelegate 的 ObjectName 是 MBeanServerDelegate.DELEGATE_NAME ,即 JMImplementation:type=MBeanServerDelegate

每次在 MBean Server mbeanServer 中注册或取消注册 MBean 时,以下代码都会打印一条消息:

 private static final NotificationListener printListener = new NotificationListener() {
   public void handleNotification(Notification n, Object handback) {
     if (!(n instanceof MBeanServerNotification)) {
       System.out.println("Ignored notification of class " + n.getClass().getName());
       return;
     }
     MBeanServerNotification mbsn = (MBeanServerNotification) n;
     String what;
     if (n.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION))
       what = "MBean registered";
     else if (n.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION))
       what = "MBean unregistered";
     else
       what = "Unknown type " + n.getType();
     System.out.println("Received MBean Server notification: " + what + ": " +
         mbsn.getMBeanName());
   }
 };

 ...
   mbeanServer.addNotificationListener(
       MBeanServerDelegate.DELEGATE_NAME, printListener, null, null);
 

不是 MBeanServerDelegate 的 MBean 也可能发出 MBeanServerNotifications。特别是,MBean 有一个为一组 MBean 发出 MBeanServerNotification 的约定。

为指示一组 MBean 的注册或注销而发出的 MBeanServerNotification 具有以下特征:

发出这些组注册/注销通知的 MBean 将在它们的 MBeanNotificationInfo 中声明它们。

自从:
1.5
参见:
  • 字段详细信息

    • REGISTRATION_NOTIFICATION

      public static final String  REGISTRATION_NOTIFICATION
      表示 MBean 已注册的通知类型。值为“JMX.mbean.registered”。
      参见:
    • UNREGISTRATION_NOTIFICATION

      public static final String  UNREGISTRATION_NOTIFICATION
      表示 MBean 已注销的通知类型。值为“JMX.mbean.unregistered”。
      参见:
  • 构造方法详细信息

    • MBeanServerNotification

      public MBeanServerNotification(String  type, Object  source, long sequenceNumber, ObjectName  objectName)
      创建一个 MBeanServerNotification 对象,指定引起通知的 MBean 的对象名称和指定的通知类型。
      参数:
      type - 表示通知类型的字符串。将其设置为以下值之一:REGISTRATION_NOTIFICATION UNREGISTRATION_NOTIFICATION
      source - 负责转发 MBean 服务通知的 MBeanServerNotification 对象。
      sequenceNumber - 可用于对收到的通知进行排序的序列号。
      objectName - 导致通知的 MBean 的对象名称。
  • 方法详情

    • getMBeanName

      public ObjectName  getMBeanName()
      返回引起通知的 MBean 的对象名称。
      返回:
      引起通知的 MBean 的对象名称。