2 Replies Latest reply on Aug 15, 2008 1:08 AM by dikar

    my first JMX

    anand_anan2k

      Hi All,

      I'm new to JMX and got some basic questions related to deployment of Mbeans and registering of mbeans.

      Got some code for mbean.

      Mbean interface :

      public interface HelloMBean {

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

      public String getName();

      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;
      }

      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);
      }

      private final String name = "Reginald";
      private int cacheSize = DEFAULT_CACHE_SIZE;
      private static final int DEFAULT_CACHE_SIZE = 200;
      }

      Now , i would like to know , how to deploy the above code in JBOSS server and make the mbean register.

      Are there any descriptor and i need to update , so that jboss will invoke the mbean registering function and the startup.

      And please let me know , how i can lookup those mbean services.

      Thanks,
      Elangovan.

      Hello.java

        • 1. Re: my first JMX
          dikar

          There is a simple example for you (in windows OS)
          By the way ,you must add the jboss-system-x.x.x.jar and jboss-jmx-x.x.x.jar in your lib path(or eclipse build path),these jar in JBoss lib dir.

          
          ##############################################
          package JMX;
          
           import org.jboss.system.ServiceMBean;
          
           public interface HelloWorldServiceMBean extends ServiceMBean {
          
           public String getMessage();
           public void setMessage(String message);
          
           }
          /***********************************************************/
          package JMX;
          
          
          
           import org.jboss.system.ServiceMBeanSupport;
           public class HelloWorldService extends ServiceMBeanSupport implements HelloWorldServiceMBean {
           private String message;
          
           public HelloWorldService()
           {
           super();
           // TODO Auto-generated constructor stub
           }
          
           public String getMessage() {
           System.out.println("getMessage()=" + message);
           return message;
           }
          
          
          
           public void setMessage(String message) {
           System.out.println("setMessage(" + message + ")");
           this.message = message;
          
          
           }
          
          
           }/***********************************************************/
          jboss-service.xml
          -----------------------------------------------------------------------------------
          <?xml version="1.0" encoding="UTF-8"?>
           <server>
           <mbean code="JMX.HelloWorldService" name="JBoss:service=HelloWorldService">
           <attribute name="Message">Hello World</attribute>
           </mbean>
           </server>----------------------------------------------------------
          
          


          In your JBOSS deploy dir ,for example:"jboss-4.2.2.GA\server\default\deploy" ,you create a dir named "Hello.sar" and new create 2 files in "Hello.sar" ,one named "JMX" and other named "META-INF".Then put the HelloWorldService.class and HelloWorldServiceMBean.class in your "JMX" dir. and new a XML file named jboss-service.xml write the content like above red XML.
          ok you can run your JBOSS and access the http://127.0.0.1:8080/jmx-console/

          find the "service=HelloWorldService " in JBoss domain.

          Note: I'm very sorry that my English not well.




          • 2. Re: my first JMX
            dikar

            I'm very sorry that I forget to tell you that put the jboss-service.xml in your "META-INF" dir.

            this is the structure of hello.sar dir
            hello.sar
            -------META-INF
            --------------jboss-service.xml
            -------JMX
            --------------HelloWorldService.claa
            --------------HelloWorldServiceMBean.claa