fatnjazzy
fatnjazzy

Reputation: 6152

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.

Upvotes: 3

Views: 1075

Answers (3)

Gray
Gray

Reputation: 116918

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.

Upvotes: 2

Nicolas Modrzyk
Nicolas Modrzyk

Reputation: 14197

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.

Upvotes: 1

Jon Freedman
Jon Freedman

Reputation: 9707

Have you seen the @MXBean annotation, it may be what you're after, and is part of Java 6.

Upvotes: 0

Related Questions