This content has been marked as final.
Show 1 reply
-
1. Re: How to get a reference to a MBean ?
nickman Sep 3, 2004 8:21 PM (in response to monocongo)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). iterator().next();
Create an ObjectName for your MBean like this:ObjectName objectName = new ObjectName("<mydomain>:<myname>");
e.g.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:mbeanServer.invoke(objectName, "<method name>", new Object[]{<array of object params>}, new String[]{<array of class types of objects>} );
Consult the javax.management JavaDoc for more details.
//Nicholas