You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2018/01/05 16:36:00 UTC

[36/50] [abbrv] qpid-proton git commit: PROTON-1720: [ruby] Default messaging adapter for duck-type handlers

PROTON-1720: [ruby] Default messaging adapter for duck-type handlers

Use messaging adapter by default so that handlers don't have to subclass
any particular class - MessagingHandler remains mainly for for documentation.
Raw handlers now implement #proton_adapter_class to return nil.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/813aa432
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/813aa432
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/813aa432

Branch: refs/heads/go1
Commit: 813aa432e8a04ad7f5800e639c0618dfd5ed08ff
Parents: c5351a9
Author: Alan Conway <ac...@redhat.com>
Authored: Mon Dec 18 14:19:39 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Mon Dec 18 14:19:39 2017 -0500

----------------------------------------------------------------------
 .../bindings/ruby/lib/core/messaging_handler.rb |  3 ---
 proton-c/bindings/ruby/lib/handler/adapter.rb   | 27 +++++++++-----------
 .../ruby/tests/test_connection_driver.rb        |  3 +++
 3 files changed, 15 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/813aa432/proton-c/bindings/ruby/lib/core/messaging_handler.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/messaging_handler.rb b/proton-c/bindings/ruby/lib/core/messaging_handler.rb
index 88392f9..fd33661 100644
--- a/proton-c/bindings/ruby/lib/core/messaging_handler.rb
+++ b/proton-c/bindings/ruby/lib/core/messaging_handler.rb
@@ -30,9 +30,6 @@ module Qpid::Proton
   #
   class MessagingHandler
 
-    # @private
-    def proton_adapter_class() Handler::MessagingAdapter; end
-
     # @return [Hash] handler options, see {#initialize}
     attr_reader :options
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/813aa432/proton-c/bindings/ruby/lib/handler/adapter.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/handler/adapter.rb b/proton-c/bindings/ruby/lib/handler/adapter.rb
index fc89b12..66fa285 100644
--- a/proton-c/bindings/ruby/lib/handler/adapter.rb
+++ b/proton-c/bindings/ruby/lib/handler/adapter.rb
@@ -27,21 +27,12 @@ module Qpid::Proton
 
       def initialize(handlers)
         raise "empty handler array" if handlers.empty?
-        adapters = handlers.map do |h|
-          h.__send__(proton_adapter_class) if h.respond_to? :proton_adapter_class
-        end.uniq
+        adapters = (handlers.map { |h| Adapter.adapter(h) }).uniq
         raise "handler array not uniform, adapters requested: #{adapters}" if adapters.size > 1
-        @proton_adapter_class = htypes[0]
-
-        @options = {}
+        @proton_adapter_class = adapters[0]
         @methods = Set.new
         handlers.each do |h|
-          if h.respond_to?(:options)
-            @options.merge(h.options) do |k, a, b|
-              raise ArgumentError, "handler array has conflicting options for [#{k}]: #{a} != #{b}"
-            end
-          end
-          @methods.merge(h.methods.select { |m| handler_method? m }) # Event handler methods
+          @methods.merge(h.methods.select { |m| handler_method? m }) # Collect handler methods
         end
       end
 
@@ -63,16 +54,22 @@ module Qpid::Proton
     class Adapter
       def initialize(h) @handler = h; end
 
-      def adapter_class(h) nil; end # Adapters don't need adapting
-
       # Create and return an adapter for handler, or return h if it does not need adapting.
       def self.adapt(handler)
         return unless handler
         a = Array(handler)
         h = (a.size == 1) ? a[0] : ArrayHandler.new(a)
-        a = h.respond_to?(:proton_adapter_class) ? h.proton_adapter_class.new(handler) : h
+        ac = adapter(h)
+        ac ? ac.new(h) : h
       end
 
+      # Adapter class if requested by handler, else default to MessagingHandler
+      def self.adapter(handler)
+        handler.respond_to?(:proton_adapter_class) ? handler.proton_adapter_class : MessagingAdapter
+      end
+
+      def proton_adapter_class() nil; end # Adapters don't need adapting
+
       def forward(method, *args)
         (@handler.__send__(method, *args); true) if @handler.respond_to? method
       end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/813aa432/proton-c/bindings/ruby/tests/test_connection_driver.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/test_connection_driver.rb b/proton-c/bindings/ruby/tests/test_connection_driver.rb
index d8cce2a..ebe6b53 100644
--- a/proton-c/bindings/ruby/tests/test_connection_driver.rb
+++ b/proton-c/bindings/ruby/tests/test_connection_driver.rb
@@ -26,6 +26,7 @@ class RawDriverTest < Minitest::Test
   # Raw handler to record all on_xxx calls
   class RecordingHandler
     def initialize() @calls =[]; end
+    def proton_adapter_class() nil; end # Raw adapter
     attr_reader :calls
 
     def method_missing(name, *args) respond_to_missing?(name) ? @calls << name : super; end
@@ -35,6 +36,7 @@ class RawDriverTest < Minitest::Test
 
   def test_send_recv
     send_class = Class.new do
+      def proton_adapter_class() nil; end # Raw adapter
       attr_reader :outcome
       def on_link_flow(event) event.sender.send Message.new("foo"); end
       def on_delivery(event)
@@ -44,6 +46,7 @@ class RawDriverTest < Minitest::Test
     end
 
     recv_class = Class.new do
+      def proton_adapter_class() nil; end # Raw adapter
       attr_reader :message
       def on_connection_remote_open(event) event.context.open; end
       def on_session_remote_open(event) event.context.open; end


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org