You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by mc...@apache.org on 2015/06/18 16:03:36 UTC

[29/50] qpid-proton git commit: PROTON-781: Added IncomingMessageHandler to the Ruby reactive APIs.

PROTON-781: Added IncomingMessageHandler to the Ruby reactive APIs.


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

Branch: refs/heads/PROTON-781-ruby-reactor-apis
Commit: e165313d7cf85a6d5fdaf5cd3072a0f56c337df5
Parents: afdef67
Author: Darryl L. Pierce <mc...@gmail.com>
Authored: Thu Feb 26 09:23:00 2015 -0500
Committer: Darryl L. Pierce <mc...@gmail.com>
Committed: Thu Jun 18 09:27:20 2015 -0400

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/exceptions.rb   | 10 +++
 .../lib/handler/incoming_message_handler.rb     | 74 ++++++++++++++++++++
 proton-c/bindings/ruby/lib/qpid_proton.rb       |  1 +
 3 files changed, 85 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e165313d/proton-c/bindings/ruby/lib/core/exceptions.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/exceptions.rb b/proton-c/bindings/ruby/lib/core/exceptions.rb
index 94d2957..75d6552 100644
--- a/proton-c/bindings/ruby/lib/core/exceptions.rb
+++ b/proton-c/bindings/ruby/lib/core/exceptions.rb
@@ -111,6 +111,16 @@ module Qpid
     class SSLUnavailableError < SSLError
     end
 
+    # Raised when a message is rejected.
+    #
+    class Reject < ProtonError
+    end
+
+    # Raised when a message is released.
+    #
+    class Release < ProtonError
+    end
+
   end
 
 end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e165313d/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
new file mode 100644
index 0000000..ced84a2
--- /dev/null
+++ b/proton-c/bindings/ruby/lib/handler/incoming_message_handler.rb
@@ -0,0 +1,74 @@
+#--
+# 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
+
+  # A utility for simpler and more intuitive handling of delivery events
+  # related to incoming messages.
+  #
+  class IncomingMessageHandler < Qpid::Proton::BaseHandler
+
+    include Acking
+
+    def initialize(auto_accept = true, delegate = nil)
+      @delegate = delegate
+      @auto_accept = auto_accept
+    end
+
+    def on_delivery(event)
+      delivery = event.delivery
+      return unless delivery.link.receiver?
+      if delivery.readable? && !delivery.partial?
+        event.message = Qpid::Proton::Util::Engine.receive_message(delivery)
+        if event.link.local_closed?
+          if @auto_accept
+            delivery.update(Qpid::Proton::Disposition::RELEASED)
+            delivery.settle
+          end
+        else
+          begin
+            self.on_message(event)
+            if @auto_accept
+              delivery.update(Qpid::Proton::Disposition::ACCEPTED)
+              delivery.settle
+            end
+          rescue Qpid::Proton::Reject
+            delivery.update(Qpid::Proton::Disposition::REJECTED)
+            delivery.settle
+          rescue Qpid::Proton::Release
+            delivery.update(Qpid::Proton::Disposition::MODIFIED)
+            delivery.settle
+          end
+        end
+      elsif delivery.updated? && delivery.settled?
+        self.on_settled(event)
+      end
+    end
+
+    def on_message(event)
+      Qpid::Proton::Event.dispatch(@delegate, :on_message, event) if !@delegate.nil?
+    end
+
+    def on_settled(event)
+      Qpid::Proton::Event.dispatch(@delegate, :on_settled, event) if !@delegate.nil?
+    end
+
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e165313d/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 ef7f300..1fbf710 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -87,6 +87,7 @@ require "handler/c_adaptor"
 require "handler/wrapped_handler"
 require "handler/acking"
 require "handler/endpoint_state_handler"
+require "handler/incoming_message_handler"
 require "handler/c_flow_controller"
 
 module Qpid::Proton


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