JMX note

「JMX note」の編集履歴(バックアップ)一覧に戻る

JMX note - (2005/12/25 (日) 15:31:44) の編集履歴(バックアップ)


four types of MBean

  • standard MBeans
  • dynamic MBeans
  • open MBeans
  • model MBeans

user code


// Get the Platform MBean Server
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

// Construct the ObjectName for the MBean we will register
ObjectName name = new ObjectName("com.example.mbeans:type=Hello");

// Create the Hello World MBean
Hello mbean = new Hello();

// Register the Hello World MBean
mbs.registerMBean(mbean, name);

MBean interface

simply an interface...

public interface HelloMBean {
   // operations

   public void sayHello();
   public int add(int x, int y);

   // attributes

   // a read-only attribute called Name of type String
   public String getName();

   // a read-write attribute called CacheSize of type int
   public int getCacheSize();
   public void setCacheSize(int size);
}

MBean implementation

public class Hello implements HelloMBean {
   public void sayHello() {
     System.out.println("hello, world");
   }

   public int add(int x, int y) {
     return x + y;
   }

   /* Name 属性の getter. 通常プライベートな実データフィールドを返す。
       アプリケーション実行に伴い変化する値は読み込みのみ可とする。
    */
   public String getName() {
     return this.name;
   }

   /* キャッシュサイズに関するゲッタ。変更可能な属性  */
   public int getCacheSize() {
       return this.cacheSize;
   }

   /* キャッシュサイズに関する雪駄。スレッド環境を考慮し同期とする */
   public synchronized void setCacheSize(int size) {
     this.cacheSize = size;


     System.out.println("Cache size now " + this.cacheSize);
   }
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。