Here's a quick JMX package that I whipped up which allows really easy JMX publishing. It also includes a descent JMX client library with a command-line and batch-file capabilities.
SimpleJmx contains easy to use server and client objects with which you can publish your JMX beans. The full code of the example program is in SVN.
// create a new server listening on port 8000 JmxServer jmxServer = new JmxServer(8000); // start our server jmxServer.start(); // register our lookupCache object defined below jmxServer.register(lookupCache); jmxServer.register(someOtherObject); // stop our server jmxServer.stop();
Instead of having to create mbean Java interface classes, you use annotations to mark both the objects to be published via JMX and also the getter, setter, and operations methods can can be called via jconsole. For example:
@JmxResource(description = "Lookup cache", domainName = "j256", beanName = "LookupCache") public class LookupCache { // this can also be specified as @JmxAttributeMethod on the getter/setter methods @JmxAttributeField(description = "Number of hits in the cache") private int hitCount; ... @JmxOperation(description = "Flush the cache") public void flushCache() { ... } }
A simple JMX client class is also included as part of the package. There are other, better packages that handle JMX client connctions but I thought SimpleJMX needed to have client and server capabilities.
JmxClient client = new JmxClient("some.host.name", somePortNumber);
// get the set of bean names exported by the JVM
Set
Free Spam Protection ORMLite Java ORM Android ORM Simple Java Magic