• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to reference a JMX MBean ?

 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian Tinnel
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In WebLogic, you use a different method to get an MBeanServer. But you still get the MBeanServer and use it.
 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much, the MBeanServer.invoke() method was the solution I needed.


--James
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic