Title: [1134] trunk/jmx: Updating gem to handle interface inheritence work around. ..
Revision
1134
Author
hooligan495
Date
2008-11-19 09:12:26 -0500 (Wed, 19 Nov 2008)

Log Message

Updating gem to handle interface inheritence work around... See the todo in dynamic_mbean.rb for the bug being worked around

Modified Paths

Diff

Modified: trunk/jmx/Manifest.txt (1133 => 1134)


--- trunk/jmx/Manifest.txt	2008-11-16 07:15:59 UTC (rev 1133)
+++ trunk/jmx/Manifest.txt	2008-11-19 14:12:26 UTC (rev 1134)
@@ -12,3 +12,4 @@
 test/jmx_attribute_test.rb
 test/jmx_client_test.rb
 test/jmx_server_test.rb
+test/test.rb

Modified: trunk/jmx/lib/jmx/dynamic_mbean.rb (1133 => 1134)


--- trunk/jmx/lib/jmx/dynamic_mbean.rb	2008-11-16 07:15:59 UTC (rev 1133)
+++ trunk/jmx/lib/jmx/dynamic_mbean.rb	2008-11-19 14:12:26 UTC (rev 1134)
@@ -70,10 +70,10 @@
   end
 end
 
-#  The Ruby-Java JMX utilities work throught the DynamicMBean concept.  Creators of Ruby based MBeans must inherit this
+#  The Ruby-Java JMX utilities work throughout the DynamicMBean concept.  Creators of Ruby based MBeans must inherit this
 # class (<tt>RubyDynamicMBean</tt>) in their own bean classes and then register them with a JMX mbean server.  
 #  Here is an example:
-#       class MyMBean < DynamicMBean
+#       class MyMBean < RuybDynamicMBean
 #         rw_attribute :status, :string, "Status information for this process"
 #         
 #         operation "Shutdown this process"
@@ -93,8 +93,14 @@
 class RubyDynamicMBean
   import javax.management.MBeanOperationInfo
   import javax.management.MBeanAttributeInfo
+  import javax.management.DynamicMBean
   include JMX::JavaTypeAware
   
+  #NOTE this will not be needed when JRuby-3164 is fixed.
+  def self.inherited(cls)
+    cls.send(:include, DynamicMBean)
+  end
+  
   # TODO: preserve any original method_added?
   # TODO: Error handling here when it all goes wrong?
   def self.method_added(name) #:nodoc:
@@ -120,8 +126,6 @@
   # patterns of creating getters and setters in ruby
   #++
   def self.rw_attribute(name, type, description)
-    #QUESTION: Is this here to ensure that our type implements the interface?
-    include DynamicMBean
     attributes << JMX::Attribute.new(name, type, description, true, true).to_jmx
     attr_accessor name    
     #create a "java" oriented accessor method
@@ -140,15 +144,14 @@
     define_method("jmx_set_#{name.to_s.downcase}") do |value| 
       blck = to_ruby(type)
       eval "@#{name.to_s} = #{blck.call(value)}"
-    end
-    
+    end    
   end
+  
   # the <tt>r_attribute</tt> method is used to declare a JMX read only attribute.
   # see the +JavaSimpleTypes+ module for more information about acceptable types
   # usage: 
   #  r_attribute :attribute_name, :string, "Description displayed in a JMX console"
   def self.r_attribute(name, type, description)
-    include DynamicMBean        
     attributes << JMX::Attribute.new(name, type, description, true, false).to_jmx
     attr_reader name
     #create a "java" oriented accessor method
@@ -164,12 +167,12 @@
       attribute = javax.management.Attribute.new(name.to_s, value)
     end
   end
+  
   # the <tt>w_attribute</tt> method is used to declare a JMX write only attribute.
   # see the +JavaSimpleTypes+ module for more information about acceptable types
   # usage: 
   #  w_attribute :attribute_name, :string, "Description displayed in a JMX console"
   def self.w_attribute(name, type, description)
-    include DynamicMBean        
     attributes << JMX::Attribute.new(name, type, description, false, true).to_jmx
     attr_writer name
     define_method("jmx_set_#{name.to_s.downcase}") do |value|
@@ -187,7 +190,6 @@
   # Last operation wins if more than one
   #++
   def self.operation(description)
-    include DynamicMBean
 
     # Wait to error check until method_added so we can know method name
     Thread.current[:op] = JMX::Operation.new description

Modified: trunk/jmx/lib/jmx/version.rb (1133 => 1134)


--- trunk/jmx/lib/jmx/version.rb	2008-11-16 07:15:59 UTC (rev 1133)
+++ trunk/jmx/lib/jmx/version.rb	2008-11-19 14:12:26 UTC (rev 1134)
@@ -1,3 +1,3 @@
 module JMX
