qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [12/12] qpid-proton git commit: PROTON-1064: [ruby] consistent handling of conditions and exceptions
Date Thu, 30 Nov 2017 21:42:43 GMT
PROTON-1064: [ruby] consistent handling of conditions and exceptions


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

Branch: refs/heads/master
Commit: c4e5e58cd87aff704fc71c4c7b3c1d006de17f1b
Parents: db1cb9f
Author: Alan Conway <aconway@redhat.com>
Authored: Tue Nov 28 09:52:59 2017 -0500
Committer: Alan Conway <aconway@redhat.com>
Committed: Thu Nov 30 16:36:26 2017 -0500

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/condition.rb    | 32 ++++++++++++++------
 proton-c/bindings/ruby/lib/core/connection.rb   |  2 +-
 .../bindings/ruby/lib/core/connection_driver.rb |  2 +-
 proton-c/bindings/ruby/lib/core/container.rb    |  2 +-
 proton-c/bindings/ruby/lib/core/disposition.rb  |  2 +-
 proton-c/bindings/ruby/lib/core/endpoint.rb     |  4 +--
 proton-c/bindings/ruby/lib/core/listener.rb     |  2 +-
 proton-c/bindings/ruby/lib/core/transport.rb    |  4 +--
 proton-c/bindings/ruby/lib/event/event.rb       |  5 +++
 9 files changed, 36 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c4e5e58c/proton-c/bindings/ruby/lib/core/condition.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/condition.rb b/proton-c/bindings/ruby/lib/core/condition.rb
index b0b8de7..9cd6eec 100644
--- a/proton-c/bindings/ruby/lib/core/condition.rb
+++ b/proton-c/bindings/ruby/lib/core/condition.rb
@@ -19,7 +19,15 @@
 
 module Qpid::Proton
 
-  class Condition
+  # An AMQP error condition.
+  #
+  # An error sent across an AMQP connection has a name, description and optional extra info.
+  # The {Connectin}, {Session} and {Link} endpoint classes all have a #condition method to
+  # check for errors.
+  #
+  # {Condition} can also be raised as an exception.
+  #
+  class Condition < ProtonError
 
     attr_reader :name, :description, :info
 
@@ -27,6 +35,7 @@ module Qpid::Proton
       @name = name
       @description = description
       @info = info
+      super(to_s)
     end
 
     def to_s() "#{@name}: #{@description}"; end
@@ -40,15 +49,16 @@ module Qpid::Proton
        (other.info == self.info))
     end
 
-    # Make a condition.
+    # Convert an object to a condition.
     # @param obj the object to turn into a condition
-    # @param default_name condition name to use if obj does not imply a name
-    # @return
-    # - when Condition return obj unchanged
-    # - when Exception return Condition(obj.class.name, obj.to_s)
-    # - when nil then nil
-    # - else return Condition(default_name, obj.to_s)
-    def self.make(obj, default_name="proton")
+    # @param default_name name to use if obj does not imply a name
+    # @return [Condition] Conversion depends on the type of obj
+    # - Condition: return obj
+    # - Exception: return Condition(obj.class.name, obj.to_s)
+    # - String-like: return String.try_convert(obj)
+    # - nil: return nil
+    # @raise ::ArgumentError if obj is not convertible to {Condition}
+    def self.convert(obj, default_name="proton")
       case obj
       when nil then nil
       when Condition then obj
@@ -59,7 +69,9 @@ module Qpid::Proton
                         Cproton.pn_condition_get_description(obj),
                         Codec::Data.to_object(Cproton.pn_condition_info(obj)))
         end
-      else Condition.new(default_name, obj.to_s)
+      else
+        raise ::ArgumentError, "can't convert #{obj.class.name} to #{self.class.name}" unless
obj.respond_to? :to_str
+        Condition.new(default_name, obj.to_str)
       end
     end
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c4e5e58c/proton-c/bindings/ruby/lib/core/connection.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/connection.rb b/proton-c/bindings/ruby/lib/core/connection.rb
index 318e925..d6ff029 100644
--- a/proton-c/bindings/ruby/lib/core/connection.rb
+++ b/proton-c/bindings/ruby/lib/core/connection.rb
@@ -234,7 +234,7 @@ module Qpid::Proton
     #
     def close(error = nil)
       if error
-        @condition = Condition.make error
+        @condition = Condition.convert error
         self._update_condition
       end
       Cproton.pn_connection_close(@impl)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c4e5e58c/proton-c/bindings/ruby/lib/core/connection_driver.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/connection_driver.rb b/proton-c/bindings/ruby/lib/core/connection_driver.rb
