1 Reply Latest reply on Sep 3, 2004 8:21 PM by Nicholas Whitehead

    How to get a reference to a MBean ?

    James Adams Novice

      I have a MBean which I want to access in other classes. I assume that I should get a reference to this MBean via a JNDI lookup. If this is true then what name should I use for the lookup ? Do I need to bind the MBean to a name in the MBean's constructor or start() method, and then use this name for the lookups ? Or can I use the name specified in the mbean element for the MBean (found in the jboss-service.xml of the MBean's SAR) ?

      Thanks in advance for any information.


        • 1. Re: How to get a reference to a MBean ?
          Nicholas Whitehead Novice

          You do not need a reference to the MBean. You simply need a reference to the JMX agent (MBeanServer). You can then invoke calls to the MBean through the agent.

          Get the MBeanServer like this:

          MBeanServer mbeanServer = (MBeanServer) MBeanServerFactory.findMBeanServer(null).

          Create an ObjectName for your MBean like this:

          ObjectName objectName = new ObjectName("<mydomain>:<myname>");


          ObjectName objectName = new ObjectName("com.example:service=myservice");

          Check the JMX Console for the name of your MBean.

          Then, invoke methods against your mbean as follows:

           "<method name>",
           new Object[]{<array of object params>},
           new String[]{<array of class types of objects>}

          Consult the javax.management JavaDoc for more details.