How to make JMX simple
I need to expose about 60 operations in a 30 different classes to JMX. Making it with DynamicMBean
is a bit annoying. I am looking for a fast and elegant way to do it.
I know that Spring has a nice way with annotations but i am not using spring in 开发者_如何学编程this project.
Please take a look at my SimpleJmx Java package which is designed to easily publish beans via JMX using annotations. It also has client code as well.
Quick code sample:
// you can also use the platform mbean server
JmxServer jmxServer = new JmxServer(8000);
jmxServer.start();
// register our lookupCache object defined below
jmxServer.register(lookupCache);
...
jmxServer.stop();
Here's how to define a bean.
@JmxResource(domainName = "j256", description = "Lookup cache")
public class LookupCache {
@JmxAttributeField(description = "Number of hits in the cache")
private int hitCount;
...
@JmxOperation(description = "Flush the cache")
public void flushCache() {
...
}
}
Feedback welcome.
If it's just a set of easy operations, you could use the JMX support provided in Clojure contrib:
Clojure Contrib
Clojure compiles to Java so you would not have much problems integrating with your current project.
Have you seen the @MXBean annotation, it may be what you're after, and is part of Java 6.
精彩评论