Treasure Trove: jmxutils 07 Oct 2009
Gianugo and I used to do a talk at JavaOne called “The Long Tail Treasure Trove.” The goal of the talk was to introduce at least thirty or so small, open source, useful libraries which the majority of attendees had never heard of. They were great talks. We haven’t done one, in a while, so at Henri’s prompting (very belatedly), I’m just going to start blogging them!
So, we’ll start with a great one – Martin’s JMX exporting library, jmxutils. Writing JMX beans tends to be agonizing, so unless someone is holding a blowtorch to you toes, you avoid it. Well, it doesn’t need to be, examine this:
public class Something
{
private volatile String color;
@Managed(description="Favorite Color")
public String getColor() {
return color;
}
@Managed
public void setColor(String color) {
this.color = color;
}
@Managed
public void pickOne(String first, String second) {
this.color = second;
}
}
MBeanExporter exporter
= new MBeanExporter(ManagementFactory.getPlatformMBeanServer());
Something s = new Something();
exporter.export("org.skife.example:name=Something", s);
This little tidbit exports a JMX Bean, building a model mbean by inspecting the annotations. This particular one exports a mutable property (color) and an operation (pickOne). Nicely, it uses Paranamer (subject for another post) to even get the parameter names on the operation right!
Now, to get it into maven central…