- 所有父级接口:
NotificationBroadcaster
- 所有已知的子接口:
ModelMBean
- 所有已知的实现类:
RequiredModelMBean
该接口必须由 ModelMBean 实现。每个 JMX 代理都必须附带此接口的实现。
希望易于管理的 Java 资源使用 MBeanServer 的 createMBean 方法实例化 ModelMBean。然后该资源为 ModelMBean 实例设置 ModelMBeanInfo(带有描述符)。通过 ModelMBeanInfo 为 ModelMBean 公开的属性和操作可从 MBean、连接器/适配器(如其他 MBean)访问。通过 ModelMBeanInfo 描述符,托管应用程序中的值和方法可以被定义并映射到 ModelMBean 的属性和操作。此map可以在开发期间以 XML 格式的文件或在运行时以编程方式动态定义。
在 MBeanServer 中实例化的每个 ModelMBean 都变得易于管理:它的属性和操作变得可以通过连接到该 MBeanServer 的连接器/适配器进行远程访问。 Java 对象不能在 MBeanServer 中注册,除非它是符合 JMX 的 MBean。通过实例化 ModelMBean,资源可以保证 MBean 有效。
必须在每个公共方法上抛出 MBeanException 和 RuntimeOperationsException。这允许包装来自分布式通信(RMI、EJB 等)的异常。除了在规范和 javadoc 中描述的场景外,这些异常不必由实现抛出。
- 自从:
- 1.5
-
方法总结
修饰符和类型方法描述voidaddAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) 将实现 NotificationListener 接口的对象注册为监听。voidremoveAttributeChangeNotificationListener(NotificationListener listener, String attributeName) 从 RequiredModelMBean 中移除 attributeChangeNotifications 的监听。voidsendAttributeChangeNotification(AttributeChangeNotification notification) 发送一个 attributeChangeNotification,它被传递给 ModelMBean 上注册的 attributeChangeNotification 监听。voidsendAttributeChangeNotification(Attribute oldValue, Attribute newValue) 将包含属性的旧值和新值的 attributeChangeNotification 发送到 ModelMBean 上已注册的 AttributeChangeNotification 监听。voidsendNotification(String ntfyText) 发送一个通知,其中包含传递给 ModelMBean 上注册的通知监听的文本字符串。voidsendNotification(Notification ntfyObj) 发送通知,该通知作为 jmx.modelmbean.generic 通知传递给 ModelMBean 上已注册的通知监听。在接口 javax.management.NotificationBroadcaster 中声明的方法
addNotificationListener, getNotificationInfo, removeNotificationListener
-
方法详情
-
sendNotification
发送通知,该通知作为 jmx.modelmbean.generic 通知传递给 ModelMBean 上已注册的通知监听。- 参数:
ntfyObj- 要传递给监听器对象的“handleNotification”方法的通知。- 抛出:
MBeanException- 包装分布式通信异常。RuntimeOperationsException- 包装 IllegalArgumentException:传入参数的 Notification 对象为 null。
-
sendNotification
发送一个通知,其中包含传递给 ModelMBean 上注册的通知监听的文本字符串。- 参数:
ntfyText- 要在通知中传递给监听器对象的“handleNotification”方法的文本。构造的通知将是:类型“jmx.modelmbean.generic” source this ModelMBean instance sequence 1- 抛出:
MBeanException- 包装分布式通信异常。RuntimeOperationsException- 包装 IllegalArgumentException:传入参数的通知文本字符串为空。
-
sendAttributeChangeNotification
void sendAttributeChangeNotification(AttributeChangeNotification notification) throws MBeanException , RuntimeOperationsException 发送一个 attributeChangeNotification,它被传递给 ModelMBean 上注册的 attributeChangeNotification 监听。- 参数:
notification- 要传递给监听器对象的“handleNotification”方法的通知。- 抛出:
MBeanException- 包装分布式通信异常。RuntimeOperationsException- 包装 IllegalArgumentException:传入参数的 AttributeChangeNotification 对象为 null。
-
sendAttributeChangeNotification
void sendAttributeChangeNotification(Attribute oldValue, Attribute newValue) throws MBeanException , RuntimeOperationsException 将包含属性的旧值和新值的 attributeChangeNotification 发送到 ModelMBean 上已注册的 AttributeChangeNotification 监听。- 参数:
oldValue- 属性的原始值newValue- 属性The constructed attributeChangeNotification will be: type "jmx.attribute.change" source this ModelMBean instance sequence 1 attributeName oldValue.getName() attributeType oldValue's class attributeOldValue oldValue.getValue() attributeNewValue newValue.getValue()
的当前值- 抛出:
MBeanException- 包装分布式通信异常。RuntimeOperationsException- 包装 IllegalArgumentException:传入参数的属性对象为 null 或参数中两个属性对象的名称不同。
-
addAttributeChangeNotificationListener
void addAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException , RuntimeOperationsException , IllegalArgumentException 将实现 NotificationListener 接口的对象注册为监听。当通过 ModelMBean 或由 ModelMBean 发出任何 attributeChangeNotification 时,将调用该对象的“handleNotification()”方法。这不包括其他通知。他们必须独立注册。将为该 attributeName 生成一个 AttributeChangeNotification。- 参数:
listener- 将处理已注册 MBean 发出的通知的监听器对象。attributeName- 要为其接收更改通知的 ModelMBean 属性的名称。如果为空,则所有属性更改都将导致发出 attributeChangeNotification。handback- 发出通知时要与通知一起发送给监听器的上下文。- 抛出:
IllegalArgumentException- 监听器不能为空。MBeanException- 包装分布式通信异常。RuntimeOperationsException- 包装 IllegalArgumentException 参数中传递的属性名称不存在。- 参见:
-
removeAttributeChangeNotificationListener
void removeAttributeChangeNotificationListener(NotificationListener listener, String attributeName) throws MBeanException , RuntimeOperationsException , ListenerNotFoundException 从 RequiredModelMBean 中移除 attributeChangeNotifications 的监听。- 参数:
listener- 处理已注册 MBean 发出的通知的监听器名称。此方法将删除与此监听器相关的所有信息。attributeName- 监听器不再希望为其接收 attributeChangeNotifications 的属性。如果为 null,则将删除所有 attributeChangeNotifications 的监听器。- 抛出:
ListenerNotFoundException- 监听器未在 MBean 中注册或为空。MBeanException- 包装分布式通信异常。RuntimeOperationsException- 如果 inAttributeName 参数不对应于属性名称,则包装 IllegalArgumentException。- 参见:
-