Wednesday July 09, 2008 VisualVM's JMX API entrypoints available in VisualVM-Tools module
It's more than likely that VisualVM plugin developers will be interested in accessing their JMX instrumented applications from within VisualVM. The VisualVM-Tools module adds some public APIs for JMX-related things in the com.sun.tools.visualvm.tools.jmx package required to get access to the underlying JMX connection and also to retrieve the JVM MXBeans that will grant access to the underlying JVM instrumentation. Then writing a JMX-based plugin for VisualVM is as simple as defining your custom UI and fill it in with the information coming from the JMX model.
Find below some examples of use:
JmxModel jmx = JmxModelFactory.getJmxModelFor(application);
if (jmx == null || jmx.getConnectionState() != JmxModel.ConnectionState.CONNECTED) {
// JMX connection not available...
} else {
MBeanServerConnection mbsc = jmx.getMBeanServerConnection();
if (mbsc != null) {
// Invoke JMX operations...
}
}
JmxModel jmxModel = JmxModelFactory.getJmxModelFor(application);
if (jmxModel != null && jmxModel.getConnectionState() == ConnectionState.CONNECTED) {
JvmMXBeans mxbeans = JvmMXBeansFactory.getJvmMXBeans(jmxModel);
if (mxbeans != null) {
MemoryMXBean memoryMXBean = mxbeans.getMemoryMXBean();
// Get/Set attributes or Invoke operations on MemoryMXBean...
}
}
In order to reduce the number of network roundtrips between the JMX clients running in the VisualVM tool and the JMX servers running in the target VMs, save some bandwidth and improve overall performance you can cache both the JMX model and the JVM instrumentation MBeans attributes values for a given interval and register MBean cache listeners that will be notified when the MBean cache has been flushed such that the presentation layers can be updated with the new values by simply calling the getter methods in the MBeans. Have a look at CachedMBeanServerConnectionFactory and JvmMXBeansFactory to have more detailed info on these APIs.
Posted by lmalvent ( Jul 09 2008, 11:58:05 PM CEST ) Permalink Comments [0]