JConsole custom MBean GUI tabs

For composite types, favor the newer MXBeans over MBeans

Applying MXBean mapping to your own types

Create UI in custom JPanel constructor, not in:

public SwingWorker newSwingWorker() {


JConsole calls the custom plug-in method passing in a connection:

MBeanServerConnection conn = null;
public void setMBeanServerConnection(
final MBeanServerConnection mBeanServerConnection) {
conn = mBeanServerConnection;
//save connection and automatically
//register for notifications here
...
}


To get a proxy to an MBean:

ObjectName oname =
new ObjectName(
"someTopNode:type=SomeMBeanName,name=someUniqueInstanceIdentifierString");

SomeMBean b =
JMX.newMXBeanProxy(conn,
oname,
SomeMBean.class,
true);


Access MBean attributes directly from proxy or as follows:

...
Object a = conn.getAttribute(oname, "SomeAttributeName");


Invoke MBean methods directly from proxy or as follows:

...
String[] paramClasses = new String[] {"java.lang.String"};
Object[] params = new Object[] {"someStringValue"};
conn.invoke(oname, "someMethodName", params, fqParamClasses);


To register for remote notification:

...
conn.addNotificationListener(oname,
new Handler(),
null, null);


To handle the notification:

public void handleNotification(
final Notification notification,
Object handback) {

new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
return null;
}

@Override
protected void done() {
//update UI on EDT
}
}.execute();
}


Java 6 u10 ManagementFactory can only return built-in MBean proxies. Can't get a Proxy to access custom MBeans with:

ManagementFactory.newPlatformMXBeanProxy(...)


Custom GUI tabs can be created for JConsole to interface with application MBeans.

VisualVM has a wrapper for adding custom tabs.

Java 6 JMX API Enhancements

Ways to access MXBeans

MBean notification events - stand-alone, not in JConsole

Add library $JDK_HOME/lib/jconsole.jar

Extend the abstract class com.sun.tools.jconsole.JConsolePlugin

Implement the getTabs and newSwingWorker methods

The newSwingWorker method returns the SwingWorker that will update the custom GUI tab.

Your plug-in must be in a jar file that contains a file named:
META-INF/services/com.sun.tools.jconsole.JConsolePlugin

This JConsolePlugin file should contain a list of all the fully-qualified class names of the plug-ins you want to add as new JConsole tabs. JConsole uses the service-provider loading facility to look up and load the plug-ins. You can have multiple plug-ins, with one entry per plug-in in the JConsolePlugin.

To load custom plug-ins into JConsole, start JConsole with the following command:

jconsole -pluginpath <plugin path>

The plugin path specifies the paths to the custom JConsole plug-ins to be loaded. The paths can be directory names or specific jar files. Multiple paths can be specified, with your platform's path separator char.

Basic documentation can be found by launching JConsole, clicking on Help and going all the way to the bottom. There is a JTop example provided with the JDK.

Jar contents - the first two entries are the class files
CustomJConsolePlugin extends JConsolePlugin
implements PropertyChangeListener
has CustomPanel
CustomPanel extends JPanel
META-INF/services/com.sun.tools.jconsole.JConsolePlugin
text file with one line listing plugin CustomJConsolePlugin

Comments

Popular posts from this blog

Sites, Newsletters, and Blogs

Oracle JDBC ReadTimeout QueryTimeout