[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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