Question

I'm trying to access the JBoss v4.2 MBean registered as

jboss.web:type=Manager,path=/,host=localhost

using the following code:

ObjectName name = new ObjectName("jboss.web:type=Manager,path=/,host=localhost");
ManagementFactory.getPlatformMBeanServer().getAttribute(name, "activeSessions");

But this code keeps throwing the following exception:

javax.management.InstanceNotFoundException : jboss.web:type=Manager,path=/,host=localhost is not registered.

On the other hand I'm able to see and use this bean using the jmx-console via ...//localhost:8080/jmx-console/ - the MBean is available.

Screenshot

What else is necessary to access the same MBean via code?

Was it helpful?

Solution

Found it...

ObjectName name = new ObjectName("jboss.web:type=Manager,path=/,host=localhost");
this.sessions = new Long((Integer) MBeanServerLocator.locateJBoss().getAttribute(name, "activeSessions"));

I had to find the right MBeanServer... MBeanServerLocator.locateJBoss() solves it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top