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 2017/11/30 21:42:41 UTC

[10/12] qpid-proton git commit: PROTON-1064: [ruby] tidy up delivery/dispolsition

PROTON-1064: [ruby] tidy up delivery/dispolsition

- Move constants to DeliveryState module
- Include DeliveryState constants in Delivery and Disposition
- Move Acking module methods to Delivery


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

Branch: refs/heads/master
Commit: db1cb9f125b74dc18a45e99115cfeeea386b16d8
Parents: de2d490
Author: Alan Conway <ac...@redhat.com>
Authored: Wed Nov 22 15:41:30 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Thu Nov 30 16:36:26 2017 -0500

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/delivery.rb     | 48 ++++++-----
 proton-c/bindings/ruby/lib/core/disposition.rb  | 33 +++++---
 proton-c/bindings/ruby/lib/core/receiver.rb     |  2 +-
 proton-c/bindings/ruby/lib/handler/acking.rb    | 70 ----------------
 .../lib/handler/incoming_message_handler.rb     |  2 -
 proton-c/bindings/ruby/lib/qpid_proton.rb       |  4 +-
 proton-c/bindings/ruby/lib/util/constants.rb    | 85 --------------------
 7 files changed, 46 insertions(+), 198 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db1cb9f1/proton-c/bindings/ruby/lib/core/delivery.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/delivery.rb b/proton-c/bindings/ruby/lib/core/delivery.rb
index 47b23d6..bb33207 100644
--- a/proton-c/bindings/ruby/lib/core/delivery.rb
+++ b/proton-c/bindings/ruby/lib/core/delivery.rb
@@ -38,6 +38,8 @@ module Qpid::Proton
   #
   class Delivery
 
+    include DeliveryState
+
     # @private
     include Util::Wrapper
 
@@ -121,14 +123,28 @@ module Qpid::Proton
     #
     proton_caller :settled?
 
+    # Update the state of the delivery
+    # @param state [Integer] the delivery state, defined in {DeliveryState}
+    def update(state) Cproton.pn_delivery_update(@impl, state); end
 
-    # @!method settle
-    #
-    # Settles a delivery.
-    #
-    #  A settled delivery can never be used again.
-    #
-    proton_caller :settle
+    # Settle a delivery, optionally update state before settling
+    # A settled delivery can never be used again.
+    # @param state [Integer] the delivery state, defined in {DeliveryState}
+    def settle(state = nil)
+      update(state) unless state.nil?
+      Cproton.pn_delivery_settle(@impl)
+    end
+
+    # Accept the receiveed message.
+    def accept() settle ACCEPTED; end
+
+    # Reject a received message that is considered invalid.
+    def reject() settle REJECTED; end
+
+    # FIXME aconway 2017-11-23: why the delivered argument?
+
+    # Release a received message making it available to other receivers.
+    def release(delivered = true) settle(delivered ? MODIFIED : RELEASED); end
 
     # @!method dump
     #
@@ -148,14 +164,6 @@ module Qpid::Proton
     #
     proton_caller :buffered?
 
-    def update(state)
-      impl = @local.impl
-      Codec::Data.from_object(Cproton.pn_disposition_data(impl), @local.data)
-      Codec::Data::from_object(Cproton.pn_disposition_annotations(impl), @local.annotations)
-      Condition.from_object(Cproton.pn_disposition_condition(impl), @local.condition)
-      Cproton.pn_delivery_update(@impl, state)
-    end
-
     # Returns the local disposition state for the delivery.
     #
     # @return [Disposition] The local disposition state.
@@ -172,16 +180,6 @@ module Qpid::Proton
       Cproton.pn_delivery_remote_state(@impl)
     end
 
-    # Returns the next delivery on the connection that has pending operations.
-    #
-    # @return [Delivery, nil] The next delivery, or nil if there are none.
-    #
-    # @see Connection#work_head
-    #
-    def work_next
-      Delivery.wrap(Cproton.pn_work_next(@impl))
-    end
-
     # Returns the parent link.
     #
     # @return [Link] The parent link.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db1cb9f1/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 37f94a5..1f2c7fd 100644