index f757328..aeca133 100644
--- a/proton-c/bindings/ruby/lib/core/connection_driver.rb
+++ b/proton-c/bindings/ruby/lib/core/connection_driver.rb
@@ -144,7 +144,7 @@ module Qpid
       private
 
       def set_error e
-        if cond = Condition.make(e, "proton:io")
+        if cond = Condition.convert(e, "proton:io")
           Cproton.pn_connection_driver_errorf(@impl, cond.name, "%s", cond.description)
         end
       end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c4e5e58c/proton-c/bindings/ruby/lib/core/container.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/container.rb b/proton-c/bindings/ruby/lib/core/container.rb
index 7a4aeb1..28c394f 100644
--- a/proton-c/bindings/ruby/lib/core/container.rb
+++ b/proton-c/bindings/ruby/lib/core/container.rb
@@ -302,7 +302,7 @@ module Qpid::Proton
       @lock.synchronize do
         raise StoppedError if @stopped
         @stopped = true
-        @stop_err = Condition.make(error)
+        @stop_err = Condition.convert(error)
         check_stop_lh
         # NOTE: @stopped =>
         # - no new run threads can join

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c4e5e58c/proton-c/bindings/ruby/lib/core/disposition.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/disposition.rb b/proton-c/bindings/ruby/lib/core/disposition.rb
index 1f2c7fd..2c12345 100644
--- a/proton-c/bindings/ruby/lib/core/disposition.rb
+++ b/proton-c/bindings/ruby/lib/core/disposition.rb
@@ -155,7 +155,7 @@ module Qpid::Proton
       if @local
         @condition
       else
-        Condition.make(Cproton.pn_disposition_condition(@impl))
+        Condition.convert(Cproton.pn_disposition_condition(@impl))
       end
     end
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c4e5e58c/proton-c/bindings/ruby/lib/core/endpoint.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/endpoint.rb b/proton-c/bindings/ruby/lib/core/endpoint.rb
index 7ef18c8..fe2eb7a 100644
--- a/proton-c/bindings/ruby/lib/core/endpoint.rb
+++ b/proton-c/bindings/ruby/lib/core/endpoint.rb
@@ -67,11 +67,11 @@ module Qpid::Proton
     end
 
     def condition
-      Condition.make(_local_condition) || remote_condition; end
+      Condition.convert(_local_condition) || remote_condition; end
 
     # @private
     def remote_condition
-      Condition.make(_remote_condition)
+      Condition.convert(_remote_condition)
     end
 
     # Return the transport associated with this endpoint.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c4e5e58c/proton-c/bindings/ruby/lib/core/listener.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/listener.rb b/proton-c/bindings/ruby/lib/core/listener.rb
index 35dfe20..3feb44b 100644
--- a/proton-c/bindings/ruby/lib/core/listener.rb
+++ b/proton-c/bindings/ruby/lib/core/listener.rb
@@ -65,7 +65,7 @@ module Qpid::Proton
     # @param error [Condition] Optional error condition.
     def close(error=nil)
       @closing = true
-      @condition ||= Condition.make(error) if error
+      @condition ||= Condition.convert error
       @io.close_read rescue nil # Cause listener to wake out of IO.select
       nil
     end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c4e5e58c/proton-c/bindings/ruby/lib/core/transport.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/transport.rb b/proton-c/bindings/ruby/lib/core/transport.rb
index 7b70ffc..7589788 100644
--- a/proton-c/bindings/ruby/lib/core/transport.rb
+++ b/proton-c/bindings/ruby/lib/core/transport.rb
@@ -228,13 +228,13 @@ module Qpid::Proton
 
     # @return [Condition, nil] transport error condition or nil if there is no error.
     def condition
-      Condition.make(Cproton.pn_transport_condition(@impl))
+      Condition.convert(Cproton.pn_transport_condition(@impl))
     end
 
     # Set the error condition for the transport.
     # @param c [Condition] The condition to set
     def condition=(c)
-      Condition.from_object(Cproton.pn_transport_condition(@impl), Condition.make(c))
+      Condition.from_object(Cproton.pn_transport_condition(@impl), Condition.convert(c))
     end
 
     # Binds to the given connection.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/c4e5e58c/proton-c/bindings/ruby/lib/event/event.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/event/event.rb b/proton-c/bindings/ruby/lib/event/event.rb
index 8492b7c..92f7eb7 100644
--- a/proton-c/bindings/ruby/lib/event/event.rb
+++ b/proton-c/bindings/ruby/lib/event/event.rb
@@ -307,6 +307,11 @@ module Qpid::Proton
 
       # @private
       def container=(c); @container = c; end
+
+      # @return The remote error {Condition} or nil if there is none.
+      def condition
+        context.remote_condition if context.respond_to? :remote_condition
+      end
     end
   end
 end


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


Mime
View raw message