JMX & Sun Java System 8.1
Hi,
I'm using Sun java System Server 8.1 Q1 with JDK 1.5
I've implemented a Lifecycle Listener for the READY_EVENT and within it, I've created a MBean (not registered it, since regsitration does not support remote monitoring) using the MBeanServer instance that I obtained via:
ManagementFactory.getPlatformMBeanServer()
I ran the MBean creation part of the code on a local, standalone JVM (via Eclipse, as an example). When I started JConsole, it shows me the JVM process on the Loacl tab and surely enough, I can connect and view my MBean therein.
When I deploy the Lifecycle Module, the code runs fine and the MBean gets created without any problems (I've inserted debug statements to detect any untoward behaviour). This time around, when I connect JConsole using the Advanced tab and the JMX URL provided the Sun App Server's server.log, it connects fine and shows me all the MBeans registered on the Server (amx, amx-support, etc), but I cannot see my MBean!
Any pointers?
The code looks similar to :
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
logger.debug("MyMBeanAgent.doMBeans() - MBeanServer '" + mbs.toString() +"' created");
myObjectName =new ObjectName(Constants.MY_OBJECT_NAME);
mbs.createMBean("com.my.package.MyJMXData", myObjectName);
logger.debug("MyMBeanAgent.doMBeans() - MBean Created");
Thanks.
-Ravi
Humm... I should probably investigate further before trying to answer - especially since it is very late here in France ;-), but this is what pops up to my mind:
Could it be possible that the server's connector does not expose the platform MBeanServer - but another MBeanServer?
Could this be related to this: http://forum.java.sun.com/thread.jspa?threadID=754170&tstart=0 ?
Or are there actually two JVMs? How many server processes do you see?
By the way you can use registerMBean when you create your MBean locally as you do.
-- daniel
http://blogs.sun.com/roller/page/jmxetc
Hi Daniel,
Bingo!
Your first guess was correct - the App Server does indeed expose another MBeanServer, which is separate from the PlatformMBeanServer.
Currently I've done the following to get it working:
MBeanServer mbs = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
Of course, fetching the very first MBeanServer found by findMBeanServer may be slightly dicey, so I shall fine-tune the code to get the appropriate MBeanServer.
The rationale behind using MBeanServerFactory instead of ManagementFactory is (as specified in the API Documentation for MBeanServerFactory for J2SE 5.0) :
"
Since JMX 1.2 this class makes it possible to replace the default MBeanServer implementation. This is done using the MBeanServerBuilder class. The class of the initial MBeanServerBuilder to be instantiated can be specified through the javax.management.builder.initial system property. The specified class must be a public subclass of MBeanServerBuilder, and must have a public empty constructor.
"
The Sun Java System App Server 8.1 does indeed provide the javax.management.builder.initial system property in domain.xml.
Cheers!
Ravi