-  VERSION = "0.2"
+  VERSION = "0.3"
 end

Modified: trunk/jmx/lib/jmx.rb (1133 => 1134)


--- trunk/jmx/lib/jmx.rb	2008-11-16 07:15:59 UTC (rev 1133)
+++ trunk/jmx/lib/jmx.rb	2008-11-19 14:12:26 UTC (rev 1134)
@@ -6,9 +6,9 @@
 
 import java.util.ArrayList
 import javax.management.Attribute
-import javax.management.DynamicMBean
 import javax.management.MBeanInfo
 import javax.management.ObjectName
+import javax.management.DynamicMBean
 
 class ObjectName
   def [](key)

Modified: trunk/jmx/test/jmx_attribute_test.rb (1133 => 1134)


--- trunk/jmx/test/jmx_attribute_test.rb	2008-11-16 07:15:59 UTC (rev 1133)
+++ trunk/jmx/test/jmx_attribute_test.rb	2008-11-19 14:12:26 UTC (rev 1134)
@@ -1,11 +1,8 @@
-
 $:.unshift File.join(File.dirname(__FILE__),'..','lib')
 
 require 'test/unit'
-require 'rmi'
 require 'jmx'
 
-
 class MyAttributeDynamicBean < RubyDynamicMBean
   rw_attribute :name1, :string, "My sample attribute"
   r_attribute :number1, :int, "My sample integer based attribute that is read only"
@@ -23,86 +20,9 @@
   end
 end
 
-class JMXAttributeTest < Test::Unit::TestCase
-  
-  def setup
-    @madb = MyAttributeDynamicBean.new("test.MyTestBean","Mwahahahahahah")    
-  end
-  
-  #make sure we didn't break anything from a ruby perspective
-  def test_can_create_bean_and_access_accessor_type_methods
-    @madb.set_number1 4
-    assert_nil(@madb.name1)
-    @madb.name1 = "Name"
-    assert_equal("Name", @madb.name1)
-    assert_equal(4, @madb.number1)
-    @madb.number2 = 4
-    assert_equal(4, @madb.fetch_number2)    
-    assert_raise(NoMethodError) { @madb.number2 }    
-  end
 
-  def test_get_attributes_via_dynamicmbeaninterface
-    @madb.set_number1 4
-    @madb.name1 = "Name"
-
-    assert_equal(@madb.name1, @madb.getAttribute("name1").get_value.to_s)
-    assert_equal(@madb.number1, @madb.getAttribute("number1").get_value)    
-    atts = ["name1", "number1"]
-    retrieved = @madb.getAttributes(atts)
-    assert_equal(2, retrieved.length)
-    #TODO: assertion comparing the types in teh array to java types
-  end
-  
-  def test_set_attributes_via_dynamicbeaninterface
-    @madb.name1 = "blue"
-    red = java.lang.String.new("red")
-    attribute = javax.management.Attribute.new("name1", red)
-    @madb.setAttribute(attribute)
-
-    assert_equal("String", @madb.name1.class.to_s )
-    assert_equal("red", @madb.name1)
-  end
-  
-  def test_set_multiple_attributes_via_dynamicbeaninterface
-    @madb.name1 = "blue"
-    three = java.lang.Integer.new(3)
-    red = java.lang.String.new("red")
-    attribute1 = javax.management.Attribute.new("name1", red)
-    attribute2 = javax.management.Attribute.new("number2", three)
-    
-    @madb.setAttributes([attribute1, attribute2])    
-    assert_equal("red", @madb.name1)
-    assert_equal(3, @madb.fetch_number2)
-  end
-  
-end
-
-$:.unshift File.join(File.dirname(__FILE__),'..','lib')
-
-require 'test/unit'
-require 'rmi'
-require 'jmx'
-
-
-class MyAttributeDynamicBean < RubyDynamicMBean
-  rw_attribute :name1, :string, "My sample attribute"
-  r_attribute :number1, :int, "My sample integer based attribute that is read only"
-  w_attribute :number2, :int, "My sample integer based attribute that is write only"
-
-  def intialize(type, text)
-    super(type,text)
-  end
-  def set_number1(val)
-    @number1 = val
-  end
-  
-  def fetch_number2
-    @number2
-  end
-end
-
 class JMXAttributeTest < Test::Unit::TestCase
-  
+
   def setup
     @madb = MyAttributeDynamicBean.new("test.MyTestBean","Mwahahahahahah")    
   end
@@ -154,3 +74,4 @@
   end
   
 end
+
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to