| 接口 | 描述 | 
|---|---|
| ModelMBean | 
           该接口必须由ModelMBeans实现。 
          | 
| ModelMBeanInfo | 
           该接口由ModelMBeanInfo为每个ModelMBean实现。 
          | 
| ModelMBeanNotificationBroadcaster | 
           该接口必须由ModelMBeans实现。 
          | 
| 类 | 描述 | 
|---|---|
| DescriptorSupport | 
           此类表示一个ModelMBean元素的元数据集。 
          | 
| ModelMBeanAttributeInfo | 
           ModelMBeanAttributeInfo对象描述了ModelMBean的属性。 
          | 
| ModelMBeanConstructorInfo | 
           ModelMBeanConstructorInfo对象描述了ModelMBean的构造函数。 
          | 
| ModelMBeanInfoSupport | 
           此类表示ModelMBeans的元数据。 
          | 
| ModelMBeanNotificationInfo | 
           ModelMBeanNotificationInfo对象描述了由ModelMBean发出的通知。 
          | 
| ModelMBeanOperationInfo | 
           ModelMBeanOperationInfo对象描述了ModelMBean的管理操作。 
          | 
| RequiredModelMBean | 
           这个类是一个ModelMBean的实现。 
          | 
| 异常 | 描述 | 
|---|---|
| InvalidTargetObjectTypeException | 
           指定无效目标对象类型时抛出异常。 
          | 
| XMLParseException | 
           当将XML格式化的字符串解析为ModelMBean对象或从ModelMBean对象创建XML格式的字符串时,将抛出此异常。 
          | 
提供ModelMBean类的定义。 MBean模型是一个MBean,用作管理界面和底层托管资源之间的桥梁。 管理界面和被管理资源都被指定为Java对象。 相同的Model MBean实现可以通过不同的管理接口和托管资源重复使用多次,并且可以提供常见的功能,如持久性和缓存。
 MBean模型实现了ModelMBean接口。 它是一个DynamicMBean ,其getMBeanInfo方法返回一个实现ModelMBeanInfo的对象。 
 每个MBean都有一个MBeanInfo ,其中包含有关MBean本身及其属性,操作,构造函数和通知的信息。 一个模型MBean增加了MBeanInfo与Descriptor s编码附加信息(密钥,值)对的形式。 通常, Descriptor是DescriptorSupport的实例 。 
 RequiredModelMBean类提供了一个标准的MBean模型实现。 
 下面的示例示出了正在使用模型Mbean使get一个的方法HashMap通过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"  
     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.