Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JMX::MBeans.parent_for unreliable in Jruby 9000 #14

Closed
savelandr opened this issue Nov 24, 2015 · 5 comments
Closed

JMX::MBeans.parent_for unreliable in Jruby 9000 #14

savelandr opened this issue Nov 24, 2015 · 5 comments

Comments

@savelandr
Copy link

test.rb:

require 'jmx'

client = JMX.connect(:host => 'localhost', :port => 9999)
puts client["JMImplementation:type=MBeanServerDelegate"].attributes

Running in JRuby 1.7:

$ rbenv global jruby-1.7.14 
$ ruby -J-Dcom.sun.management.jmxremote -J-Dcom.sun.management.jmxremote.port=9999 -J-Dcom.sun.management.jmxremote.authenticate=false -J-Dcom.sun.management.jmxremote.ssl=false test.rb
MBeanServerId
SpecificationName
SpecificationVersion
SpecificationVendor
ImplementationName
ImplementationVersion
ImplementationVendor

Running in JRuby 9000:

$ rbenv global jruby-9.0.3.0 
$ ruby -J-Dcom.sun.management.jmxremote -J-Dcom.sun.management.jmxremote.port=9999 -J-Dcom.sun.management.jmxremote.authenticate=false -J-Dcom.sun.management.jmxremote.ssl=false test.rb
ArgumentError: Java package `javax' does not have a method `const_set'
       method_missing at uri:classloader:/jruby/java/java_package_module_template.rb:13
  block in parent_for at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbeans.rb:20
                 each at org/jruby/RubyArray.java:1560
               inject at org/jruby/RubyEnumerable.java:895
           parent_for at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbeans.rb:12
             generate at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbean_proxy.rb:30
                   [] at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/server.rb:46
                <top> at test.rb:4

I also have similar problems when the ObjectName's class name is "com.x.y.z". And I can easily force the issue by just calling Java::Com or Java::Sun before accessing an ObjectName whose class name path is sun.x.y or com.x.y.

I.e.

require 'jmx'

Java::Sun
client = JMX.connect(:host => 'localhost', :port => 9999)
puts client["java.lang:type=Memory"].attributes

results in

$ rbenv global jruby-9.0.3.0 
$ ruby -J-Dcom.sun.management.jmxremote -J-Dcom.sun.management.jmxremote.port=9999 -J-Dcom.sun.management.jmxremote.authenticate=false -J-Dcom.sun.management.jmxremote.ssl=false test.rb
ArgumentError: Java package `sun' does not have a method `const_set'
       method_missing at uri:classloader:/jruby/java/java_package_module_template.rb:13
  block in parent_for at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbeans.rb:20
                 each at org/jruby/RubyArray.java:1560
               inject at org/jruby/RubyEnumerable.java:895
           parent_for at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbeans.rb:12
             generate at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbean_proxy.rb:30
                   [] at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/server.rb:46
                <top> at test.rb:5

but this doesn't force the problem in JRuby 1.7, it still prints the attributes for that object name.

@savelandr
Copy link
Author

Actually, a simpler demonstration that doesn't require launching the JVM with JMX available:

test.rb:

require 'jmx'

Java::Sun
puts JMX::MBeans.parent_for "sun.something.SomethingElse"

JRuby 1.7:

$ rbenv global jruby-1.7.14 
$ ruby test.rb 
JMX::MBeans::Sun::Something
SomethingElse

JRuby 9000:

$ rbenv global jruby-9.0.3.0 
$ ruby test.rb 
ArgumentError: Java package `sun' does not have a method `const_set'
       method_missing at uri:classloader:/jruby/java/java_package_module_template.rb:13
  block in parent_for at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbeans.rb:20
                 each at org/jruby/RubyArray.java:1560
               inject at org/jruby/RubyEnumerable.java:895
           parent_for at /home/saveland/.rbenv/versions/jruby-9.0.3.0/lib/ruby/gems/shared/gems/jmx-0.9/lib/jmx/mbeans.rb:12
                <top> at test.rb:4

@tobias
Copy link
Contributor

tobias commented Nov 17, 2016

I'm not sure if it's the same issue, but #16 may fix this as well.

@enebo
Copy link
Owner

enebo commented Nov 18, 2016

@tobias @savelandr sure seems like the same issue you had.

@savelandr
Copy link
Author

@tobias @enebo

Yup, this does fix it. I tried the simple example as well as running Ruby with JMX enabled so the test connects to itself. Thanks!

@enebo
Copy link
Owner

enebo commented Nov 18, 2016

@savelandr thanks for checking!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants