Java™ Platform
Standard Edition 7

パッケージ javax.management.modelmbean

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"
    

パッケージの仕様

導入されたバージョン:
1.5
Java™ Platform
Standard Edition 7

バグまたは機能を送信
詳細な API リファレンスおよび開発者ドキュメントについては、Java SE のドキュメントを参照してください。そのドキュメントには、概念的な概要、用語の定義、回避方法、有効なコード例などの、開発者を対象にしたより詳細な説明が含まれています。
Copyright © 1993, 2013, Oracle and/or its affiliates. All rights reserved.