包 javax.management.modelmbean


javax.management.modelmbean

提供 ModelMBean 类的定义。模型 MBean 是充当管理接口和底层托管资源之间桥梁的 MBean。管理接口和托管资源都指定为 Java 对象。相同的 Model MBean 实现可以在不同的管理接口和托管资源中多次重复使用,并且可以提供持久性和缓存等通用功能。

模型 MBean 实现了 ModelMBean 接口。它是一个 DynamicMBean ,其 getMBeanInfo 方法返回一个实现 ModelMBeanInfo 的对象。

每个 MBean 都有一个 MBeanInfo ,其中包含有关 MBean 本身及其属性、操作、构造函数和通知的信息。 Model MBean 使用 Descriptor 扩充此 MBeanInfo ,以(键,值)对的形式编码附加信息。通常,DescriptorDescriptorSupport 的实例。

RequiredModelMBean 提供标准的 Model MBean 实现。

以下示例显示了一个模型 MBean,该模型 MBean 用于使 HashMapget 方法可用于通过 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"
  

包装规格

自从:
1.5