jmx 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Manifest.txt CHANGED
@@ -3,12 +3,14 @@ Rakefile
3
3
  README.txt
4
4
  LICENSE.txt
5
5
  lib/jmx
6
+ lib/jmx.rb
7
+ lib/rmi.rb
6
8
  lib/jmx/dynamic_mbean.rb
7
9
  lib/jmx/server.rb
8
10
  lib/jmx/version.rb
9
- lib/jmx.rb
10
- lib/rmi.rb
11
11
  samples/memory.rb
12
12
  test/jmx_attribute_test.rb
13
13
  test/jmx_client_test.rb
14
+ test/jmx_notification_test.rb
14
15
  test/jmx_server_test.rb
16
+ test/object_name_test.rb
data/Rakefile CHANGED
File without changes
data/lib/jmx.rb CHANGED
@@ -6,17 +6,19 @@ require 'jmx/server'
6
6
 
7
7
  import java.util.ArrayList
8
8
  import javax.management.Attribute
9
- import javax.management.DynamicMBean
10
9
  import javax.management.MBeanInfo
11
- import javax.management.ObjectName
10
+ import javax.management.DynamicMBean
12
11
 
13
- class ObjectName
14
- def [](key)
15
- get_key_property(key.to_s)
16
- end
12
+ module JMX
13
+ import javax.management.ObjectName
14
+ class ObjectName
15
+ def [](key)
16
+ get_key_property(key.to_s)
17
+ end
17
18
 
18
- def info(server)
19
- server.getMBeanInfo(self)
19
+ def info(server)
20
+ server.getMBeanInfo(self)
21
+ end
20
22
  end
21
23
  end
22
24
 
@@ -70,10 +70,10 @@ module JMX
70
70
  end
71
71
  end
72
72
 
73
- # The Ruby-Java JMX utilities work throught the DynamicMBean concept. Creators of Ruby based MBeans must inherit this
73
+ # The Ruby-Java JMX utilities work throughout the DynamicMBean concept. Creators of Ruby based MBeans must inherit this
74
74
  # class (<tt>RubyDynamicMBean</tt>) in their own bean classes and then register them with a JMX mbean server.
75
75
  # Here is an example:
76
- # class MyMBean < DynamicMBean
76
+ # class MyMBean < RuybDynamicMBean
77
77
  # rw_attribute :status, :string, "Status information for this process"
78
78
  #
79
79
  # operation "Shutdown this process"
@@ -83,18 +83,27 @@ end
83
83
  # "shutdown requests more time"
84
84
  # end
85
85
  # end
86
- # Once you have defined your bean class you can start declaring attributes and operations. Attributes come in three flavors:
87
- # read, write, and read write. Simmilar to the <tt>attr*</tt> helpers, there are helpers that are used to create management
88
- # attributes. Use +r_attribute+, +w_attribute+, and +rw_attribute+ to declare attributes, and the +operation+, +returns+, and +parameter+
89
- # helpers to define a management operation.
86
+ # Once you have defined your bean class you can start declaring attributes and operations.
87
+ # Attributes come in three flavors: read, write, and read write. Simmilar to the <tt>attr*</tt>
88
+ # helpers, there are helpers that are used to create management attributes. Use +r_attribute+,
89
+ # +w_attribute+, and +rw_attribute+ to declare attributes, and the +operation+, +returns+,
90
+ # and +parameter+ helpers to define a management operation.
90
91
  # Creating attributes with the *_attribute convention ALSO creates ruby accessors
91
- # (it invokes the attr_accessor/attr_reader/attr_writer ruby helpers) to create ruby methods like: user_name= and username.
92
- # So in your ruby code you can treat the attributes as "regular" ruby accessors
92
+ # (it invokes the attr_accessor/attr_reader/attr_writer ruby helpers) to create ruby methods
93
+ # like: user_name= and username. So in your ruby code you can treat the attributes
94
+ # as "regular" ruby accessors
93
95
  class RubyDynamicMBean
94
96
  import javax.management.MBeanOperationInfo
95
97
  import javax.management.MBeanAttributeInfo
98
+ import javax.management.DynamicMBean
99
+ import javax.management.MBeanInfo
96
100
  include JMX::JavaTypeAware
