jmx4r 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/examples/ruby_mbean.rb +41 -0
- data/lib/dynamic_mbean.rb +275 -0
- data/lib/jconsole.rb +1 -1
- data/lib/jmx4r.rb +23 -16
- data/test/tc_attributes.rb +4 -3
- data/test/tc_composite_data.rb +3 -3
- data/test/tc_dynamic_mbean.rb +79 -0
- data/test/ts_all.rb +2 -0
- metadata +46 -40
data/Rakefile
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
|
3
|
+
# Run with:
|
4
|
+
# jruby -J-Dcom.sun.management.jmxremote -Ilib examples/ruby_mbean.rb
|
5
|
+
#
|
6
|
+
# and open jconsole to manage the MBean
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'jmx4r'
|
10
|
+
|
11
|
+
import java.lang.management.ManagementFactory
|
12
|
+
import javax.management.ObjectName
|
13
|
+
|
14
|
+
class ExampleMBean < DynamicMBean
|
15
|
+
rw_attribute :string_attr, :string, "a String attribute"
|
16
|
+
rw_attribute :int_attr, :int, "a Integer attribute"
|
17
|
+
rw_attribute :long_attr, :long, "a Long attribute"
|
18
|
+
rw_attribute :float_attr, :float, "a Float attribute"
|
19
|
+
rw_attribute :double_attr, :double, "a Double attribute"
|
20
|
+
rw_attribute :boolean_attr, :boolean, "a Boolean attribute"
|
21
|
+
|
22
|
+
operation "reverse the string passed in parameter"
|
23
|
+
parameter :string, "arg", "a String to reverse"
|
24
|
+
returns :string
|
25
|
+
def reverse(arg)
|
26
|
+
arg.reverse
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
mbean = ExampleMBean.new
|
31
|
+
object_name = ObjectName.new("jmx4r:name=ExampleMBean")
|
32
|
+
|
33
|
+
mbeanServer = ManagementFactory.platform_mbean_server
|
34
|
+
mbeanServer.register_mbean mbean, object_name
|
35
|
+
puts "Open jconsole to manage the MBean #{object_name}"
|
36
|
+
puts "When you have finished, type <ENTER> to exit"
|
37
|
+
gets
|
38
|
+
|
39
|
+
mbeanServer.unregister_mbean object_name
|
40
|
+
puts "unregistered #{object_name}"
|
41
|
+
|
@@ -0,0 +1,275 @@
|
|
1
|
+
# Copyright (c) 2008 Thomas E Enebo <enebo@acm.org>
|
2
|
+
#--
|
3
|
+
# taken from the 'jmx' gems in jruby-extras
|
4
|
+
|
5
|
+
module JMX
|
6
|
+
import javax.management.MBeanParameterInfo
|
7
|
+
import javax.management.MBeanOperationInfo
|
8
|
+
import javax.management.MBeanAttributeInfo
|
9
|
+
import javax.management.MBeanInfo
|
10
|
+
|
11
|
+
# Module that is used to bridge java to ruby and ruby to java types.
|
12
|
+
module JavaTypeAware
|
13
|
+
# Current list of types we understand If it's not in this list we are
|
14
|
+
# assuming that we are going to convert to a java.object
|
15
|
+
SIMPLE_TYPES = {
|
16
|
+
:boolean => ['java.lang.Boolean', lambda {|param| param}],
|
17
|
+
:byte => ['java.lang.Byte', lambda {|param| param.to_i}],
|
18
|
+
:int => ['java.lang.Integer', lambda {|param| param.to_i}],
|
19
|
+
:long => ['java.lang.Long', lambda {|param| param.to_i}],
|
20
|
+
:float => ['java.lang.Float', lambda {|param| param.to_f}],
|
21
|
+
:double => ['java.lang.Double', lambda {|param| param.to_f}],
|
22
|
+
:list => ['java.util.ArrayList', lambda {|param| param.to_a}],
|
23
|
+
:map => ['java.util.HashMap', lambda {|param| param}],
|
24
|
+
:set => ['java.util.HashSet', lambda {|param| param}],
|
25
|
+
:string => ['java.lang.String', lambda {|param| param.to_s}],
|
26
|
+
:void => ['java.lang.Void', lambda {|param| nil}]
|
27
|
+
}
|
28
|
+
|
29
|
+
def to_java_type(type_name)
|
30
|
+
SIMPLE_TYPES[type_name][0] || type_name
|
31
|
+
end
|
32
|
+
#TODO: I'm not sure this is strictly needed, but funky things can happen if you
|
33
|
+
# are expecting your attributes (from the ruby side) to be ruby types and they are java types.
|
34
|
+
def to_ruby(type_name)
|
35
|
+
SIMPLE_TYPES[type_name][1] || lambda {|param| param}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Parameter
|
40
|
+
include JavaTypeAware
|
41
|
+
|
42
|
+
def initialize(type, name, description)
|
43
|
+
@type, @name, @description = type, name, description
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_jmx
|
47
|
+
MBeanParameterInfo.new @name.to_s, to_java_type(@type), @description
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Operation < Struct.new(:description, :parameters, :return_type, :name, :impact)
|
52
|
+
include JavaTypeAware
|
53
|
+
|
54
|
+
def initialize(description)
|
55
|
+
super
|
56
|
+
self.parameters, self.impact, self.description = [], MBeanOperationInfo::UNKNOWN, description
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_jmx
|
60
|
+
java_parameters = parameters.map { |parameter| parameter.to_jmx }
|
61
|
+
MBeanOperationInfo.new name.to_s, description, java_parameters.to_java(javax.management.MBeanParameterInfo), to_java_type(return_type), impact
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Attribute < Struct.new(:name, :type, :description, :is_reader, :is_writer, :is_iser)
|
66
|
+
include JavaTypeAware
|
67
|
+
|
68
|
+
def initialize(name, type, description, is_rdr, is_wrtr)
|
69
|
+
super
|
70
|
+
self.description, self.type, self.name = description, type, name
|
71
|
+
self.is_reader,self.is_writer, self.is_iser = is_rdr, is_wrtr, false
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_jmx
|
75
|
+
MBeanAttributeInfo.new(name.to_s, to_java_type(type), description, is_reader, is_writer, is_iser)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Creators of Ruby based MBeans must inherit this
|
80
|
+
# class (<tt>DynamicMBean</tt>) in their own bean classes and then register them with a JMX mbean server.
|
81
|
+
# Here is an example:
|
82
|
+
# class MyMBean < DynamicMBean
|
83
|
+
# rw_attribute :status, :string, "Status information for this process"
|
84
|
+
#
|
85
|
+
# operation "Shutdown this process"
|
86
|
+
# parameter :string, "user_name", "Name of user requesting shutdown"
|
87
|
+
# returns :string
|
88
|
+
# def shutdown(user_name)
|
89
|
+
# "shutdown requests more time"
|
90
|
+
# end
|
91
|
+
# end
|
92
|
+
# Once you have defined your bean class you can start declaring attributes and operations.
|
93
|
+
# Attributes come in three flavors: read, write, and read write. Simmilar to the <tt>attr*</tt>
|
94
|
+
# helpers, there are helpers that are used to create management attributes. Use +r_attribute+,
|
95
|
+
# +w_attribute+, and +rw_attribute+ to declare attributes, and the +operation+, +returns+,
|
96
|
+
# and +parameter+ helpers to define a management operation.
|
97
|
+
# Creating attributes with the *_attribute convention ALSO creates ruby accessors
|
98
|
+
# (it invokes the attr_accessor/attr_reader/attr_writer ruby helpers) to create ruby methods
|
99
|
+
# like: user_name= and username. So in your ruby code you can treat the attributes
|
100
|
+
# as "regular" ruby accessors
|
101
|
+
class DynamicMBean
|
102
|
+
import javax.management.MBeanOperationInfo
|
103
|
+
import javax.management.MBeanAttributeInfo
|
104
|
+
import javax.management.DynamicMBean
|
105
|
+
import javax.management.MBeanInfo
|
106
|
+
include JMX::JavaTypeAware
|
107
|
+
|
108
|
+
#NOTE this will not be needed when JRuby-3164 is fixed.
|
109
|
+
def self.inherited(cls)
|
110
|
+
cls.send(:include, DynamicMBean)
|
111
|
+
end
|
112
|
+
|
113
|
+
# TODO: preserve any original method_added?
|
114
|
+
# TODO: Error handling here when it all goes wrong?
|
115
|
+
def self.method_added(name) #:nodoc:
|
116
|
+
return if Thread.current[:op].nil?
|
117
|
+
Thread.current[:op].name = name
|
118
|
+
operations << Thread.current[:op].to_jmx
|
119
|
+
Thread.current[:op] = nil
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.attributes #:nodoc:
|
123
|
+
Thread.current[:attrs] ||= []
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.operations #:nodoc:
|
127
|
+
Thread.current[:ops] ||= []
|
128
|
+
end
|
129
|
+
|
130
|
+
# the <tt>rw_attribute</tt> method is used to declare a JMX read write attribute.
|
131
|
+
# see the +JavaSimpleTypes+ module for more information about acceptable types
|
132
|
+
# usage:
|
133
|
+
# rw_attribute :attribute_name, :string, "Description displayed in a JMX console"
|
134
|
+
#
|
135
|
+
# The name and type parameters are mandatory
|
136
|
+
# The description parameter is optional (defaults to the same value than the env: ruby: No such file or directory
|
137
|
+
# name parameter in that case)
|
138
|
+
# --
|
139
|
+
# methods used to create an attribute. They are modeled on the attrib_accessor
|
140
|
+
# patterns of creating getters and setters in ruby
|
141
|
+
#++
|
142
|
+
def self.rw_attribute(name, type, description=nil)
|
143
|
+
description ||= name.to_s
|
144
|
+
attributes << JMX::Attribute.new(name, type, description, true, true).to_jmx
|
145
|
+
attr_accessor name
|
146
|
+
#create a "java" oriented accessor method
|
147
|
+
define_method("jmx_get_#{name.to_s.downcase}") do
|
148
|
+
begin
|
149
|
+
#attempt conversion
|
150
|
+
java_type = to_java_type(type)
|
151
|
+
value = eval "#{java_type}.new(@#{name.to_s})"
|
152
|
+
rescue
|
153
|
+
#otherwise turn it into a java Object type for now.
|
154
|
+
value = eval "Java.ruby_to_java(@#{name.to_s})"
|
155
|
+
end
|
156
|
+
attribute = javax.management.Attribute.new(name.to_s, value)
|
157
|
+
end
|
158
|
+
|
159
|
+
define_method("jmx_set_#{name.to_s.downcase}") do |value|
|
160
|
+
blck = to_ruby(type)
|
161
|
+
send "#{name.to_s}=", blck.call(value)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# the <tt>r_attribute</tt> method is used to declare a JMX read only attribute.
|
166
|
+
# see the +JavaSimpleTypes+ module for more information about acceptable types
|
167
|
+
# usage:
|
168
|
+
# r_attribute :attribute_name, :string, "Description displayed in a JMX console"
|
169
|
+
def self.r_attribute(name, type, description)
|
170
|
+
attributes << JMX::Attribute.new(name, type, description, true, false).to_jmx
|
171
|
+
attr_reader name
|
172
|
+
#create a "java" oriented accessor method
|
173
|
+
define_method("jmx_get_#{name.to_s.downcase}") do
|
174
|
+
begin
|
175
|
+
#attempt conversion
|
176
|
+
java_type = to_java_type(type)
|
177
|
+
value = eval "#{java_type}.new(@#{name.to_s})"
|
178
|
+
rescue
|
179
|
+
#otherwise turn it into a java Object type for now.
|
180
|
+
value = eval "Java.ruby_to_java(@#{name.to_s})"
|
181
|
+
end
|
182
|
+
attribute = javax.management.Attribute.new(name.to_s, value)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# the <tt>w_attribute</tt> method is used to declare a JMX write only attribute.
|
187
|
+
# see the +JavaSimpleTypes+ module for more information about acceptable types
|
188
|
+
# usage:
|
189
|
+
# w_attribute :attribute_name, :string, "Description displayed in a JMX console"
|
190
|
+
def self.w_attribute(name, type, description)
|
191
|
+
attributes << JMX::Attribute.new(name, type, description, false, true).to_jmx
|
192
|
+
attr_writer name
|
193
|
+
define_method("jmx_set_#{name.to_s.downcase}") do |value|
|
194
|
+
blck = to_ruby(type)
|
195
|
+
eval "@#{name.to_s} = #{blck.call(value)}"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# Use the operation method to declare the start of an operation
|
200
|
+
# It takes as an optional argument the description for the operation
|
201
|
+
# Example:
|
202
|
+
# operation "Used to start the service"
|
203
|
+
# def start
|
204
|
+
# end
|
205
|
+
#--
|
206
|
+
# Last operation wins if more than one
|
207
|
+
#++
|
208
|
+
def self.operation(description=nil)
|
209
|
+
# Wait to error check until method_added so we can know method name
|
210
|
+
Thread.current[:op] = JMX::Operation.new description
|
211
|
+
end
|
212
|
+
|
213
|
+
# Used to declare a parameter (you can declare more than one in succession) that
|
214
|
+
# is associated with the currently declared operation.
|
215
|
+
# The type is mandatory, the name and description are optional.
|
216
|
+
# Example:
|
217
|
+
# operation "Used to update the name of a service"
|
218
|
+
# parameter :string, "name", "Set the new name of the service"
|
219
|
+
# def start(name)
|
220
|
+
# ...
|
221
|
+
# end
|
222
|
+
def self.parameter(type, name=nil, description=nil)
|
223
|
+
Thread.current[:op].parameters << JMX::Parameter.new(type, name, description)
|
224
|
+
end
|
225
|
+
|
226
|
+
# Used to declare the return type of the operation
|
227
|
+
# operation "Used to update the name of a service"
|
228
|
+
# parameter :string, "name", "Set the new name of the service"
|
229
|
+
# returns :void
|
230
|
+
# def do_stuff
|
231
|
+
# ...
|
232
|
+
# end
|
233
|
+
def self.returns(type)
|
234
|
+
Thread.current[:op].return_type = type
|
235
|
+
end
|
236
|
+
|
237
|
+
def initialize(description="")
|
238
|
+
name = self.class.to_s
|
239
|
+
operations = self.class.operations.to_java(MBeanOperationInfo)
|
240
|
+
attributes = self.class.attributes.to_java(MBeanAttributeInfo)
|
241
|
+
@info = MBeanInfo.new name, description, attributes, nil, operations, nil
|
242
|
+
end
|
243
|
+
|
244
|
+
# Retrieve the value of the requested attribute
|
245
|
+
def getAttribute(attribute)
|
246
|
+
send("jmx_get_"+attribute.downcase).value
|
247
|
+
end
|
248
|
+
|
249
|
+
def getAttributes(attributes)
|
250
|
+
attrs = javax.management.AttributeList.new
|
251
|
+
attributes.each { |attribute| send("jmx_get_"+attribute.downcase) }
|
252
|
+
attrs
|
253
|
+
end
|
254
|
+
|
255
|
+
def getMBeanInfo; @info; end
|
256
|
+
|
257
|
+
def invoke(actionName, params=nil, signature=nil)
|
258
|
+
send(actionName, *params)
|
259
|
+
end
|
260
|
+
|
261
|
+
def setAttribute(attribute)
|
262
|
+
send("jmx_set_#{attribute.name.downcase}", attribute.value)
|
263
|
+
end
|
264
|
+
|
265
|
+
def setAttributes(attributes)
|
266
|
+
attributes.each { |attribute| setAttribute attribute}
|
267
|
+
end
|
268
|
+
|
269
|
+
def to_s; toString; end
|
270
|
+
def inspect; toString; end
|
271
|
+
def toString; "#@info.class_name: #@info.description"; end
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
|
data/lib/jconsole.rb
CHANGED
data/lib/jmx4r.rb
CHANGED
@@ -15,6 +15,7 @@ class String
|
|
15
15
|
end
|
16
16
|
|
17
17
|
module JMX
|
18
|
+
require 'dynamic_mbean'
|
18
19
|
require 'open_data_helper'
|
19
20
|
require 'objectname_helper'
|
20
21
|
require 'jruby'
|
@@ -135,23 +136,29 @@ module JMX
|
|
135
136
|
|
136
137
|
# Create a connection to a remote MBean server.
|
137
138
|
#
|
138
|
-
# The args accepts
|
139
|
+
# The args accepts the following keys:
|
139
140
|
#
|
140
|
-
# [:host]
|
141
|
-
#
|
142
|
-
# [:
|
143
|
-
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
#
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
141
|
+
# [:host] the host of the MBean server (defaults to "localhost")
|
142
|
+
#
|
143
|
+
# [:port] the port of the MBean server (defaults to 3000)
|
144
|
+
#
|
145
|
+
# [:url] the url of the MBean server.
|
146
|
+
# No default.
|
147
|
+
# if the url is specified, the host & port parameters are
|
148
|
+
# not taken into account
|
149
|
+
#
|
150
|
+
# [:username] the name of the user (if the MBean server requires authentication).
|
151
|
+
# No default
|
152
|
+
#
|
153
|
+
# [:password] the password of the user (if the MBean server requires authentication).
|
154
|
+
# No default
|
155
|
+
#
|
156
|
+
# [:credentials] custom credentials (if the MBean server requires authentication).
|
157
|
+
# No default. It has precedence over :username and :password (i.e. if
|
158
|
+
# :credentials is specified, :username & :password are ignored)
|
159
|
+
#
|
160
|
+
# [:provider_package] use to fill the JMXConnectorFactory::PROTOCOL_PROVIDER_PACKAGES.
|
161
|
+
# No default
|
155
162
|
#
|
156
163
|
def self.create_connection(args={})
|
157
164
|
host= args[:host] || "localhost"
|
data/test/tc_attributes.rb
CHANGED
@@ -6,14 +6,14 @@ require "jmx4r"
|
|
6
6
|
require "jconsole"
|
7
7
|
|
8
8
|
class TestAttribute < Test::Unit::TestCase
|
9
|
+
import java.lang.management.ManagementFactory
|
10
|
+
|
9
11
|
def setup
|
10
|
-
|
11
|
-
@memory = JMX::MBean.find_by_name "java.lang:type=Memory"
|
12
|
+
@memory = JMX::MBean.find_by_name "java.lang:type=Memory", :connection => ManagementFactory.platform_mbean_server
|
12
13
|
end
|
13
14
|
|
14
15
|
def teardown
|
15
16
|
JMX::MBean.remove_connection
|
16
|
-
JConsole::stop
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_unknwown_attribute
|
@@ -28,6 +28,7 @@ class TestAttribute < Test::Unit::TestCase
|
|
28
28
|
assert_equal false, @memory.verbose
|
29
29
|
@memory.verbose = true
|
30
30
|
assert_equal true, @memory.verbose
|
31
|
+
@memory.verbose = false
|
31
32
|
end
|
32
33
|
|
33
34
|
def test_non_writable_attribute
|
data/test/tc_composite_data.rb
CHANGED
@@ -6,9 +6,10 @@ require "jmx4r"
|
|
6
6
|
require "jconsole"
|
7
7
|
|
8
8
|
class TestCompositeData < Test::Unit::TestCase
|
9
|
+
import java.lang.management.ManagementFactory
|
10
|
+
|
9
11
|
def setup
|
10
|
-
|
11
|
-
memory = JMX::MBean.find_by_name "java.lang:type=Memory"
|
12
|
+
memory = JMX::MBean.find_by_name "java.lang:type=Memory", :connection => ManagementFactory.platform_mbean_server
|
12
13
|
# heap_memory_usage is a CompositeData
|
13
14
|
@heap = memory.heap_memory_usage
|
14
15
|
end
|
@@ -16,7 +17,6 @@ class TestCompositeData < Test::Unit::TestCase
|
|
16
17
|
def teardown
|
17
18
|
@heap = nil
|
18
19
|
JMX::MBean.remove_connection
|
19
|
-
JConsole::stop
|
20
20
|
end
|
21
21
|
|
22
22
|
# use #map to check that CompositeData includes Enumerable
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Copyright 2008 Jeff Mesnil (http://jmesnil.net)
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
require "jmx4r"
|
5
|
+
|
6
|
+
|
7
|
+
class TestDynamicMBean < Test::Unit::TestCase
|
8
|
+
|
9
|
+
import java.lang.management.ManagementFactory
|
10
|
+
import javax.management.ObjectName
|
11
|
+
|
12
|
+
class AttributeTypesMBean < JMX::DynamicMBean
|
13
|
+
rw_attribute :string_attr, :string, "a String attribute"
|
14
|
+
rw_attribute :byte_attr, :byte, "a Byte attribute"
|
15
|
+
rw_attribute :int_attr, :int, "a Integer attribute"
|
16
|
+
rw_attribute :long_attr, :long, "a Long attribute"
|
17
|
+
rw_attribute :float_attr, :float, "a Float attribute"
|
18
|
+
rw_attribute :double_attr, :double, "a Double attribute"
|
19
|
+
rw_attribute :list_attr, :list, "a List attribute"
|
20
|
+
rw_attribute :map_attr, :map, "a Map attribute"
|
21
|
+
rw_attribute :set_attr, :set, "a Set attribute"
|
22
|
+
rw_attribute :boolean_attr, :boolean, "a Boolean attribute"
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_attribute_types
|
26
|
+
mbean = AttributeTypesMBean.new
|
27
|
+
mbeanServer = ManagementFactory.platform_mbean_server
|
28
|
+
mbeanServer.register_mbean mbean, ObjectName.new("jmx4r:name=AttributeTypesMBean")
|
29
|
+
|
30
|
+
mbean = JMX::MBean.find_by_name "jmx4r:name=AttributeTypesMBean", :connection => mbeanServer
|
31
|
+
mbean.string_attr = "test"
|
32
|
+
assert_equal("test", mbean.string_attr)
|
33
|
+
|
34
|
+
mbean.byte_attr = 9
|
35
|
+
assert_equal(9, mbean.byte_attr)
|
36
|
+
|
37
|
+
mbean.int_attr = 23
|
38
|
+
assert_equal(23, mbean.int_attr)
|
39
|
+
|
40
|
+
mbean.long_attr = 33
|
41
|
+
assert_equal(33, mbean.long_attr)
|
42
|
+
|
43
|
+
mbean.float_attr = 91.0
|
44
|
+
assert_equal(91.0, mbean.float_attr)
|
45
|
+
|
46
|
+
mbean.float_attr = 7.0
|
47
|
+
assert_equal(7.0, mbean.float_attr)
|
48
|
+
|
49
|
+
mbean.list_attr = [1, 2, 3]
|
50
|
+
assert_equal([1, 2, 3], mbean.list_attr.to_a)
|
51
|
+
|
52
|
+
mbean.set_attr = [1, 2, 3]
|
53
|
+
assert_equal([1, 2, 3].sort, mbean.list_attr.to_a.sort)
|
54
|
+
|
55
|
+
mbean.map_attr = { "a" => 1, "b" => 2}
|
56
|
+
assert_equal({ "a" => 1, "b" => 2}.to_a.sort, mbean.map_attr.to_a.sort)
|
57
|
+
|
58
|
+
mbean.boolean_attr = true
|
59
|
+
assert_equal(true, mbean.boolean_attr)
|
60
|
+
end
|
61
|
+
|
62
|
+
class OperationInvocationMBean < JMX::DynamicMBean
|
63
|
+
operation "reverse the string passed in parameter"
|
64
|
+
parameter :string, "arg", "a String to reverse"
|
65
|
+
returns :string
|
66
|
+
def reverse(arg)
|
67
|
+
arg.reverse
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_operation_invocation
|
72
|
+
mbean = OperationInvocationMBean.new
|
73
|
+
mbeanServer = ManagementFactory.platform_mbean_server
|
74
|
+
mbeanServer.register_mbean mbean, ObjectName.new("jmx4r:name=OperationInvocationMBean")
|
75
|
+
|
76
|
+
mbean = JMX::MBean.find_by_name "jmx4r:name=OperationInvocationMBean", :connection => mbeanServer
|
77
|
+
assert_equal("oof", mbean.reverse("foo"))
|
78
|
+
end
|
79
|
+
end
|
data/test/ts_all.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
|
2
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
3
|
+
requirements:
|
4
|
+
- - '>='
|
5
|
+
- !ruby/object:Gem::Version
|
6
|
+
version: "0"
|
7
|
+
version:
|
8
|
+
email: jmesnil@gmail.com
|
9
|
+
cert_chain: []
|
3
10
|
|
11
|
+
summary: jmx4r is a JMX library for JRuby
|
12
|
+
post_install_message:
|
13
|
+
extra_rdoc_files:
|
14
|
+
- README.rdoc
|
15
|
+
- LICENSE.txt
|
4
16
|
homepage: http://jmesnil.net/wiki/Jmx4r
|
17
|
+
signing_key:
|
18
|
+
name: jmx4r
|
19
|
+
rdoc_options:
|
20
|
+
- --title
|
21
|
+
- jmx4r Documentation
|
22
|
+
- --main
|
23
|
+
- README.rdoc
|
24
|
+
rubyforge_project: jmx4r
|
25
|
+
autorequire:
|
26
|
+
licenses: []
|
27
|
+
|
5
28
|
executables: []
|
6
29
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
30
|
+
description: |
|
31
|
+
jmx4r is a JMX library for JRuby
|
32
|
+
specification_version: 3
|
33
|
+
default_executable:
|
11
34
|
files:
|
12
35
|
- examples/class_loading.rb
|
13
36
|
- examples/jvm_mngmt.rb
|
@@ -15,7 +38,9 @@ files:
|
|
15
38
|
- examples/memory.rb
|
16
39
|
- examples/memory_on_many_nodes.rb
|
17
40
|
- examples/memory_types.rb
|
41
|
+
- examples/ruby_mbean.rb
|
18
42
|
- examples/runtime_sysprops.rb
|
43
|
+
- lib/dynamic_mbean.rb
|
19
44
|
- lib/jconsole.rb
|
20
45
|
- lib/jmx4r.rb
|
21
46
|
- lib/objectname_helper.rb
|
@@ -24,53 +49,34 @@ files:
|
|
24
49
|
- test/tc_auth.rb
|
25
50
|
- test/tc_composite_data.rb
|
26
51
|
- test/tc_connection.rb
|
52
|
+
- test/tc_dynamic_mbean.rb
|
27
53
|
- test/tc_multiple_connections.rb
|
28
54
|
- test/ts_all.rb
|
29
55
|
- Rakefile
|
30
56
|
- README.rdoc
|
31
57
|
- LICENSE.txt
|
32
|
-
rubygems_version: 1.3.1
|
33
|
-
rdoc_options:
|
34
|
-
- --title
|
35
|
-
- jmx4r Documentation
|
36
|
-
- --main
|
37
|
-
- README.rdoc
|
38
|
-
signing_key:
|
39
|
-
cert_chain: []
|
40
|
-
|
41
|
-
name: jmx4r
|
42
|
-
has_rdoc: true
|
43
|
-
platform: ruby
|
44
|
-
summary: jmx4r is a JMX library for JRuby
|
45
|
-
default_executable:
|
46
|
-
bindir: bin
|
47
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
-
version:
|
49
59
|
requirements:
|
50
60
|
- - '>='
|
51
61
|
- !ruby/object:Gem::Version
|
52
62
|
version: "0"
|
53
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
54
63
|
version:
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
require_paths:
|
60
|
-
- lib
|
61
|
-
specification_version: 2
|
62
|
-
test_files:
|
63
|
-
- test/ts_all.rb
|
64
|
-
dependencies: []
|
64
|
+
extensions: []
|
65
|
+
|
66
|
+
rubygems_version: 1.3.3
|
67
|
+
requirements: []
|
65
68
|
|
66
|
-
description: jmx4r is a JMX library for JRuby
|
67
|
-
email: jmesnil@gmail.com
|
68
69
|
authors:
|
69
70
|
- Jeff Mesnil
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
date: 2009-06-14 22:00:00 +00:00
|
72
|
+
platform: ruby
|
73
|
+
test_files:
|
74
|
+
- test/ts_all.rb
|
75
|
+
version: !ruby/object:Gem::Version
|
76
|
+
version: 0.0.8
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
dependencies: []
|
74
80
|
|
75
|
-
|
76
|
-
|
81
|
+
bindir: bin
|
82
|
+
has_rdoc: true
|