Home / Java / Guice and JMX on JBoss

Guice and JMX on JBoss

It is very easy to use Guice’s runtime injector bindings to register MBeans on any instance of mbean server. Lets look at a simple example of a HelloMBean. In this example a simple MBean is created and registered on JBoss using google-guice runtime injection.

The implementation of this MBean needs to have a method for the injection of the MBeanServer.

Now all that needs to be done is creating an Injector with bean and server bindings. The following piece of code can be used in any class (like a Servlet) to register the MBean when the application is deployed or as part of your injection bootstrap.

You can also use “ManagementFactory.getPlatformMBeanServer()” to get/create an MBeanServer. Unfortunately this method cannot be used to get/locate the current JBoss MBeanServer, so “MBeanServerLocator” in the last code snippet above is the only way to locate a JBoss MBean Server instance. After the bean is registered you can use jboss jmx-console or jdk’s jconsole to access the mbean.

About Author:

Leave A Comment

Your email address will not be published. Required fields are marked *