包 javax.management.modelmbean
包javax.management.modelmbean
提供 ModelMBean 类的定义。模型 MBean 是充当管理接口和底层托管资源之间桥梁的 MBean。管理接口和托管资源都指定为 Java 对象。相同的 Model MBean 实现可以在不同的管理接口和托管资源中多次重复使用,并且可以提供持久性和缓存等通用功能。
模型 MBean 实现了 ModelMBean
接口。它是一个 DynamicMBean
,其 getMBeanInfo
方法返回一个实现 ModelMBeanInfo
的对象。
每个 MBean 都有一个 MBeanInfo
,其中包含有关 MBean 本身及其属性、操作、构造函数和通知的信息。 Model MBean 使用 Descriptor
扩充此 MBeanInfo
,以(键,值)对的形式编码附加信息。通常,Descriptor
是 DescriptorSupport
的实例。
类 RequiredModelMBean
提供标准的 Model MBean 实现。
以下示例显示了一个模型 MBean,该模型 MBean 用于使 HashMap
的 get
方法可用于通过 MBean 服务进行管理。没有其他方法可通过 MBean 服务使用。这里的 HashMap
没有什么特别之处。来自任何公共类的公共方法都可以以相同的方式公开以供管理。
import java.lang.reflect.Method; import java.util.HashMap; import javax.management.*; import javax.management.modelmbean.*; // ... MBeanServer mbs = MBeanServerFactory.createMBeanServer(); // The MBean Server HashMap map = new HashMap(); // The resource that will be managed // Construct the management interface for the Model MBean Method getMethod = HashMap.class.getMethod("get", new Class[] {Object.class}); ModelMBeanOperationInfo getInfo = new ModelMBeanOperationInfo("Get value for key", getMethod); ModelMBeanInfo mmbi = new ModelMBeanInfoSupport(HashMap.class.getName(), "Map of keys and values", null, // no attributes null, // no constructors new ModelMBeanOperationInfo[] {getInfo}, null); // no notifications // Make the Model MBean and link it to the resource ModelMBean mmb = new RequiredModelMBean(mmbi); mmb.setManagedResource(map, "ObjectReference"); // Register the Model MBean in the MBean Server ObjectName mapName = new ObjectName(":type=Map,name=whatever"); mbs.registerMBean(mmb, mapName); // Resource can evolve independently of the MBean map.put("key", "value"); // Can access the "get" method through the MBean Server mbs.invoke(mapName, "get", new Object[] {"key"}, new String[] {Object.class.getName()}); // returns "value"
包装规格
- 见JMX 1.4 规范 JMX 规范,版本 1.4
- 自从:
- 1.5
-
类描述此类表示 ModelMBean 元素的元数据集。指定无效的目标对象类型时抛出异常。该接口必须由 ModelMBean 实现。ModelMBeanAttributeInfo 对象描述了 ModelMBean 的一个属性。ModelMBeanConstructorInfo 对象描述了 ModelMBean 的构造方法。该接口由每个 ModelMBean 的 ModelMBeanInfo 实现。此类表示 ModelMBean 的元数据。该接口必须由 ModelMBean 实现。ModelMBeanNotificationInfo 对象描述由 ModelMBean 发出的通知。ModelMBeanOperationInfo 对象描述了 ModelMBean 的管理操作。此类是 ModelMBean 的实现。当将 XML 格式的字符串解析为 ModelMBean 对象或从 ModelMBean 对象创建 XML 格式的字符串时,会抛出此异常。