public class MBeanServerNotification extends Notification
要接收MBeanServerNotifications,您需要使用代表MBeanServer的MBeanServerDelegate
MBean注册一个监听器。 MBeanServerDelegate的ObjectName是MBeanServerDelegate.DELEGATE_NAME
,它是JMImplementation:type=MBeanServerDelegate
。
以下代码在MBean服务器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。
发布的MBeanServerNotification表示一组MBean的注册或注销具有以下特征:
"JMX.mbean.registered.group"
或"JMX.mbean.unregistered.group"
,其也可以被写入REGISTRATION_NOTIFICATION
+ ".group"
或UNREGISTRATION_NOTIFICATION
+ ".group"
。 排放这些团体注册/注销通知的MBean将在其MBeanNotificationInfo
中声明。
Modifier and Type | Field and Description |
---|---|
static String |
REGISTRATION_NOTIFICATION
通知类型表示MBean已被注册。
|
static String |
UNREGISTRATION_NOTIFICATION
指示MBean已注销的通知类型。
|
source
Constructor and Description |
---|
MBeanServerNotification(String type, Object source, long sequenceNumber, ObjectName objectName)
创建一个MBeanServerNotification对象,指定导致通知的MBean的对象名称和指定的通知类型。
|
Modifier and Type | Method and Description |
---|---|
ObjectName |
getMBeanName()
返回导致通知的MBean的对象名称。
|
String |
toString()
返回此通知的String表示形式。
|
getMessage, getSequenceNumber, getTimeStamp, getType, getUserData, setSequenceNumber, setSource, setTimeStamp, setUserData
getSource
public static final String REGISTRATION_NOTIFICATION
public static final String UNREGISTRATION_NOTIFICATION
public MBeanServerNotification(String type, Object source, long sequenceNumber, ObjectName objectName)
type
- 表示通知类型的字符串。
将它设置为一个这些值: REGISTRATION_NOTIFICATION
, UNREGISTRATION_NOTIFICATION
。
source
- 负责转发MBean服务器通知的MBeanServerNotification对象。
sequenceNumber
- 可用于订购接收到的通知的序列号。
objectName
- 导致通知的MBean的对象名称。
public ObjectName getMBeanName()
public String toString()
Notification
复制
toString
在
Notification
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.