Introducing Groovy JMX Builder
http://code.google.com/p/groovy-jmx-builder/
Features
- Ability to expose any class instance for management for both Java and Groovy classes.
- No need to implement a specific management interface.
- Shield developer from complexity of JMX API
- Use familiar Groovy builder pattern
- Exposes attribute, constructors, operations, parameters
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()You use the JmxBuilder() class to capture meta data about your class instance that will be made available at runtime for management.
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")
}
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.
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.
More About Vladimir »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 7
- Agility
- Testing: Geb, Spock, Easyb
- REST
- NoSQL: MongoDB, Cassandra
- Hadoop
- Spring 3
- Automation Tools: Git, Hudson, Sonar
- HTML5, Ajax, jQuery, Usability
- Mobile Applications - iPhone and Android
- More...
NFJS, the Magazine
December Issue Now AvailableBDD and REST
by Brian SlettenMocks and Stubs in Groovy Tests
by Kenneth KousenAlgorithms for Better Text Search Results
by John GriffinKnowns and Unknowns of Scrum and Agile
by Brian Tarbox

