JMX note

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

JMX note - (2005/12/26 (月) 00:25:47) のソース

**  four types of MBean
- standard MBeans
- dynamic MBeans
- open MBeans
- model MBeans

** Specifications
:JSR3 | JMX local specification
:JSR160 | JMX remote implementation.  javax.management.remote package

** type of service URL
service:jmx:rmi://host
service:jmx:iiop://host
service:jmx:soap://host
service:jmx:local://host
service:jmx:hessian://host
service:jmx:burlap://host

** Architecture
: Instrumentation | Java で書いた MBean のインターフェイス、実装。実装されると Agent から管理できる。

: Agent | MBean server and services for MBeans

: Remote Management | Protocol adaptors and standard connectors RMI, JMXMP

** 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 もご覧ください。