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.



119
120
121
122
123
124
125
# File 'lib/jmx.rb', line 119

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



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

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.



137
138
139
140
141
# File 'lib/jmx.rb', line 137

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



144
145
146
# File 'lib/jmx.rb', line 144

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



148
149
150
# File 'lib/jmx.rb', line 148

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

#attributesObject



127
128
129
# File 'lib/jmx.rb', line 127

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

#operationsObject



131
132
133
# File 'lib/jmx.rb', line 131

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

#remove_notification_listener(listener) ⇒ Object



152
153
154
# File 'lib/jmx.rb', line 152

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