--- a/proton-c/bindings/ruby/lib/core/disposition.rb
+++ b/proton-c/bindings/ruby/lib/core/disposition.rb
@@ -19,6 +19,26 @@
 
 module Qpid::Proton
 
+  # States of a delivery
+  module DeliveryState
+    # Message was successfully processed by the receiver
+    ACCEPTED = Cproton::PN_ACCEPTED
+
+    # Message rejected as invalid and unprocessable by the receiver.
+    REJECTED = Cproton::PN_REJECTED
+
+    # Message was not (and will not be) processed by the receiver, but may be
+    # acceptable if re-delivered to another receiver
+    RELEASED = Cproton::PN_RELEASED
+
+    # Like released, but the disposition includes modifications to be made to
+    # the message before re-delivery
+    MODIFIED = Cproton::PN_MODIFIED
+
+    # Partial message data was received, message can be resuemed - used only during link recovery.
+    RECEIVED =  Cproton::PN_RECEIVED
+  end
+
   # Disposition records the current state and/or final outcome of a transfer.
   #
   # Every delivery contains both a local and a remote disposition. The local
@@ -27,18 +47,7 @@ module Qpid::Proton
   #
   class Disposition
 
-    include Util::Constants
-
-    # Indicates the delivery was received.
-    self.add_constant(:RECEIVED, Cproton::PN_RECEIVED)
-    # Indicates the delivery was accepted.
-    self.add_constant(:ACCEPTED, Cproton::PN_ACCEPTED)
-    # Indicates the delivery was rejected.
-    self.add_constant(:REJECTED, Cproton::PN_REJECTED)
-    # Indicates the delivery was released.
-    self.add_constant(:RELEASED, Cproton::PN_RELEASED)
-    # Indicates the delivery was modified.
-    self.add_constant(:MODIFIED, Cproton::PN_MODIFIED)
+    include DeliveryState
 
     attr_reader :impl
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db1cb9f1/proton-c/bindings/ruby/lib/core/receiver.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/receiver.rb b/proton-c/bindings/ruby/lib/core/receiver.rb
index 2be36ab..df767e2 100644
--- a/proton-c/bindings/ruby/lib/core/receiver.rb
+++ b/proton-c/bindings/ruby/lib/core/receiver.rb
@@ -77,7 +77,7 @@ module Qpid::Proton
     # @param limit [Integer] The maximum bytes to receive.
     #
     # @return [Integer, nil] The number of bytes received, or nil if the end of
-    # the stream was reached.t
+    # the stream was reached.
     #
     # @see Deliver#pending To see how much buffer space is needed.
     #

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db1cb9f1/proton-c/bindings/ruby/lib/handler/acking.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/handler/acking.rb b/proton-c/bindings/ruby/lib/handler/acking.rb
deleted file mode 100644
index 1c4f69d..0000000
--- a/proton-c/bindings/ruby/lib/handler/acking.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-#--
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#++
-
-module Qpid::Proton::Handler
-
-  # Mixing that provides methods for acknowledging a delivery.
-  #
-  module Acking
-
-    # Accept the receivered message.
-    #
-    # @param delivery [Qpid::Proton::Delivery] The delivery.
-    #
-    def accept(delivery)
-      self.settle(delivery, Qpid::Proton::Delivery::ACCEPTED)
-    end
-
-    # Rejects a received message that is considered invalid or unprocessable.
-    #
-    # @param delivery [Qpid::Proton::Delivery] The delivery.
-    #
-    def reject(delivery)
-      self.settle(delivery, Qpid::Proton::Delivery::REJECTED)
-    end
-
-    # Releases a received message, making it available at the source for any
-    # other interested receiver.
-    #
-    # @param delivery [Qpid::Proton::Delivery] The delivery
-    # @param delivered [Boolean] True if this was considered a delivery
-    #   attempt.
-    #
-    def release(delivery, delivered = true)
-      if delivered
-        self.settle(delivery, Qpid::Proton::Delivery::MODIFIED)
-      else
-        self.settle(delivery, Qpid::Proton::Delivery::RELEASED)
-      end
-    end
-
-    # Settles the specified delivery. Updates the delivery state if a state
-    # is specified.
-    #
-    # @param delivery [Qpid::Proton::Delivery] The delivery.
-    # @param state [Integer] The delivery state.
-    #
-    def settle(delivery, state = nil)
-      delivery.update(state) unless state.nil?
-      delivery.settle
-    end
-
-  end
-
-end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db1cb9f1/proton-c/bindings/ruby/lib/handler/incoming_message_handler.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/handler/incoming_message_handler.rb b/proton-c/bindings/ruby/lib/handler/incoming_message_handler.rb
index a64cffc..db0f6db 100644
--- a/proton-c/bindings/ruby/lib/handler/incoming_message_handler.rb
+++ b/proton-c/bindings/ruby/lib/handler/incoming_message_handler.rb
@@ -24,8 +24,6 @@ module Qpid::Proton::Handler
   #
   class IncomingMessageHandler
 
