This is not a tag line!
Posts tagged jmx
Accessing a JMX object programmatically from JBoss
Apr 15th
OK so here’s some geeky information… I’ve had several times the need to access a JMX service programmatically and each time, I had to hunt down the information so here it is so that I know where to find it next time.
It took me three years almost to the days to need that piece of code again and realize that it wouldn’t even compile… Should be fixed now!
import org.jboss.mx.util.MBeanProxy;
import org.jboss.mx.util.MBeanProxyCreationException;
import org.jboss.mx.util.MBeanServerLocator;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
ObjectName objectName;
String name;
try {
objectName = new ObjectName(name);
} catch (MalformedObjectNameException e) {
throw new IllegalArgumentException("'" + name + "' is not a valid ObjectName");
}
MBeanServer server = MBeanServerLocator.locateJBoss();
try {
return MBeanProxy.get(clazz, objectName, server);
} catch (MBeanProxyCreationException e) {
String message = "Couldn't retrieve '" + objectName.getCanonicalName() + "' MBean with class " + clazz.getName();
throw new RuntimeException(message, e);
}
