# Jmx4r metaprogramming

**URL:** <https://www.ruby-forum.com/t/jmx4r-metaprogramming/192715>\
**Category:** Ruby\
**Created:** [August 4, 2010, 1:10pm UTC](https://www.ruby-forum.com/t/jmx4r-metaprogramming/192715 "2010-08-04T13:10:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [August 4, 2010, 1:10pm UTC](https://www.ruby-forum.com/t/jmx4r-metaprogramming/192715/1 "2010-08-04T13:10:44Z")

</div>

Hi,

I am attempting to use the jmx4r library to set an MBean attribute.

From here: [JMX the Ruby way with jmx4r](http://www.infoq.com/news/2007/06/jmx4r-jruby)

It looks like jmx4r uses metaprogramming techniques which disposes  
with JMX method calls.

However, I am receiving a

`method_missing': undefined method `active =’

exception, when I attempt to set the attribute.

require ‘rubygems’  
require ‘jmx4r’

include JMX  
MBean.establish\_connection :host =\> “xxxxx”, :port =\> 8999  
standby\_mbean = MBean.find\_by\_name  
“xxx.jmx.monitors:name=hydra.planb.cps,type=JmsQueueStatsMBeanFactory”  
standby\_mbean.active # == true  
begin  
standby\_mbean.active = false  
ensure  
MBean.remove\_connection  
end

Do I need to explicitly invoke an operation?

Thanks

Aidy

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [August 4, 2010, 4:46pm UTC](https://www.ruby-forum.com/t/jmx4r-metaprogramming/192715/2 "2010-08-04T16:46:04Z")

</div>

aidy wrote:

> Hi,
> 
> I am attempting to use the jmx4r library to set an MBean attribute.

> `method_missing': undefined method`active =’
> 
> exception, when I attempt to set the attribute.

This error is strange, there should not be a white space between  
‘active’ and ‘=’. The method to set the value should be ‘active=’, not  
‘active =’

This may be due to an error in the description of the MBean.  
What you can do:

- check what attributes are exposed by the jmx4r mbean  
irb\> standby\_mbean.attributes
- check what is exposed by the Real JMX MBean object:  
irb\> JMX::MBean.pretty\_print  
“xxx.jmx.monitors:name=hydra.planb.cps,type=JmsQueueStatsMBeanFactory”

In you case, you should see a “Value” attribute which is both readable  
and writable.

hope that helps,  
jeff

---

<div class="post-metadata">

**Author:** ![aidy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@aidy](https://www.ruby-forum.com/u/aidy)\
**Post date:** [August 4, 2010, 6:45pm UTC](https://www.ruby-forum.com/t/jmx4r-metaprogramming/192715/3 "2010-08-04T18:45:40Z")

</div>

Hi Jeff

jmx4r is a pretty useful library.

> This error is strange, there should not be a white space between  
> ‘active’ and ‘=’. The method to set the value should be ‘active=’, not  
> ‘active =’

That is a typo, apologies.

> This may be due to an error in the description of the MBean.  
> What you can do:
> 
> - check what attributes are exposed by the jmx4r mbean  
> irb\> standby\_mbean.attributes

standby\_mbean.attributes.each { |a | puts a.grep /^ac/ }

# =\> active

> - check what is exposed by the Real JMX MBean object:  
> irb\> JMX::MBean.pretty\_print  
> “xxx.jmx.monitors:name=hydra.planb.cps,type=JmsQueueStatsMBeanFactory”

very nice

> In you case, you should see a “Value” attribute which is both readable  
> and writable.

writable is false and I am an idiot.

I then successfully invoked a JMX operation on the object returned  
with MBean#find\_by\_name

Thanks

Aidy
