Introducing Groovy JMX Builder - No Fluff Just Stuff

Introducing Groovy JMX Builder

Posted by: Vladimir Vivien on April 9, 2008

After I attended the Groovy/Grails Experience in February this year, I realize that the Groovy builder pattern can be used to façade many other API's (not just swing). So, I decide to create, yet another builder, for the JMX API and here it is!

http://code.google.com/p/groovy-jmx-builder/

Features

Suppose you have a class called Greeter (on your class path) that prints out greeting to a specified person in a specified language, so the class may look like this

public class Greeter {
private String name;
private String language = "en";

// ...

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

// ...

public String greet(){
String greet = (String) (langs.containsKey(getLanguage()) ?
langs.get(getLanguage()) : langs.get("en"));
return greet + " " + getName();
}

String greet(String person){
return langs.get(language) + " " + person
}
}

You can use Groovy Jmx Builder to expose an instance of that class for management as an MBean.

def greeter = new Greeter()
JmxBuilder jmx = new JmxBuilder()
def server = jmx.export(svr){
bean(greeter){
name("greeterDemo:service=greeting")
desc("This service prints a greeting on console")
attribute(name:"name", desc:"name of person to greet", writable:true)
attribute(name:"language", desc:"the language to use", editable:true)
operation(name:"greet", desc:"Sends greeting to user")
operation(name:"greet", desc:"Send greeting to user"){
parameter(type:"java.lang.String", name:"Person", desc:"The person to send greeting to")
}
}

bean(object:greeter, name:"greeterDemo:service=greeting2")
}
You use the JmxBuilder() class to capture meta data about your class instance that will be made available at runtime for management.

In JConsole, the generated MBean may look like this



Feedbacks
I am interested in feedbacks for this project. So, download it and give it a try. I will be adding more features to it in the future.
Vladimir Vivien

About Vladimir Vivien

Vladimir Vivien is a software engineer living in the United States. Past and current experiences include development in Java and C#.Net for industries including publishing, financial, and healthcare. He has a wide range of technology interests including Java, OSGi, Groovy/Grails, JavaFX, SunSPOT, BugLabs, module/component-based development, and anything else that runs on the JVM.

Vladimir is the author of “JavaFX Application Development Cookbook” published by Packt Publishing. He is the creator of the Groovv JmxBuilder open source project, a JMX DSL, that is now part of the Groovy language. Other open source endeavor includes JmxLogger and GenShell. You can follow Vladimir through his blog: http://blog.vladimirvivien.com/, Twitter: http://twitter.com/vladimirvivien, and Linked In: http://www.linkedin.com/in/vvivien.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »