Forum: JRuby Setting JMX attributes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Josh M. (Guest)
on 2009-02-17 09:27
(Received via mailing list)
Hi, I am using edge jruby edge (rev 9083) and I am trying to set a JMX
attribute.  I can establish the connection and and read the variables no
problem.  But, when I try to set them I get this exception.

Here is the code that is causing the exception:
JMX::MBean.find_by_name("com.armorize:type=ScanEngine").maximum_concurrent_scans=(1)(Using
the jmx4r gem for convience but even when I do not use jmx4r I get
the same exception see next command).
conn.set_attribute(ObjectName.getInstance("com.armorize:type=ScanEngine"),
Attribute.new("MaximumConcurrentScans", 2))

Also I checked the MBean interface and I it is expecting an integer.

Thanks,

Josh

NativeException: javax.management.InvalidAttributeValueException:
attribute=
MaximumConcurrentScans value = 6
    from com/sun/jmx/mbeanserver/StandardMetaDataImpl.java:735:in
`setAttribute'
    from com/sun/jmx/mbeanserver/StandardMetaDataImpl.java:360:in
`setAttribute'
    from com/sun/jmx/mbeanserver/MetaDataImpl.java:206:in `setAttribute'
    from
com/sun/jmx/interceptor/DefaultMBeanServerInterceptor.java:737:in
`setAttribute'
    from com/sun/jmx/mbeanserver/JmxMBeanServer.java:722:in
`setAttribute'
    from javax/management/remote/rmi/RMIConnectionImpl.java:1433:in
`doOperation'
    from javax/management/remote/rmi/RMIConnectionImpl.java:81:in
`access$100'
    from javax/management/remote/rmi/RMIConnectionImpl.java:1247:in
`run'
    from javax/management/remote/rmi/RMIConnectionImpl.java:1343:in
`doPrivilegedOperation'
    from javax/management/remote/rmi/RMIConnectionImpl.java:681:in
`setAttribute'
    from sun.reflect.GeneratedMethodAccessor150:-1:in `invoke'
    from sun/reflect/DelegatingMethodAccessorImpl.java:25:in `invoke'
    from java/lang/reflect/Method.java:585:in `invoke'
    from sun/rmi/server/UnicastServerRef.java:294:in `dispatch'
    from sun/rmi/transport/Transport.java:153:in `run'
    from java/security/AccessController.java:-2:in `doPrivileged'
... 121 levels...
    from org/jruby/ast/NewlineNode.java:104:in `interpret'
    from org/jruby/ast/BlockNode.java:71:in `interpret'
    from
org/jruby/internal/runtime/methods/InterpretedMethod.java:163:in
`call'
    from org/jruby/internal/runtime/methods/DefaultMethod.java:144:in
`call'
    from org/jruby/runtime/callsite/CachingCallSite.java:273:in
`cacheAndCall'
    from org/jruby/runtime/callsite/CachingCallSite.java:112:in `call'
    from usr/local/share/jruby_edge/bin/jirb:19:in `__file__'
    from usr/local/share/jruby_edge/bin/jirb:-1:in `load'
    from org/jruby/Ruby.java:575:in `runScript'
    from org/jruby/Ruby.java:478:in `runNormally'
    from org/jruby/Ruby.java:352:in `runFromMain'
    from org/jruby/Main.java:222:in `run'
    from org/jruby/Main.java:103:in `run'
    from org/jruby/util/ShellLauncher.java:102:in `run'
    from java/lang/Thread.java:619:in `run'
Charles Oliver N. (Guest)
on 2009-02-17 10:03
(Received via mailing list)
I hate to ask, but does it do the same from Java? I know JMX is pretty
painful to do from Java so I won't fault you if you haven't tried.

You might try pulling Tom Enebo's JMX gem "gem install jmx" since it
works pretty well...then we could at least rule out whether it's
specific to the library.

Josh M. wrote:
>
>     from com/sun/jmx/mbeanserver/StandardMetaDataImpl.java:360:in
>     from javax/management/remote/rmi/RMIConnectionImpl.java:1247:in `run'
> ... 121 levels...
>     from org/jruby/Ruby.java:575:in `runScript'
>     from org/jruby/Ruby.java:478:in `runNormally'
>     from org/jruby/Ruby.java:352:in `runFromMain'
>     from org/jruby/Main.java:222:in `run'
>     from org/jruby/Main.java:103:in `run'
>     from org/jruby/util/ShellLauncher.java:102:in `run'
>     from java/lang/Thread.java:619:in `run'
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Josh M. (Guest)
on 2009-02-17 12:35
(Received via mailing list)
I just tried Tom Enebo's JMX gem and using Java and the Java worked but
the
gem did not.  It seams like the 2 is not getting cast right when it is
passed into JMX because when I was using java if I passed in a non
integer I
got the same exception.  Is there anyway to force JRuby to convert the 2
to
an integer?

Josh

On Tue, Feb 17, 2009 at 4:03 PM, Charles Oliver N. <
Thomas E Enebo (Guest)
on 2009-02-17 17:03
(Received via mailing list)
Perhaps try java.lang.Integer.new(2) in place of a raw 2.  I notice
that Attribute.new accepts an Object as a parameter.  I am not sure
how we pass our RubyFixnum over in that case, but I would still hope
it was getting unwrapped long/Long/int/Integer.  If that works, then
let us know.  This may be a JI bug.

-Tom

On Tue, Feb 17, 2009 at 4:34 AM, Josh M. <removed_email_address@domain.invalid>
wrote:
>>
>>> attribute.  I can establish the connection and and read the variables no
>>> Also I checked the MBean interface and I it is expecting an integer.
>>> `setAttribute'
>>> `doPrivilegedOperation'
>>>    from org/jruby/ast/BlockNode.java:71:in `interpret'
>>>    from org/jruby/Ruby.java:478:in `runNormally'
>>
>>   http://xircles.codehaus.org/manage_email
>>
>>
>
>



--
Blog: http://www.bloglines.com/blog/ThomasEEnebo
Email: removed_email_address@domain.invalid , 
removed_email_address@domain.invalid

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Charles Oliver N. (Guest)
on 2009-02-17 18:21
(Received via mailing list)
Thomas E Enebo wrote:
> Perhaps try java.lang.Integer.new(2) in place of a raw 2.  I notice
> that Attribute.new accepts an Object as a parameter.  I am not sure
> how we pass our RubyFixnum over in that case, but I would still hope
> it was getting unwrapped long/Long/int/Integer.  If that works, then
> let us know.  This may be a JI bug.

Yeah, if it's Object it probably gets passed as Long. If that angers
JMX, we may need to hack around it in the various JMX libraries until JI
is smarter about coercing (and even then, what do we coerce "2" to?
Byte? Short? Integer?).

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Josh M. (Guest)
on 2009-02-18 03:28
(Received via mailing list)
Thanks to everybody for there help.  The java.lang.Integer.new(2) did
the
trick.

Thanks,

Josh

On Wed, Feb 18, 2009 at 12:20 AM, Charles Oliver N. <
This topic is locked and can not be replied to.