Friday, January 24, 2003

JMX-enable a bean in 3 easy steps

Another java trivia:

1. Add jmx.jar and commons-modeler.jar in your CLASSPATH

2. Insert at the top of the file:

import org.apache.commons.modeler.Registry;

3. Add in constructor ( or somewhere ):

Registry reg=Registry.getRegistry();

reg.registerComponent( this, DOMAIN, TYPE, OBJECTNAME );

The type doesn't matter too much unless you have the optional mbeans-descriptors.xml in the same package. Start the JMX console ( that's a bit more complicated - another 3 steps ) and enjoy viewing/setting attributes at runtime.

Why would you want to do that ? For fun and to monitor what's happening inside your app, or control it "life".

A HEAD build of modeler is required ( 1.0 won't work ).

No comments: