• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

JBoss ServerInfoMBean - How do I use it from within a Session EJB?

I need to display information about my JBoss server in a client application. I'm going to implement that by adding a method to one of my Stateless Session Bean that returns a single object (POJO) with this information.

The information I'm looking for are (among others):
- The runtime configuration name of the JBoss server.
- The version of the JBoss
- The version of the JVM
- etc.

Basically this is the same information that is displayed on the "web-console" web application that comes with JBoss.

I took a look at that web app and unfortunately I only found the JSP way of doing this. They use some JBoss specific tag library to gain access to the ServerInfoMBean and from there it's easy for them to get all this information.

My question is: How do I get access to the ServerInfoMBean from within my Stateless Session EJB?

I'm going to try to dig up this taglib that JBoss uses and I'll post a comment here if I find out how they do that there.

Kind regards, Stefan Freyr.
0
stefanfreyr
Asked:
stefanfreyr
  • 4
  • 4
  • 2
1 Solution
 
TimYatesCommented:
From:

http://www.cenqua.com/clover/eg/jboss/report/org/jboss/system/server/ServerInfo.html

can't you just lookup:

    jboss.system:type=ServerInfo

Then call the methods declared in ServerInfoMBean?

I'll have a bit of a better look now...
0
 
TimYatesCommented:
Yeah...I *reckon* you should be able to do:

        RMIAdaptor jboss = (RMIAdaptor)context.lookup( "jmx/rmi/RMIAdaptor" ) ;
        ObjectName name = new ObjectName( "jboss.system:type=ServerInfo" ) ;
        System.out.println( jboss.invoke( name, "getJavaVersion", null, null ) ) ;

maybe ;-)

Again, I haven't tested this...  but it feels right...

Tim
0
 
stefanfreyrAuthor Commented:
ok... I'll give it a go... but isn't there any way of getting an instance of ServerInfo and calling the methods directly? I really don't like putting too much reflection stuff in my code :o(
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
TimYatesCommented:
That's not reflection....ok well, it is...  but really, it's a normal JMX lookup call

You could just put the methods that are in serverinfo into your own EJB...  

all it does is call System.getProperty()  (see the link I posted -- all the methods are in the lower half of the class)

So rolling your own methods is always a distinct possibility :-)
0
 
stefanfreyrAuthor Commented:
Tested and it works!

Now I just have to find out what thing I should ask for information about what address this server is bound to (when running jboss you can bind it to a specific IP).

Thanks a lot for your help.
0
 
TimYatesCommented:
Cool :-)

Did you go the "RMIAdaptor" route?

Glad you got it working!!

>> Now I just have to find out what thing I should ask for information about what address this server is bound to (when running jboss you can bind it to a specific IP).

Eeeep!  I have no idea where this will be...  but I guess it will be one of the MBeans (so you should be able to do a similar thing) :-)

Good luck with it all!!

Tim
0
 
aozarovCommented:
BTW, in your case where your code is running in the same JVM as JBoss you don't have to use RMIAdaptor (which is an rmi delegator to the local MBeanServer and used by remote clients).
You can just get the MBeanServer by calling:
MBeanServer server = MBeanServerFactory.findMBeanServer(null).get(0);

and then applying the same logic provided above, hence:
ObjectName name = new ObjectName( "jboss.system:type=ServerInfo" ) ;
System.out.println( server.invoke( name, "getJavaVersion", null, null ) ) ;
0
 
stefanfreyrAuthor Commented:
Thank you very much... that really was getting on my nerves (using RMI from within the JVM).

Kind regards, Stefan.
0
 
stefanfreyrAuthor Commented:
I decided to go with this instead though:
MBeanServer jboss = MBeanServerLocator.locateJBoss();

The solution you pointed out is used all over the JBoss source code but this somehow seems a bit more "stable". If I understand correctly it can also find MBeanServers on a network so I'm guessing (and that's really what I'm doing... guessing!) that it might be a bit more "cluster friendly" even.

If anybody knows of some good (by good I mean not bloated... just a concise, to the point high level explanation of the MBeanServer stuff in JBoss, I'd really appreciate knowing about it.

Kind regards, Stefan.
0
 
aozarovCommented:
MBeanServerLocator is Jboss specific code.
This is what it does: http://www.docjar.com/html/api/org/jboss/mx/util/MBeanServerLocator.java.html
It doesn't not seem to be "cluster friendly" but rather will find the MBeanServer of the same JVM.
See for for Jboss specific JMX information: http://www.jboss.org/wiki/Wiki.jsp?page=JBossMX
For general details about JMX and JMX MBeanServer: http://java.sun.com/developer/technicalArticles/J2SE/jmx.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now