jmx 0.3 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/Manifest.txt +0 -2
- data/Rakefile +3 -3
- data/lib/jmx.rb +25 -18
- data/lib/jmx/dynamic_mbean.rb +78 -86
- data/lib/jmx/server.rb +6 -6
- data/lib/jmx/version.rb +1 -1
- data/lib/rmi.rb +3 -3
- data/test/jmx_attribute_test.rb +34 -32
- data/test/jmx_server_test.rb +7 -0
- metadata +60 -59
- data/test/jmx_notification_test.rb +0 -29
- data/test/object_name_test.rb +0 -12
data/.gemtest
ADDED
File without changes
|
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -12,9 +12,9 @@ begin
|
|
12
12
|
require 'hoe'
|
13
13
|
Hoe.new("jmx", JMX::VERSION) do |p|
|
14
14
|
p.rubyforge_name = "jruby-extras"
|
15
|
-
p.url = "http://
|
16
|
-
p.author = "Thomas Enebo"
|
17
|
-
p.email = "enebo@
|
15
|
+
p.url = "http://github.com/enebo/jmxjr"
|
16
|
+
p.author = "Thomas Enebo & Jay McGaffigan"
|
17
|
+
p.email = "tom.enebo@gmail.com"
|
18
18
|
p.summary = "Package for interacting/creating Java Management Extensions"
|
19
19
|
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
20
20
|
p.description = "Install this gem and require 'jmx' to load the library."
|
data/lib/jmx.rb
CHANGED
@@ -4,13 +4,13 @@ require 'rmi'
|
|
4
4
|
require 'jmx/dynamic_mbean'
|
5
5
|
require 'jmx/server'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
java_import java.util.ArrayList
|
8
|
+
java_import javax.management.Attribute
|
9
|
+
java_import javax.management.MBeanInfo
|
10
|
+
java_import javax.management.DynamicMBean
|
11
11
|
|
12
12
|
module JMX
|
13
|
-
|
13
|
+
java_import javax.management.ObjectName
|
14
14
|
class ObjectName
|
15
15
|
def [](key)
|
16
16
|
get_key_property(key.to_s)
|
@@ -130,9 +130,12 @@ module JMX
|
|
130
130
|
@operations ||= @info.operations.inject([]) { |s,op| s << op.name }
|
131
131
|
end
|
132
132
|
|
133
|
-
# Get MBean attribute specified by name
|
133
|
+
# Get MBean attribute specified by name. If it is just a plain attribute then
|
134
|
+
# unwrap the attribute and just return the value.
|
134
135
|
def [](name)
|
135
|
-
@server.getAttribute
|
136
|
+
attribute = @server.getAttribute(@object_name, name.to_s)
|
137
|
+
return attribute.value if attribute.kind_of? javax.management.Attribute
|
138
|
+
attribute
|
136
139
|
end
|
137
140
|
|
138
141
|
# Set MBean attribute specified by name to value
|
@@ -169,8 +172,8 @@ module JMX
|
|
169
172
|
def define_operations
|
170
173
|
@info.operations.each do |op|
|
171
174
|
self.class.__send__(:define_method, op.name) do |*args|
|
172
|
-
jargs = java_args(op.signature, args)
|
173
|
-
@server.invoke @object_name, op.name, jargs,
|
175
|
+
jargs, jtypes = java_args(op.signature, args)
|
176
|
+
@server.invoke @object_name, op.name, jargs, jtypes
|
174
177
|
end
|
175
178
|
end
|
176
179
|
end
|
@@ -180,29 +183,33 @@ module JMX
|
|
180
183
|
def java_args(signature, params)
|
181
184
|
return nil if params.nil?
|
182
185
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
186
|
+
jtypes = []
|
187
|
+
jargs = []
|
188
|
+
params.each_with_index do |param, i|
|
189
|
+
type = signature[i].get_type
|
190
|
+
jtypes << type
|
191
|
+
required_type = JavaClass.for_name(type)
|
192
|
+
|
193
|
+
java_arg = param.to_java(:object)
|
187
194
|
|
188
195
|
if (param.kind_of? Array)
|
189
196
|
java_arg = param.inject(ArrayList.new) {|l, element| l << element }
|
190
197
|
end
|
198
|
+
|
199
|
+
jargs << java_arg
|
191
200
|
|
192
201
|
arg_type = java_arg.java_class
|
193
202
|
|
194
203
|
raise TypeError.new("parameter #{signature[i].name} expected to be #{required_type}, but was #{arg_type}") if !required_type.assignable_from? arg_type
|
195
|
-
|
196
|
-
|
197
|
-
java_arg
|
198
|
-
end.to_java(:object)
|
204
|
+
end
|
205
|
+
[jargs.to_java, jtypes.to_java(:string)]
|
199
206
|
end
|
200
207
|
|
201
208
|
# Convert a collection of java objects to their Java class name equivalents
|
202
209
|
def java_types(params)
|
203
210
|
return nil if params.nil?
|
204
211
|
|
205
|
-
params.map {|e|
|
212
|
+
params.map {|e| e.class.java_class.name }.to_java(:string)
|
206
213
|
end
|
207
214
|
|
208
215
|
def underscore(string)
|
data/lib/jmx/dynamic_mbean.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module JMX
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
java_import javax.management.MBeanParameterInfo
|
3
|
+
java_import javax.management.MBeanOperationInfo
|
4
|
+
java_import javax.management.MBeanAttributeInfo
|
5
|
+
java_import javax.management.MBeanInfo
|
6
6
|
|
7
7
|
# Module that is used to bridge java to ruby and ruby to java types.
|
8
8
|
module JavaTypeAware
|
@@ -15,18 +15,21 @@ module JMX
|
|
15
15
|
:float => ['java.lang.Float', lambda {|param| param.to_f}],
|
16
16
|
:map => ['java.util.Map', lambda {|param| param}],
|
17
17
|
:set => ['java.util.Set', lambda {|param| param}],
|
18
|
-
:string => ['java.lang.String', lambda {|param|
|
18
|
+
:string => ['java.lang.String', lambda {|param| param.to_s}],
|
19
19
|
:void => ['java.lang.Void', lambda {|param| nil}]
|
20
20
|
}
|
21
21
|
|
22
22
|
def to_java_type(type_name)
|
23
23
|
SIMPLE_TYPES[type_name][0] || type_name
|
24
24
|
end
|
25
|
+
|
25
26
|
#TODO: I'm not sure this is strictly needed, but funky things can happen if you
|
26
27
|
# are expecting your attributes (from the ruby side) to be ruby types and they are java types.
|
27
28
|
def to_ruby(type_name)
|
28
29
|
SIMPLE_TYPES[type_name][1] || lambda {|param| param}
|
29
30
|
end
|
31
|
+
|
32
|
+
module_function :to_java_type, :to_ruby
|
30
33
|
end
|
31
34
|
|
32
35
|
class Parameter
|
@@ -93,95 +96,80 @@ end
|
|
93
96
|
# like: user_name= and username. So in your ruby code you can treat the attributes
|
94
97
|
# as "regular" ruby accessors
|
95
98
|
class RubyDynamicMBean
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
99
|
+
java_import javax.management.AttributeList
|
100
|
+
java_import javax.management.MBeanOperationInfo
|
101
|
+
java_import javax.management.MBeanAttributeInfo
|
102
|
+
java_import javax.management.MBeanInfo
|
100
103
|
include JMX::JavaTypeAware
|
101
104
|
|
102
|
-
#NOTE this will not be needed when JRuby-3164 is fixed.
|
103
105
|
def self.inherited(cls)
|
104
|
-
cls.send(:include, DynamicMBean)
|
106
|
+
cls.send(:include, javax.management.DynamicMBean)
|
105
107
|
end
|
106
|
-
|
108
|
+
|
107
109
|
# TODO: preserve any original method_added?
|
108
110
|
# TODO: Error handling here when it all goes wrong?
|
109
111
|
def self.method_added(name) #:nodoc:
|
110
|
-
return if
|
111
|
-
|
112
|
-
operations <<
|
113
|
-
|
112
|
+
return if local_hash[:op].nil?
|
113
|
+
local_hash[:op].name = name
|
114
|
+
operations << local_hash[:op].to_jmx
|
115
|
+
local_hash[:op] = nil
|
114
116
|
end
|
115
117
|
|
116
118
|
def self.attributes #:nodoc:
|
117
|
-
|
119
|
+
local_hash[:attrs] ||= []
|
118
120
|
end
|
119
121
|
|
120
122
|
def self.operations #:nodoc:
|
121
|
-
|
123
|
+
local_hash[:ops] ||= []
|
122
124
|
end
|
123
125
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
def self.rw_attribute(name, type, description)
|
132
|
-
attributes << JMX::Attribute.new(name, type, description, true, true).to_jmx
|
133
|
-
attr_accessor name
|
134
|
-
#create a "java" oriented accessor method
|
135
|
-
define_method("jmx_get_#{name.to_s.downcase}") do
|
136
|
-
begin
|
137
|
-
#attempt conversion
|
138
|
-
java_type = to_java_type(type)
|
139
|
-
value = eval "#{java_type}.new(@#{name.to_s})"
|
140
|
-
rescue
|
141
|
-
#otherwise turn it into a java Object type for now.
|
142
|
-
value = eval "Java.ruby_to_java(@#{name.to_s})"
|
143
|
-
end
|
144
|
-
attribute = javax.management.Attribute.new(name.to_s, value)
|
126
|
+
def self.define_getter(name, type)
|
127
|
+
# FIXME: Our to_java_type needs to do something saner
|
128
|
+
java_type = begin; to_java_type(type); rescue; nil; end
|
129
|
+
value_proc = java_type ? proc { |value| java_type.new value } : proc { |value| Java.ruby_to_java value }
|
130
|
+
|
131
|
+
define_method("jmx_get_#{name.downcase}") do
|
132
|
+
javax.management.Attribute.new name, value_proc.call(instance_variable_get('@' + name))
|
145
133
|
end
|
134
|
+
end
|
146
135
|
|
147
|
-
|
148
|
-
|
149
|
-
|
136
|
+
def self.define_setter(name, type)
|
137
|
+
value_converter = JMX::JavaTypeAware.to_ruby(type)
|
138
|
+
|
139
|
+
define_method("jmx_set_#{name.downcase}") do |value|
|
140
|
+
instance_variable_set '@' + name, value_converter.call(value)
|
150
141
|
end
|
151
142
|
end
|
152
143
|
|
153
|
-
# the <tt>
|
154
|
-
#
|
155
|
-
#
|
156
|
-
|
144
|
+
# the <tt>rw_attribute</tt> method is used to declare a JMX read write attribute. See the +JavaSimpleTypes+
|
145
|
+
# module for more information about acceptable types usage:
|
146
|
+
# rw_attribute :attribute_name, :string, "Description displayed in a JMX console"
|
147
|
+
def self.rw_attribute(name, type, description)
|
148
|
+
name = name.to_s
|
149
|
+
attributes << JMX::Attribute.new(name, type, description, true, true).to_jmx
|
150
|
+
attr_accessor name
|
151
|
+
define_getter name, type
|
152
|
+
define_setter name, type
|
153
|
+
end
|
154
|
+
|
155
|
+
# the <tt>r_attribute</tt> method is used to declare a JMX read only attribute. See the +JavaSimpleTypes+
|
156
|
+
# module for more information about acceptable types usage:
|
157
|
+
# r_attribute :attribute_name, :string, "Description displayed in a JMX console"
|
157
158
|
def self.r_attribute(name, type, description)
|
159
|
+
name = name.to_s
|
158
160
|
attributes << JMX::Attribute.new(name, type, description, true, false).to_jmx
|
159
161
|
attr_reader name
|
160
|
-
|
161
|
-
define_method("jmx_get_#{name.to_s.downcase}") do
|
162
|
-
begin
|
163
|
-
#attempt conversion
|
164
|
-
java_type = to_java_type(type)
|
165
|
-
value = eval "#{java_type}.new(@#{name.to_s})"
|
166
|
-
rescue
|
167
|
-
#otherwise turn it into a java Object type for now.
|
168
|
-
value = eval "Java.ruby_to_java(@#{name.to_s})"
|
169
|
-
end
|
170
|
-
attribute = javax.management.Attribute.new(name.to_s, value)
|
171
|
-
end
|
162
|
+
define_getter name, type
|
172
163
|
end
|
173
164
|
|
174
|
-
# the <tt>w_attribute</tt> method is used to declare a JMX write only attribute.
|
175
|
-
#
|
176
|
-
#
|
177
|
-
# w_attribute :attribute_name, :string, "Description displayed in a JMX console"
|
165
|
+
# the <tt>w_attribute</tt> method is used to declare a JMX write only attribute. See the +JavaSimpleTypes+
|
166
|
+
# module for more information about acceptable types usage:
|
167
|
+
# w_attribute :attribute_name, :string, "Description displayed in a JMX console"
|
178
168
|
def self.w_attribute(name, type, description)
|
169
|
+
name = name.to_s
|
179
170
|
attributes << JMX::Attribute.new(name, type, description, false, true).to_jmx
|
180
171
|
attr_writer name
|
181
|
-
|
182
|
-
blck = to_ruby(type)
|
183
|
-
eval "@#{name.to_s} = #{blck.call(value)}"
|
184
|
-
end
|
172
|
+
define_setter name, type
|
185
173
|
end
|
186
174
|
|
187
175
|
# Use the operation method to declare the start of an operation
|
@@ -193,9 +181,8 @@ class RubyDynamicMBean
|
|
193
181
|
# Last operation wins if more than one
|
194
182
|
#++
|
195
183
|
def self.operation(description)
|
196
|
-
|
197
184
|
# Wait to error check until method_added so we can know method name
|
198
|
-
|
185
|
+
local_hash[:op] = JMX::Operation.new description
|
199
186
|
end
|
200
187
|
|
201
188
|
# Used to declare a parameter (you can declare more than one in succession) that
|
@@ -205,7 +192,7 @@ class RubyDynamicMBean
|
|
205
192
|
# def start
|
206
193
|
# end
|
207
194
|
def self.parameter(type, name=nil, description=nil)
|
208
|
-
|
195
|
+
local_hash[:op].parameters << JMX::Parameter.new(type, name, description)
|
209
196
|
end
|
210
197
|
|
211
198
|
# Used to declare the return type of the operation
|
@@ -215,44 +202,49 @@ class RubyDynamicMBean
|
|
215
202
|
# def set_name
|
216
203
|
# end
|
217
204
|
def self.returns(type)
|
218
|
-
|
205
|
+
local_hash[:op].return_type = type
|
219
206
|
end
|
220
207
|
|
221
|
-
#
|
222
|
-
|
208
|
+
# Thread local storage for the derived bean
|
209
|
+
def self.local_hash
|
210
|
+
Thread.current[self.name] ||= {}
|
211
|
+
end
|
212
|
+
|
213
|
+
# when creating a dynamic MBean we need to provide it with a name and a description.
|
223
214
|
def initialize(name, description)
|
224
|
-
operations = self.class.operations.to_java
|
225
|
-
attributes = self.class.attributes.to_java
|
215
|
+
operations = self.class.operations.to_java MBeanOperationInfo
|
216
|
+
attributes = self.class.attributes.to_java MBeanAttributeInfo
|
226
217
|
@info = MBeanInfo.new name, description, attributes, nil, operations, nil
|
227
218
|
end
|
228
219
|
|
229
|
-
# Retrieve the value of the requested attribute (where attribute is a
|
230
|
-
# javax.management.Attribute class)
|
220
|
+
# Retrieve the value of the requested attribute (where attribute is a javax.management.Attribute class)
|
231
221
|
def getAttribute(attribute)
|
232
|
-
|
222
|
+
__send__("jmx_get_" + attribute.downcase)
|
233
223
|
end
|
234
224
|
|
235
225
|
def getAttributes(attributes)
|
236
|
-
attrs
|
237
|
-
attributes.each { |attribute| attrs.add(getAttribute(attribute)) }
|
238
|
-
attrs
|
226
|
+
attributes.inject(AttributeList.new) { |attrs, attribute| attrs.add(getAttribute(attribute)); attrs }
|
239
227
|
end
|
240
228
|
|
241
|
-
def getMBeanInfo
|
229
|
+
def getMBeanInfo
|
230
|
+
@info
|
231
|
+
end
|
242
232
|
|
243
233
|
def invoke(actionName, params=nil, signature=nil)
|
244
|
-
|
234
|
+
__send__(actionName, *params)
|
245
235
|
end
|
246
236
|
|
247
237
|
def setAttribute(attribute)
|
248
|
-
|
238
|
+
__send__("jmx_set_#{attribute.name.downcase}", attribute.value)
|
249
239
|
end
|
250
240
|
|
251
241
|
def setAttributes(attributes)
|
252
242
|
attributes.each { |attribute| setAttribute attribute}
|
253
243
|
end
|
254
244
|
|
255
|
-
def
|
256
|
-
|
257
|
-
|
245
|
+
def toString
|
246
|
+
"#@info.class_name: #@info.description"
|
247
|
+
end
|
248
|
+
alias_method :to_s, :toString
|
249
|
+
alias_method :inspect, :toString
|
258
250
|
end
|
data/lib/jmx/server.rb
CHANGED
@@ -7,10 +7,10 @@ module JMX
|
|
7
7
|
# Represents both MBeanServer and MBeanServerConnection
|
8
8
|
#++
|
9
9
|
class MBeanServer
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
java_import javax.management.Attribute
|
11
|
+
java_import javax.management.MBeanServerFactory
|
12
|
+
java_import javax.management.remote.JMXConnectorFactory
|
13
|
+
java_import javax.management.remote.JMXServiceURL
|
14
14
|
|
15
15
|
attr_accessor :server
|
16
16
|
@@classes = {}
|
@@ -101,8 +101,8 @@ module JMX
|
|
101
101
|
end
|
102
102
|
|
103
103
|
class MBeanServerConnector
|
104
|
-
|
105
|
-
|
104
|
+
java_import javax.management.remote.JMXServiceURL
|
105
|
+
java_import javax.management.remote.JMXConnectorServerFactory
|
106
106
|
|
107
107
|
def initialize(location, server)
|
108
108
|
@url = JMXServiceURL.new location
|
data/lib/jmx/version.rb
CHANGED
data/lib/rmi.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
include Java
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
java_import java.rmi.registry.LocateRegistry
|
4
|
+
java_import java.rmi.registry.Registry
|
5
|
+
java_import java.rmi.server.UnicastRemoteObject
|
6
6
|
|
7
7
|
class RMIRegistry
|
8
8
|
def initialize(port = Registry::REGISTRY_PORT)
|
data/test/jmx_attribute_test.rb
CHANGED
@@ -3,20 +3,22 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
|
3
3
|
require 'test/unit'
|
4
4
|
require 'jmx'
|
5
5
|
|
6
|
+
# These tests are for verifying that at a Ruby-level (on server-side) it is still possible
|
7
|
+
# to interact with dynamic mbeans as you expect. *_attributes are backed by ordinary
|
8
|
+
# Ruby instance variables of the same name.
|
9
|
+
|
6
10
|
class MyAttributeDynamicBean < RubyDynamicMBean
|
7
|
-
rw_attribute :
|
8
|
-
r_attribute :
|
9
|
-
w_attribute :
|
11
|
+
rw_attribute :name, :string, "My sample attribute"
|
12
|
+
r_attribute :number_read_only, :int, "My sample integer based attribute that is read only"
|
13
|
+
w_attribute :number_write_only, :int, "My sample integer based attribute that is write only"
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def set_number1(val)
|
15
|
-
@number1 = val
|
15
|
+
# Give us a way to change the attribute for testing
|
16
|
+
def set_number_read_only(value)
|
17
|
+
@number_read_only = value
|
16
18
|
end
|
17
19
|
|
18
|
-
def
|
19
|
-
@
|
20
|
+
def fetch_number_write_only
|
21
|
+
@number_write_only
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -29,48 +31,48 @@ class JMXAttributeTest < Test::Unit::TestCase
|
|
29
31
|
|
30
32
|
#make sure we didn't break anything from a ruby perspective
|
31
33
|
def test_can_create_bean_and_access_accessor_type_methods
|
32
|
-
@madb.
|
33
|
-
assert_nil(@madb.
|
34
|
-
@madb.
|
35
|
-
assert_equal("Name", @madb.
|
36
|
-
assert_equal(4, @madb.
|
37
|
-
@madb.
|
38
|
-
assert_equal(4, @madb.
|
39
|
-
assert_raise(NoMethodError) { @madb.
|
34
|
+
@madb.set_number_read_only 4
|
35
|
+
assert_nil(@madb.name)
|
36
|
+
@madb.name = "Name"
|
37
|
+
assert_equal("Name", @madb.name)
|
38
|
+
assert_equal(4, @madb.number_read_only)
|
39
|
+
@madb.number_write_only = 4
|
40
|
+
assert_equal(4, @madb.fetch_number_write_only)
|
41
|
+
assert_raise(NoMethodError) { @madb.number_write_only }
|
40
42
|
end
|
41
43
|
|
42
44
|
def test_get_attributes_via_dynamicmbeaninterface
|
43
|
-
@madb.
|
44
|
-
@madb.
|
45
|
+
@madb.set_number_read_only 4
|
46
|
+
@madb.name = "Name"
|
45
47
|
|
46
|
-
assert_equal(@madb.
|
47
|
-
assert_equal(@madb.
|
48
|
-
atts = ["
|
48
|
+
assert_equal(@madb.name, @madb.getAttribute("name").get_value.to_s)
|
49
|
+
assert_equal(@madb.number_read_only, @madb.getAttribute("number_read_only").get_value)
|
50
|
+
atts = ["name", "number_read_only"]
|
49
51
|
retrieved = @madb.getAttributes(atts)
|
50
52
|
assert_equal(2, retrieved.length)
|
51
53
|
#TODO: assertion comparing the types in teh array to java types
|
52
54
|
end
|
53
55
|
|
54
56
|
def test_set_attributes_via_dynamicbeaninterface
|
55
|
-
@madb.
|
57
|
+
@madb.name = "blue"
|
56
58
|
red = java.lang.String.new("red")
|
57
|
-
attribute = javax.management.Attribute.new("
|
59
|
+
attribute = javax.management.Attribute.new("name", red)
|
58
60
|
@madb.setAttribute(attribute)
|
59
61
|
|
60
|
-
assert_equal("String", @madb.
|
61
|
-
assert_equal("red", @madb.
|
62
|
+
assert_equal("String", @madb.name.class.to_s )
|
63
|
+
assert_equal("red", @madb.name)
|
62
64
|
end
|
63
65
|
|
64
66
|
def test_set_multiple_attributes_via_dynamicbeaninterface
|
65
|
-
@madb.
|
67
|
+
@madb.name = "blue"
|
66
68
|
three = java.lang.Integer.new(3)
|
67
69
|
red = java.lang.String.new("red")
|
68
|
-
attribute1 = javax.management.Attribute.new("
|
69
|
-
attribute2 = javax.management.Attribute.new("
|
70
|
+
attribute1 = javax.management.Attribute.new("name", red)
|
71
|
+
attribute2 = javax.management.Attribute.new("number_write_only", three)
|
70
72
|
|
71
73
|
@madb.setAttributes([attribute1, attribute2])
|
72
|
-
assert_equal("red", @madb.
|
73
|
-
assert_equal(3, @madb.
|
74
|
+
assert_equal("red", @madb.name)
|
75
|
+
assert_equal(3, @madb.fetch_number_write_only)
|
74
76
|
end
|
75
77
|
|
76
78
|
end
|
data/test/jmx_server_test.rb
CHANGED
@@ -10,6 +10,8 @@ require 'rmi'
|
|
10
10
|
require 'jmx'
|
11
11
|
|
12
12
|
class MyDynamicMBean < RubyDynamicMBean
|
13
|
+
rw_attribute :name, :string, "My sample attribute"
|
14
|
+
|
13
15
|
operation "Doubles a value"
|
14
16
|
parameter :int, "a", "Value to double"
|
15
17
|
returns :int
|
@@ -67,7 +69,12 @@ class JMXServerTest < Test::Unit::TestCase
|
|
67
69
|
assert_raise(TypeError) { puts bean.double("HEH") }
|
68
70
|
assert_equal("hehheh", bean.string_double("heh"))
|
69
71
|
assert_equal("123", bean.concat([1,2,3]))
|
72
|
+
|
73
|
+
assert_nil(bean.name)
|
74
|
+
bean.name = "Name"
|
75
|
+
assert_equal("Name", bean.name)
|
70
76
|
end
|
77
|
+
|
71
78
|
def test_ruby_mbean_twice
|
72
79
|
dyna = MyDynamicMBean.new("domain.MySuperBean", "Heh")
|
73
80
|
domain = @server.default_domain
|
metadata
CHANGED
@@ -1,71 +1,72 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
3
|
-
requirements:
|
4
|
-
- - '>='
|
5
|
-
- !ruby/object:Gem::Version
|
6
|
-
version: "0"
|
7
|
-
version:
|
8
|
-
email: enebo@acm.org
|
9
|
-
cert_chain: []
|
10
|
-
|
11
|
-
summary: Package for interacting/creating Java Management Extensions
|
12
|
-
post_install_message:
|
13
|
-
extra_rdoc_files:
|
14
|
-
- Manifest.txt
|
15
|
-
- README.txt
|
16
|
-
- LICENSE.txt
|
17
|
-
homepage: http://jruby-extras.rubyforge.org/jmx
|
18
|
-
signing_key:
|
19
2
|
name: jmx
|
20
|
-
|
21
|
-
|
22
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "0.5"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas Enebo & Jay McGaffigan
|
23
9
|
autorequire:
|
24
|
-
|
25
|
-
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
26
12
|
|
27
|
-
|
28
|
-
specification_version: 2
|
13
|
+
date: 2011-03-18 00:00:00 -05:00
|
29
14
|
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Install this gem and require 'jmx' to load the library.
|
18
|
+
email: tom.enebo@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- Manifest.txt
|
25
|
+
- README.txt
|
26
|
+
- LICENSE.txt
|
30
27
|
files:
|
31
|
-
- Manifest.txt
|
32
|
-
- Rakefile
|
33
|
-
- README.txt
|
34
|
-
- LICENSE.txt
|
35
|
-
- lib/jmx
|
36
|
-
- lib/
|
37
|
-
- lib/
|
38
|
-
- lib/jmx/
|
39
|
-
- lib/jmx/
|
40
|
-
-
|
41
|
-
-
|
42
|
-
- test/
|
43
|
-
- test/
|
44
|
-
-
|
45
|
-
|
46
|
-
|
28
|
+
- Manifest.txt
|
29
|
+
- Rakefile
|
30
|
+
- README.txt
|
31
|
+
- LICENSE.txt
|
32
|
+
- lib/jmx.rb
|
33
|
+
- lib/rmi.rb
|
34
|
+
- lib/jmx/dynamic_mbean.rb
|
35
|
+
- lib/jmx/server.rb
|
36
|
+
- lib/jmx/version.rb
|
37
|
+
- samples/memory.rb
|
38
|
+
- test/jmx_attribute_test.rb
|
39
|
+
- test/jmx_client_test.rb
|
40
|
+
- test/jmx_server_test.rb
|
41
|
+
- .gemtest
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/enebo/jmxjr
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --main
|
49
|
+
- README.txt
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
47
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
48
60
|
requirements:
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
version:
|
53
|
-
extensions: []
|
54
|
-
|
55
|
-
rubygems_version: 1.3.1
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
56
64
|
requirements: []
|
57
65
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
66
|
+
rubyforge_project: jruby-extras
|
67
|
+
rubygems_version: 1.5.1
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Package for interacting/creating Java Management Extensions
|
62
71
|
test_files: []
|
63
72
|
|
64
|
-
version: !ruby/object:Gem::Version
|
65
|
-
version: "0.3"
|
66
|
-
require_paths:
|
67
|
-
- lib
|
68
|
-
dependencies: []
|
69
|
-
|
70
|
-
bindir: bin
|
71
|
-
has_rdoc: true
|
@@ -1,29 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'rmi'
|
5
|
-
require 'jmx'
|
6
|
-
|
7
|
-
class MyAttributeDynamicBean < RubyDynamicMBean
|
8
|
-
rw_attribute :name1, :string, "My sample attribute"
|
9
|
-
r_attribute :number1, :int, "My sample integer based attribute that is read only"
|
10
|
-
w_attribute :number2, :int, "My sample integer based attribute that is write only"
|
11
|
-
|
12
|
-
def intialize(type, text)
|
13
|
-
super(type,text)
|
14
|
-
end
|
15
|
-
def set_number1(val)
|
16
|
-
@number1 = val
|
17
|
-
end
|
18
|
-
|
19
|
-
def fetch_number2
|
20
|
-
@number2
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
#interface NotificationEmitter
|
27
|
-
#v addNotificationListener listener, filter, handback
|
28
|
-
#MBEanNotificationInfo getNotificationInfo
|
29
|
-
#v removeNotificationListener listener, filter, handback
|
data/test/object_name_test.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
-
require "test/unit"
|
3
|
-
|
4
|
-
require "jmx"
|
5
|
-
|
6
|
-
class TestObjectName < Test::Unit::TestCase
|
7
|
-
def test_create_object_name
|
8
|
-
MObjectName.ancestors.each {|method| p method}
|
9
|
-
x = MObjectName.new "foo:d=bar"
|
10
|
-
assert_not_nil(x)
|
11
|
-
end
|
12
|
-
end
|