• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to reference a JMX MBean ?

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much, the MBeanServer.invoke() method was the solution I needed.


--James
 
And then the flying monkeys attacked. My only defense was this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic