aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes How to reference a JMX MBean ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to reference a JMX MBean ?" Watch "How to reference a JMX MBean ?" New topic
Author

How to reference a JMX MBean ?

James Adams
Ranch Hand

Joined: Sep 12, 2003
Posts: 188
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.


--James
James Adams
Ranch Hand

Joined: Sep 12, 2003
Posts: 188
BTW my aplogies if this is the wrong forum for this question -- there's no JMX forum here and I don't think this question is really JBoss-specific. If there's a better place for JMX questions then please let me know.

--James
Brian Tinnel
Ranch Hand

Joined: Aug 25, 2003
Posts: 69
Access to an MBean is usually done via the MBeanServer. In JBoss, you can get the MBeanServer like this:



I think that works on any JBoss server. I know that it does not work on other app servers. According to the spec, you can also use an MBeanServerDelegate, but I'll let you read the spec to figure out how to do that.

Once you have the MBeanServer, you can use it to invoke methods on the MBeans registered with it. Basically, you want to call MBeanServer.invoke. It takes a number of parameters to specify the name of the mbean, the method on the mbean to call, the parameters to pass, and the class names of those parameters. Download the api spec for more information.

A simple call might look like:

amit mawkin
Ranch Hand

Joined: Oct 31, 2001
Posts: 73
Hi,

Correct me if If I am wrong a reference to mbean is usually get by the mbean agent in which you register the name by which it can be called by remote clients as well as provide the detailed implementation.
In weblogic its done like that not sure of Jboss.


regards, Amit
coffee drinker and Sun Certified Programmer for Java 2 Platform
Brian Tinnel
Ranch Hand

Joined: Aug 25, 2003
Posts: 69
In WebLogic, you use a different method to get an MBeanServer. But you still get the MBeanServer and use it.
James Adams
Ranch Hand

Joined: Sep 12, 2003
Posts: 188
Thanks so much, the MBeanServer.invoke() method was the solution I needed.


--James
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to reference a JMX MBean ?