モジュール java.management
パッケージjavax.management.modelmbean
パッケージjavax.management.modelmbean
ModelMBeanクラスの定義を提供します。 Model MBeanは、管理インタフェースと配下の管理対象リソースのブリッジとして機能するMBeanです。 管理インタフェースと管理対象リソースは、どちらもJavaオブジェクトとして指定されます。 複数の異なった管理インタフェースおよび管理対象リソースで、同じModel MBean実装を繰返し利用できます。また、Model MBean実装は、永続性機能、キャッシング機能などの共通機能を提供できます。
Model MBeanは、ModelMBeanインタフェースを実装します。 Model MBeanはDynamicMBeanであり、ModelMBeanInfoを実装するオブジェクトを返すgetMBeanInfoメソッドを持っています。
すべてのMBeanは、MBean自体の情報とその属性、オペレーション、コンストラクタ、および通知を備えたMBeanInfoを持ちます。 Model MBeanは、このMBeanInfoに、(key,value)のペア形式の追加情報をエンコードするDescriptorを追加します。 通常、Descriptorは、DescriptorSupportのインスタンスです。
RequiredModelMBeanクラスは、標準Model MBean実装を提供します。
次に、MBeanサーバーからHashMapのgetメソッドを管理できるようにするためのModel MBeanの例を示します。 MBeanサーバーからは、これ以外のメソッドは利用できません。 この例では、HashMapに関する特別な情報はありません。 同様にして、任意のpublicクラスのpublicメソッドを管理用に公開できます。
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のコンストラクタを記述します。ModelMBeanInfoは、ModelMBeanごとにこのインタフェースを実装する必要があります。このクラスは、ModelMBeanのメタデータを表します。このインタフェースはModelMBeanによって実装される必要があります。ModelMBeanNotificationInfoオブジェクトは、ModelMBeanが発行する通知を記述します。ModelMBeanOperationInfoオブジェクトは、ModelMBeanの管理オペレーションを記述します。このクラスは、ModelMBeanの実装です。この例外は、XML形式の文字列がModelMBeanオブジェクトに解析される場合、またはXML形式の文字列がModelMBeanオブジェクトから作成される場合にスローされます。