|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個軟體套件 下一個軟體套件 | 框架 無框架 | |||||||||
請參見:
描述
| 介面摘要 | |
|---|---|
| ModelMBean | ModelMBean 必須實作此介面。 |
| ModelMBeanInfo | 此介面由每個 ModelMBean 的 ModelMBeanInfo 實作。 |
| ModelMBeanNotificationBroadcaster | ModelMBean 必須實作此介面。 |
| 類別摘要 | |
|---|---|
| DescriptorSupport | 此類別表示 ModelMBean 元素的元資料集。 |
| ModelMBeanAttributeInfo | ModelMBeanAttributeInfo 物件描述了 ModelMBean 的屬性。 |
| ModelMBeanConstructorInfo | ModelMBeanConstructorInfo 物件描述了 ModelMBean 的一個建構子。 |
| ModelMBeanInfoSupport | 此類別表示 ModelMBean 的元資料。 |
| ModelMBeanNotificationInfo | ModelMBeanNotificationInfo 物件描述了由 ModelMBean 發出的通知。 |
| ModelMBeanOperationInfo | ModelMBeanOperationInfo 物件描述了 ModelMBean 的管理操作。 |
| RequiredModelMBean | 此類別是 ModelMBean 的實作。 |
| 異常摘要 | |
|---|---|
| InvalidTargetObjectTypeException | 當指定了無效的目標物件型別時,拋出此異常。 |
| XMLParseException | 當將某個 XML 格式的字元串解析為 ModelMBean 物件,或從 ModelMBean 物件創建 XML 格式的字元串時,拋出此異常。 |
提供了 ModelMBean 類別的定義。Model MBean 是充當管理介面與底層托管資源之間橋樑的 MBean。管理介面和托管資源都指定為 Java 物件。不同管理介面和托管資源可以多次重用相同的 Model MBean 實作,它可以提供諸如持久存儲和快取記憶體這樣常見的功能。
Model MBean 實作 ModelMBean 介面。它是一個 DynamicMBean 介面,該介面的 getMBeanInfo 方法返回實作 ModelMBeanInfo 的物件。
每個 MBean 都有一個 MBeanInfo,它包含關於 MBean 本身、其屬性、操作、建構子和通知的資訊。Model MBean 用 Descriptor 來擴充此 MBeanInfo,這裡 Descriptor 通過 (key,value) 對的形式對其他資訊進行編碼。通常,Descriptor 是 DescriptorSupport 的實例。
RequiredModelMBean 類別提供了標準的 Model MBean 實作。
以下顯示了一個 Model MBean 的範例,它使我們可以通過 MBean 伺服器管理 HashMap 的 get 方法。其他方法不能通過 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"
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個軟體套件 下一個軟體套件 | 框架 無框架 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。