97
101
 
102
+ #NOTE this will not be needed when JRuby-3164 is fixed.
103
+ def self.inherited(cls)
104
+ cls.send(:include, DynamicMBean)
105
+ end
106
+
98
107
  # TODO: preserve any original method_added?
99
108
  # TODO: Error handling here when it all goes wrong?
100
109
  def self.method_added(name) #:nodoc:
@@ -120,8 +129,6 @@ class RubyDynamicMBean
120
129
  # patterns of creating getters and setters in ruby
121
130
  #++
122
131
  def self.rw_attribute(name, type, description)
123
- #QUESTION: Is this here to ensure that our type implements the interface?
124
- include DynamicMBean
125
132
  attributes << JMX::Attribute.new(name, type, description, true, true).to_jmx
126
133
  attr_accessor name
127
134
  #create a "java" oriented accessor method
@@ -140,15 +147,14 @@ class RubyDynamicMBean
140
147
  define_method("jmx_set_#{name.to_s.downcase}") do |value|
141
148
  blck = to_ruby(type)
142
149
  eval "@#{name.to_s} = #{blck.call(value)}"
143
- end
144
-
150
+ end
145
151
  end
152
+
146
153
  # the <tt>r_attribute</tt> method is used to declare a JMX read only attribute.
147
154
  # see the +JavaSimpleTypes+ module for more information about acceptable types
148
155
  # usage:
149
156
  # r_attribute :attribute_name, :string, "Description displayed in a JMX console"
150
157
  def self.r_attribute(name, type, description)
151
- include DynamicMBean
152
158
  attributes << JMX::Attribute.new(name, type, description, true, false).to_jmx
153
159
  attr_reader name
154
160
  #create a "java" oriented accessor method
@@ -164,12 +170,12 @@ class RubyDynamicMBean
164
170
  attribute = javax.management.Attribute.new(name.to_s, value)
165
171
  end
166
172
  end
173
+
167
174
  # the <tt>w_attribute</tt> method is used to declare a JMX write only attribute.
168
175
  # see the +JavaSimpleTypes+ module for more information about acceptable types
169
176
  # usage:
170
177
  # w_attribute :attribute_name, :string, "Description displayed in a JMX console"
171
178
  def self.w_attribute(name, type, description)
172
- include DynamicMBean
173
179
  attributes << JMX::Attribute.new(name, type, description, false, true).to_jmx
174
180
  attr_writer name
175
181
  define_method("jmx_set_#{name.to_s.downcase}") do |value|
@@ -187,7 +193,6 @@ class RubyDynamicMBean
187
193
  # Last operation wins if more than one
188
194
  #++
189
195
  def self.operation(description)
190
- include DynamicMBean
191
196
 
192
197
  # Wait to error check until method_added so we can know method name
193
198
  Thread.current[:op] = JMX::Operation.new description
@@ -221,7 +226,8 @@ class RubyDynamicMBean
221
226
  @info = MBeanInfo.new name, description, attributes, nil, operations, nil
222
227
  end
223
228
 
224
- # Retrieve the value of the requested attribute (where attribute is a javax.management.Attribute class)
229
+ # Retrieve the value of the requested attribute (where attribute is a
230
+ # javax.management.Attribute class)
225
231
  def getAttribute(attribute)
226
232
  send("jmx_get_"+attribute.downcase)
227
233
  end
data/lib/jmx/server.rb CHANGED
@@ -69,12 +69,16 @@ module JMX
69
69
 
70
70
  @server.query_names(object_name, query)
71
71
  end
72
+
73
+ def unregister_mbean(object_name)
74
+ name = make_object_name object_name
75
+ @server.unregisterMBean(name)
76
+
77
+ end
72
78
 
73
79
  def register_mbean(object, object_name)
74
80
  name = make_object_name object_name
75
-
76
81
  @server.registerMBean(object, name)
77
-
78
82
  MBeanProxy.generate(@server, name)
79
83
  end
80
84
 
data/lib/jmx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module JMX
2
- VERSION = "0.2"
2
+ VERSION = "0.3"
3
3
  end
data/lib/rmi.rb CHANGED
File without changes
@@ -1,11 +1,8 @@
1
-
2
1
  $:.unshift File.join(File.dirname(__FILE__),'..','lib')
