SimpleJmx - Simple JMX Java Package Using Annotations

This package provides classes that simplify the publishing of objects using Java's Management Extensions (JMX). These published objects can be investigated with jconsole (Sun's graphical JMX user interface application) or another JMX client. Included is also a programmatic JMX client which you can use to connect to and interrogate remote JMX servers as well as a web/HTTP interface so you can publish JMX beans to a browser or other web client.

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 checked into source control.

// create a new server listening on port 8000 JmxServer jmxServer = new JmxServer(8000); // or: JmxServer jmxServer = new JmxServer(ManagementFactory.getPlatformMBeanServer()); // start our server jmxServer.start(); // register our lookupCache object defined below jmxServer.register(lookupCache); jmxServer.register(someOtherObject); ... // now you can use your JMX client to connect on port 8000 ... // stop our server jmxServer.close();

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

You can also programmatically public beans with code or Spring configuration.

Expose JMX Beans Over HTTP for Web Browsers

SimpleJMX also includes a simple web server handler to expose JMX beans over HTTTP.

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 connections 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<ObjectName> 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.

More 256 Sources

Free Spam Protection   Android ORM   Simple Java Magic   JMX using HTTP   Great Eggnog Recipe   Massachusetts Covid Vaccine Sites