jmx4r
jmx4r copied to clipboard
Allow attributes to be backed by methods, not just plain attr_accessors
Hey there,
So I've tweaked the dynamic mbean class a bit so that you can do things like:
class HttpServerMBean < JMX::DynamicMBean
def initialize(http_server)
@http_server = http_server
end
r_attribute :thread_count, :int, 'number of threads'
def thread_count
@http_server.thread_count
end
end
It didn't work as it was, because it was fetching values by accessing the instance variable directly, which didn't seem necessary. I could have gone a lot further, you can see the code above code benefit from some ruby meta magic, but this was just enough to get in what I needed. I also made another small change so you can connect via pid, useful when you have a pidfile somewhere, as I often do.
Cheers, Nick