3
2
 
4
3
  require 'test/unit'
5
- require 'rmi'
6
4
  require 'jmx'
7
5
 
8
-
9
6
  class MyAttributeDynamicBean < RubyDynamicMBean
10
7
  rw_attribute :name1, :string, "My sample attribute"
11
8
  r_attribute :number1, :int, "My sample integer based attribute that is read only"
@@ -23,86 +20,9 @@ class MyAttributeDynamicBean < RubyDynamicMBean
23
20
  end
24
21
  end
25
22
 
26
- class JMXAttributeTest < Test::Unit::TestCase
27
-
28
- def setup
29
- @madb = MyAttributeDynamicBean.new("test.MyTestBean","Mwahahahahahah")
30
- end
31
-
32
- #make sure we didn't break anything from a ruby perspective
33
- def test_can_create_bean_and_access_accessor_type_methods
34
- @madb.set_number1 4
35
- assert_nil(@madb.name1)
36
- @madb.name1 = "Name"
37
- assert_equal("Name", @madb.name1)
38
- assert_equal(4, @madb.number1)
39
- @madb.number2 = 4
40
- assert_equal(4, @madb.fetch_number2)
41
- assert_raise(NoMethodError) { @madb.number2 }
42
- end
43
-
44
- def test_get_attributes_via_dynamicmbeaninterface
45
- @madb.set_number1 4
46
- @madb.name1 = "Name"
47
-
48
- assert_equal(@madb.name1, @madb.getAttribute("name1").get_value.to_s)
49
- assert_equal(@madb.number1, @madb.getAttribute("number1").get_value)
50
- atts = ["name1", "number1"]
51
- retrieved = @madb.getAttributes(atts)
52
- assert_equal(2, retrieved.length)
53
- #TODO: assertion comparing the types in teh array to java types
54
- end
55
-
56
- def test_set_attributes_via_dynamicbeaninterface
57
- @madb.name1 = "blue"
58
- red = java.lang.String.new("red")
59
- attribute = javax.management.Attribute.new("name1", red)
60
- @madb.setAttribute(attribute)
61
-
62
- assert_equal("String", @madb.name1.class.to_s )
63
- assert_equal("red", @madb.name1)
64
- end
65
-
66
- def test_set_multiple_attributes_via_dynamicbeaninterface
67
- @madb.name1 = "blue"
68
- three = java.lang.Integer.new(3)
69
- red = java.lang.String.new("red")
70
- attribute1 = javax.management.Attribute.new("name1", red)
71
- attribute2 = javax.management.Attribute.new("number2", three)
72
-
73
- @madb.setAttributes([attribute1, attribute2])
74
- assert_equal("red", @madb.name1)
75
- assert_equal(3, @madb.fetch_number2)
76
- end
77
-
78
- end
79
-
80
- $:.unshift File.join(File.dirname(__FILE__),'..','lib')
81
-
82
- require 'test/unit'
83
- require 'rmi'
84
- require 'jmx'
85
-
86
-
87
- class MyAttributeDynamicBean < RubyDynamicMBean
88
- rw_attribute :name1, :string, "My sample attribute"
89
- r_attribute :number1, :int, "My sample integer based attribute that is read only"
90
- w_attribute :number2, :int, "My sample integer based attribute that is write only"
91
-
92
- def intialize(type, text)
93
- super(type,text)
94
- end
95
- def set_number1(val)
96
- @number1 = val
97
- end
98
-
99
- def fetch_number2
100
- @number2
101
- end
102
- end
103
23
 
104
24
  class JMXAttributeTest < Test::Unit::TestCase
105
-
25
+
106
26
  def setup
107
27
  @madb = MyAttributeDynamicBean.new("test.MyTestBean","Mwahahahahahah")
108
28
  end
@@ -154,3 +74,4 @@ class JMXAttributeTest < Test::Unit::TestCase
154
74
  end
155
75
 
156
76
  end
77
+
File without changes
@@ -0,0 +1,29 @@
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
@@ -68,4 +68,17 @@ class JMXServerTest < Test::Unit::TestCase
68
68
  assert_equal("hehheh", bean.string_double("heh"))