-    include Acking
-
     def initialize(auto_accept = true, delegate = nil)
       @delegate = delegate
       @auto_accept = auto_accept

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db1cb9f1/proton-c/bindings/ruby/lib/qpid_proton.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/qpid_proton.rb b/proton-c/bindings/ruby/lib/qpid_proton.rb
index 4a1f677..b47b863 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -28,7 +28,7 @@ else
 end
 
 DEPRECATION = "[DEPRECATION]"
-def deprecated(old, new)
+def deprecated(old, new=nil)
   repl = new ? ", use `#{new}`" : "with no replacement"
   warn "#{DEPRECATION} `#{old}` is deprecated #{repl} (called from #{caller(2).first})"
 end
@@ -39,7 +39,6 @@ require "core/exceptions"
 # Utility classes
 require "util/version"
 require "util/error_handler"
-require "util/constants"
 require "util/swig_helper"
 require "util/wrapper"
 require "util/class_wrapper"
@@ -92,7 +91,6 @@ require "messenger/messenger"
 # Handler classes
 require "handler/c_adaptor"
 require "handler/wrapped_handler"
-require "handler/acking"
 require "handler/endpoint_state_handler"
 require "handler/incoming_message_handler"
 require "handler/outgoing_message_handler"

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/db1cb9f1/proton-c/bindings/ruby/lib/util/constants.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/util/constants.rb b/proton-c/bindings/ruby/lib/util/constants.rb
deleted file mode 100644
index 50225e6..0000000
--- a/proton-c/bindings/ruby/lib/util/constants.rb
+++ /dev/null
@@ -1,85 +0,0 @@
-#--
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#++
-
-module Qpid::Proton::Util
-
-  # Provides a means for defining constant values within the namespace
-  # of a class.
-  #
-  # If the class has defined the class method, :post_add_constant, then that
-  # method will be invoked after each new item is added. It must be defined
-  # *before* any constants are defined.
-  #
-  # ==== Example
-  #
-  #   class GrammarComponent
-  #
-  #     include Qpid::Proton::Constants
-  #
-  #     def self.post_add_constant(key, value)
-  #       @terminal << value if value.terminal?
-  #       @nonterminal << value if !value.terminal? && !value.rule
-  #       @rule << value if value.rule
-  #     end
-  #
-  #     self.add_constant :LEFT_PARENTHESIS, new GrammarComponent("(", :terminal)
-  #     self.add_constant :RIGHT_PARENTHESIS, new GrammarComponent(")", :terminal)
-  #     self.add_constant :ELEMENT, new GrammarComponent("E", :rule)
-  #
-  #     def initialize(component, type)
-  #       @component = component
-  #       @type = type
-  #     end
-  #
-  #     def terminal?; @type == :terminal; end
-  #
-  #     def rule?; @type == :rule; end
-  #
-  #   end
-  #
-  # @private
-  #
-  module Constants
-
-    def self.included(base)
-      base.extend ClassMethods
-    end
-
-    module ClassMethods
-
-      def add_constant(key, value)
-        self.const_set(key, value)
-
-        @pn_by_value ||= {}
-        @pn_by_value[value] = key
-
-        if self.respond_to? :post_add_constant
-          self.post_add_constant(key, value)
-        end
-      end
-
-      def by_value(value)
-        (@pn_by_value || {})[value]
-      end
-
-    end
-
-  end
-
-end


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