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

setAttributes is internally using invoke on MBean #10

Open
ksekhar opened this issue Jan 10, 2014 · 5 comments
Open

setAttributes is internally using invoke on MBean #10

ksekhar opened this issue Jan 10, 2014 · 5 comments

Comments

@ksekhar
Copy link

ksekhar commented Jan 10, 2014

It seems the DynamicMbean class's method setAttributes is calling the invoke method on the MBean and not the setAttributes method itself.

The problem I am facing is that the server code I work with is written in such a way that only the attributes set through the setAttributes method are persisted in Database,
Is there a way I can bypass this method and directly use the Mbean's setAttributes method ?

@enebo
Copy link
Owner

enebo commented Jan 27, 2014

@ksekhar I am sorry about the tardiness of this response. It got lost in a sea of tabs in my browser.

I think I need a bit more detail on your problem. I think you are interacting with an already written MBean and it only persists if attributes are set through setAttributes right? Does it persist if they are set through setAttribute?

The second part of what I think you are asking confuses me a little. The attributes seem to be using []= which does call setAttribute. I half wonder if perhaps you might have an operand and an attribute with the same name? Could their be an name collision?

@ksekhar
Copy link
Author

ksekhar commented Jan 28, 2014

@enebo Thanks for the reply. I was always resigned about replies from code owners. You proved me wrong.

I tried using setAttribute, but the results are the same. It would update in JVM but it won't in DB.
I am not overriding any operands in my code, unless jruby or rails is inserting one behind the scenes. And I don't see any name collision.

I even checked out Twiddle (https://community.jboss.org/wiki/Twiddle) source code and it does exactly what I do I call the setAttributes method on the RMIServerConnection object that JMXConnectionFactory returns.

heres my code if that helps (Pardon if its horrible)

#@conn ||= JMX.connect :host => @hostname,:port => @port, :user => FreBean.user_pass1[0], :password => FreBean.user_pass1[1]

 def update(name, data)
    attributes = @conn[name].attributes #returns MBeanInfo object (I modified the method  in gem to return type along with name)
    o = ObjectName.new(name)
    list = AttributeList.new
    data.each do |mbean_name,att_val_hash|
      att_val_hash.each do |att, val|
          val = javax.management.ObjectName.new(val) if attributes.find{|a| a.first.downcase ==  att.camelcase.downcase}[1] == "javax.management.ObjectName" unless val.blank?
        cast_val = val.to_java(attributes.find{|a| a.first.downcase ==  att.camelcase.downcase}[1]) 
        a = Attribute.new(attributes.find{|a| a.first.downcase ==  att.camelcase.downcase}.first,cast_val)
        list.add(a)
      end
    end
    @conn.server.setAttributes(o,list)
    return @conn[name]
  end

@enebo
Copy link
Owner

enebo commented Jan 28, 2014

I don't know if this will help there are really only two changes I made:

  1. list = []
  2. @conn[name].setAttributes(list)
#@conn ||= JMX.connect :host => @hostname,:port => @port, :user => FreBean.user_pass1[0], :password => FreBean.user_pass1[1]

def update(name, data)
  attributes = @conn[name].attributes #returns MBeanInfo object (I modified the method  in gem to return type along with name)
  list = []
  data.each do |mbean_name,att_val_hash|
    att_val_hash.each do |att, val|
      n, type = attributes.find{|a| a.first.downcase == att.camelcase.downcase }
      val = javax.management.ObjectName.new(val) if type == "javax.management.ObjectName" unless val.blank?

      list.add(Attribute.new(n, val.to_java(type)))
    end
  end
  @conn[name].setAttributes(list)
end

If this does not work I am wondering if there is something Open Sourced as a MBean which I can reproduce this issue. Looking informally at the library I feel like it should really be calling setAttributes.

@enebo
Copy link
Owner

enebo commented Jan 28, 2014

It is possible my simplification of your find is wrong too but it was difficult to tell. Still I think you should be able to to something similar.

@ksekhar
Copy link
Author

ksekhar commented Jan 31, 2014

I tried the first and got undefined method setAttributes
Thank You for trying to solve my problem.

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

2 participants