69
69
  assert_equal("123", bean.concat([1,2,3]))
70
70
  end
71
+ def test_ruby_mbean_twice
72
+ dyna = MyDynamicMBean.new("domain.MySuperBean", "Heh")
73
+ domain = @server.default_domain
74
+ @server.unregister_mbean "#{domain}:type=MyDynamicMBean"
75
+ @server.register_mbean dyna, "#{domain}:type=MyDynamicMBean"
76
+ # Get bean from client connector connection
77
+ bean = @client["#{domain}:type=MyDynamicMBean"]
78
+ assert_equal("foo", bean.foo)
79
+ assert_equal(6, bean.double(3))
80
+ assert_raise(TypeError) { puts bean.double("HEH") }
81
+ assert_equal("hehheh", bean.string_double("heh"))
82
+ assert_equal("123", bean.concat([1,2,3]))
83
+ end
71
84
  end
@@ -0,0 +1,12 @@
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
metadata CHANGED
@@ -1,69 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
- name: jmx
3
- version: !ruby/object:Gem::Version
4
- version: "0.2"
5
- platform: ruby
6
- authors:
7
- - Thomas Enebo
8
- autorequire:
9
- bindir: bin
10
- cert_chain: []
11
-
12
- date: 2008-07-28 00:00:00 +09:00
13
- default_executable:
14
- dependencies: []
15
-
16
- description: Install this gem and require 'jmx' to load the library.
2
+ required_ruby_version: !ruby/object:Gem::Requirement
3
+ requirements:
4
+ - - '>='
5
+ - !ruby/object:Gem::Version
6
+ version: "0"
7
+ version:
17
8
  email: enebo@acm.org
18
- executables: []
19
-
20
- extensions: []
9
+ cert_chain: []
21
10
 
11
+ summary: Package for interacting/creating Java Management Extensions
12
+ post_install_message:
22
13
  extra_rdoc_files:
23
14
  - Manifest.txt
24
15
  - README.txt
25
16
  - LICENSE.txt
17
+ homepage: http://jruby-extras.rubyforge.org/jmx
18
+ signing_key:
19
+ name: jmx
20
+ rdoc_options:
21
+ - --main
22
+ - README.txt
23
+ autorequire:
24
+ rubyforge_project: jruby-extras
25
+ executables: []
26
+
27
+ description: Install this gem and require 'jmx' to load the library.
28
+ specification_version: 2
29
+ default_executable:
26
30
  files:
27
31
  - Manifest.txt
28
32
  - Rakefile
29
33
  - README.txt
30
34
  - LICENSE.txt
31
35
  - lib/jmx
36
+ - lib/jmx.rb
37
+ - lib/rmi.rb
32
38
  - lib/jmx/dynamic_mbean.rb
33
39
  - lib/jmx/server.rb
34
40
  - lib/jmx/version.rb
35
- - lib/jmx.rb
36
- - lib/rmi.rb
37
41
  - samples/memory.rb
38
42
  - test/jmx_attribute_test.rb
39
43
  - test/jmx_client_test.rb
44
+ - test/jmx_notification_test.rb
40
45
  - test/jmx_server_test.rb
41
- has_rdoc: true
42
- homepage: http://jruby-extras.rubyforge.org/jmx
43
- post_install_message:
44
- rdoc_options:
45
- - --main
46
- - README.txt
47
- require_paths:
48
- - lib
49
- required_ruby_version: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
54
- version:
46
+ - test/object_name_test.rb
55
47
  required_rubygems_version: !ruby/object:Gem::Requirement
56
48
  requirements:
57
- - - ">="
49
+ - - '>='
58
50
  - !ruby/object:Gem::Version
59
51
  version: "0"
60
52
  version:
53
+ extensions: []
54
+
55
+ rubygems_version: 1.3.1
61
56
  requirements: []
62
57
 
63
- rubyforge_project: jruby-extras
64
- rubygems_version: 1.0.1
65
- signing_key:
66
- specification_version: 2
67
- summary: Package for interacting/creating Java Management Extensions
58
+ authors:
59
+ - Thomas Enebo
60
+ date: 2008-11-21 05:00:00 +00:00
61
+ platform: ruby
68
62
  test_files: []
69
63
 
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