Jeff Mesnil
Weblog · About

jmx4r 0.0.4 is released

August 7, 2007

jmx4r 0.0.4 has just been released.
jmx4r is a JRuby library which makes it super easy to write simple Ruby scripts to manage Java applications using JMX.

To get this new release, just update the rubygem: jruby -S gem install jmx4r

All contributions to this new release were done by Skaar:

  • CompositeData behave like regular read-only Ruby Hash
  • custom classes can be loaded by require statements
  • custom JMX credentials are supported

CompositeData as read-only Hash

CompositeData are the open and interoperable way to return custom data structures from JMX.
They now behave in jmx4r as regular read-only Ruby Hash.

For example, the JVM exposes its heap memory usage with such a composite data:

memory = JMX::MBean.find_by_name "java.lang:type=Memory"
# heap is a CompositeData attribute
heap = memory.heap_memory_usage

To list the name and values of the heap attribute, the code was:

heap.composite_type.key_set.each do |type|
    puts "#{type} : #{heap.get type}"

and now it is simply:

heap.keys.each do |key|
    puts "#{key} : #{heap[key]}"

Classloading using require

A second contribution by Skaar was to fix a classloading problem. In case you need to use custom classes in your JMX code, only classes loaded from JRuby's classpath were taken into account. It is now possible to reference classes loaded using require statements.

Custom JMX credentials

jmx4r now allow you to specify custom credentials used by JMX authentication (as specified by a JMXAuthenticator) in addition to the "standard" :login/:password credentials:

creds = create_my_custom_credentials()
# creds will be used by the JMXAuthenticator on the MBeanServer
JMX::MBean.establish_connection :credentials => creds