Class: JMX::MBeanProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/jmx.rb

Overview

Create a Ruby proxy based on the MBean represented by the object_name

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, object_name) ⇒ MBeanProxy

Returns a new instance of MBeanProxy.



117
118
119
120
121
122
123
# File 'lib/jmx.rb', line 117

def initialize(server, object_name)
  @server, @object_name = server, object_name
  @info = @server.getMBeanInfo(@object_name)

  define_attributes
  define_operations
end

Class Method Details

.generate(server, object_name) ⇒ Object

Generate a friendly Ruby proxy for the MBean represented by object_name



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/jmx.rb', line 104

def self.generate(server, object_name)
  parent, class_name = MBeans.parent_for object_name.info(server).class_name

  if parent.const_defined? class_name
    proxy = parent.const_get(class_name)
  else
    proxy = Class.new MBeanProxy
    parent.const_set class_name, proxy
  end

  proxy.new(server, object_name)
end

Instance Method Details

#[](name) ⇒ Object

Get MBean attribute specified by name. If it is just a plain attribute then unwrap the attribute and just return the value.



135
136
137
138
139
# File 'lib/jmx.rb', line 135

def [](name)
  attribute = @server.getAttribute(@object_name, name.to_s)
  return attribute.value if attribute.kind_of? javax.management.Attribute
  attribute
end

#[]=(name, value) ⇒ Object

Set MBean attribute specified by name to value



142
143
144
# File 'lib/jmx.rb', line 142

def []=(name, value) 
  @server.setAttribute @object_name, javax.management.Attribute.new(name.to_s, value)
end

#add_notification_listener(filter = nil, handback = nil, &listener) ⇒ Object



146
147
148
# File 'lib/jmx.rb', line 146

def add_notification_listener(filter=nil, handback=nil, &listener)
  @server.addNotificationListener @object_name, listener, filter, handback
end

#attributesObject



125
126
127
# File 'lib/jmx.rb', line 125

def attributes
  @attributes ||= @info.attributes.inject([]) { |s,attr| s << attr.name }
end

#operationsObject



129
130
131
# File 'lib/jmx.rb', line 129

def operations
  @operations ||= @info.operations.inject([]) { |s,op| s << op.name }
end

#remove_notification_listener(listener) ⇒ Object



150
151
152
# File 'lib/jmx.rb', line 150

def remove_notification_listener(listener)
  @server.removeNotificationListener @object_name, listener
end