Saturday, June 9, 2007

Nice Blog on JRuby + JMX

While stumbling around trying to replicate a JXTA Hello world type application in JRuby, I ran across a well-written tutorial by Jeff Mesnil on how to script JMX with JRuby as well a part II.


module JMX
require 'java'

include_class 'java.util.HashMap'
include_package 'java.lang.management'
include_package 'javax.management'
include_package 'javax.management.remote'

url = JMXServiceURL.new "service:jmx:rmi:///jndi/rmi://localhost:3000/jmxrmi"
connector = JMXConnectorFactory::connect url, HashMap.new
mbsc = connector.mbean_server_connection

memory_mbean = ManagementFactory::newPlatformMXBeanProxy mbsc, "java.lang:type=Memory",
MemoryMXBean::java_class

memory_mbean.verbose = !memory_mbean.verbose
puts "verbose = #{memory_mbean.verbose}"

memory_mbean.gc
end

No comments: