SimpleJmx - Simple JMX Java Package

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.

Start Simple JMX Server and Register Objects

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();

Use Annotations to Mark JMX Objects

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() { ... } }

Simple JmxClient Class Included

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 objectNameSet = client.getBeanNames(); // get the start-time in milliseconds long startTimeMillis = (Long)client.getAttribute(new ObjectName("java.lang:type=Runtime"), "StartTime"); // run garbage collection client.invokeOperation(new ObjectName("java.lang:type=Memory"), "gc");

Here are the javadocs for my JmxClient.

Free Spam Protection   ORMLite Java ORM   Android ORM   Simple Java Magic