Author: mcpierce
Date: Wed Nov 14 20:15:23 2012
New Revision: 1409366
URL: http://svn.apache.org/viewvc?rev=1409366&view=rev
Log:
NO-JIRA: Added support for tracking messages to the Ruby bindings.
Created the Qpid::Proton::Tracker type, which is now returned by the new
methods incoming_tracker and outgoing_tracker.
Adds the ability to accept and reject trackers to the Ruby bindings.
Added:
qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/tracker.rb
- copied, changed from r1409365,
qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb
qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/tracker_status.rb
Modified:
qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb
qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/messenger.rb
qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/messenger_spec.rb
Modified: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb?rev=1409366&r1=1409365&r2=1409366&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb Wed Nov 14
20:15:23 2012
@@ -24,4 +24,6 @@ require "qpid_proton/exceptions"
require "qpid_proton/exception_handling"
require "qpid_proton/message_format"
require "qpid_proton/message"
+require "qpid_proton/tracker_status"
+require "qpid_proton/tracker"
require "qpid_proton/messenger"
Modified: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/messenger.rb
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/messenger.rb?rev=1409366&r1=1409365&r2=1409366&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/messenger.rb
(original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/messenger.rb Wed
Nov 14 20:15:23 2012
@@ -28,6 +28,14 @@ module Qpid
#
class Messenger
+ # Automatically accept every message as it is returned by #get
+ #
+ ACCEPT_MODE_AUTO = Cproton::PN_ACCEPT_MODE_AUTO
+
+ # Messages must be manually accepted or rejected using #accept
+ #
+ ACCEPT_MODE_MANUAL = Cproton::PN_ACCEPT_MODE_MANUAL
+
include Qpid::Proton::ExceptionHandling
# Creates a new +Messenger+.
@@ -235,6 +243,108 @@ module Qpid
Cproton.pn_messenger_incoming(@impl)
end
+ # Returns a +Tracker+ for the message most recently sent via the put
+ # method.
+ #
+ def outgoing_tracker
+ impl = Cproton.pn_messenger_outgoing_tracker(@impl)
+ return nil if impl == -1
+ Qpid::Proton::Tracker.new(impl)
+ end
+
+ # Returns a +Tracker+ for the most recently received message.
+ #
+ def incoming_tracker
+ impl = Cproton.pn_messenger_incoming_tracker(@impl)
+ return nil if impl == -1
+ Qpid::Proton::Tracker.new(impl)
+ end
+
+ # Set the accept mode for the Messenger. See #ACCEPT_MODE_AUTO and
+ # #ACCEPT_MODE_MANUAL for more details
+ #
+ # ==== Options
+ #
+ # * mode - the acceptance mode
+ #
+ # ==== Examples
+ #
+ # @messenger.accept_mode = Qpid::Proton::Messenger::ACCEPT_MODE_AUTO
+ #
+ def accept_mode=(mode)
+ raise TypeError.new("Invalid mode: #{mode}") unless valid_mode?(mode)
+ Cproton.pn_messenger_set_accept_mode(@impl, mode)
+ end
+
+ # Returns the current acceptance mode for the Messenger.
+ #
+ def accept_mode
+ Cproton.pn_messenger_get_accept_mode(@impl)
+ end
+
+ # Accepts the incoming message identified by the tracker.
+ #
+ # ==== Options
+ #
+ # * tracker - the tracker
+ # * flag - the flag
+ #
+ def accept(tracker, flag)
+ raise TypeError.new("invalid tracker: #{tracker}") unless
valid_tracker?(tracker)
+ raise TypeError.new("invalid flag: #{flag}") unless
Qpid::Proton::Tracker.valid_flag?(flag)
+ check_for_error(Cproton.pn_messenger_accept(@impl, tracker.impl, flag))
+ end
+
+ # Rejects the incoming message identified by the tracker.
+ #
+ # ==== Options
+ #
+ # * tracker - the tracker
+ # * flag - the flag
+ #
+ def reject(tracker, flag)
+ raise TypeError.new("invalid tracker: #{tracker}") unless
valid_tracker?(tracker)
+ check_for_error(Cproton.pn_messenger_reject(@impl, tracker.impl, flag))
+ end
+
+ # Gets the last known remote state of the delivery associated with
+ # the given tracker. See TrackerStatus for details on the values
+ # returned.
+ #
+ # ==== Options
+ #
+ # * tracker - the tracker
+ #
+ def status(tracker)
+ raise TypeError.new("invalid tracker: #{tracker}") unless
valid_tracker?(tracker)
+
Qpid::Proton::TrackerStatus.by_value(Cproton.pn_messenger_status(@impl,
tracker.impl))
+ end
+
+ # Settles messages for a tracker.
+ #
+ # ==== Options
+ #
+ # * tracker - the tracker
+ # * flag - the flag
+ #
+ # ==== Examples
+ #
+ def settle(tracker, flag)
+ raise TypeError.new("invalid tracker: #{tracker}") unless
valid_tracker?(tracker)
+ raise TypeError.new("invalid flag: #{flag}") unless
Qpid::Proton::Tracker.valid_flag?(flag)
+ Cproton.pn_messenger_settle(@impl, tracker.impl, flag)
+ end
+
+ private
+
+ def valid_tracker?(tracker)
+ !tracker.nil? && tracker.is_a?(Qpid::Proton::Tracker)
+ end
+
+ def valid_mode?(mode)
+ [ACCEPT_MODE_AUTO, ACCEPT_MODE_MANUAL].include?(mode)
+ end
+
end
end
Copied: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/tracker.rb
(from r1409365, qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb)
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/tracker.rb?p2=qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/tracker.rb&p1=qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb&r1=1409365&r2=1409366&rev=1409366&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/tracker.rb Wed Nov
14 20:15:23 2012
@@ -17,11 +17,30 @@
# under the License.
#
-require "cproton"
+module Qpid
-require "qpid_proton/version"
-require "qpid_proton/exceptions"
-require "qpid_proton/exception_handling"
-require "qpid_proton/message_format"
-require "qpid_proton/message"
-require "qpid_proton/messenger"
+ module Proton
+
+ # A +Tracker+ is used to track the disposition of a +Message+.
+ #
+ class Tracker
+
+ CUMULATIVE = Cproton::PN_CUMULATIVE
+
+ def initialize(impl) # :nodoc:
+ @impl = impl
+ end
+
+ def impl # :nodoc:
+ @impl
+ end
+
+ def self.valid_flag?(flag) # :nodoc:
+ [0, CUMULATIVE].include?(flag)
+ end
+
+ end
+
+ end
+
+end
Added:
qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/tracker_status.rb
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/tracker_status.rb?rev=1409366&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/tracker_status.rb
(added)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/tracker_status.rb
Wed Nov 14 20:15:23 2012
@@ -0,0 +1,72 @@
+#
+# 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
+
+ module Proton
+
+ # TrackerStatus contains symbols that represent the status value for a
+ # Tracker.
+ #
+ class TrackerStatus
+
+ def initialize value, name # :nodoc:
+ @value = value
+ @name = name
+ end
+
+ def value # :nodoc:
+ @value
+ end
+
+ def to_s # :nodoc:
+ @name.to_s
+ end
+
+ def self.by_name(name) # :nodoc:
+ @by_name[name.to_sym] unless name.nil?
+ end
+
+ def self.by_value(value) # :nodoc:
+ @by_value[value] unless value.nil?
+ end
+
+ private
+
+ def self.add_item(key, value) # :nodoc:
+ @by_name ||= {}
+ @by_name[key] = TrackerStatus.new value, key
+ @by_value ||= {}
+ @by_value[value] = @by_name[key]
+ end
+
+ def self.const_missing(key) # :nodoc:
+ @by_name[key]
+ end
+
+ self.add_item :UNKNOWN, Cproton::PN_STATUS_UNKNOWN
+ self.add_item :PENDING, Cproton::PN_STATUS_PENDING
+ self.add_item :ACCEPTED, Cproton::PN_STATUS_ACCEPTED
+ self.add_item :REJECTED, Cproton::PN_STATUS_REJECTED
+
+ end
+
+ end
+
+end
Modified:
qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/messenger_spec.rb
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/messenger_spec.rb?rev=1409366&r1=1409365&r2=1409366&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/messenger_spec.rb
(original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/spec/qpid/proton/messenger_spec.rb
Wed Nov 14 20:15:23 2012
@@ -152,6 +152,31 @@ module Qpid
@messenger.trusted_certificates.should eq(certs)
end
+ it "raises an error when setting a nil accept mode" do
+ expect {
+ @messenger.accept_mode = nil
+ }.to raise_error(TypeError)
+ end
+
+ it "raises an error when setting an invalid accept mode" do
+ mode = random_string(16)
+ expect {
+ @messenger.accept_mode = mode
+ }.to raise_error(TypeError)
+ end
+
+ it "can have an automatic acceptance mode" do
+ mode = Qpid::Proton::Messenger::ACCEPT_MODE_AUTO
+ @messenger.accept_mode = mode
+ @messenger.accept_mode.should equal(mode)
+ end
+
+ it "can have a manual acceptance mode" do
+ mode = Qpid::Proton::Messenger::ACCEPT_MODE_MANUAL
+ @messenger.accept_mode = mode
+ @messenger.accept_mode.should equal(mode)
+ end
+
describe "once started" do
before (:each) do
@@ -172,6 +197,24 @@ module Qpid
}.to_not raise_error
end
+ it "does not return a tracker before sending messages" do
+ @messenger.outgoing_tracker.should be_nil
+ end
+
+ it "returns a tracker's status"
+
+ it "raises an error when settling with a nil flag" do
+ expect {
+ @messenger.settle(@tracker, nil)
+ }.to raise_error(TypeError)
+ end
+
+ it "raises an error when settling with an invalid flag" do
+ expect {
+ @messenger.settle(@tracker, rand(256) + 2)
+ }.to raise_error(TypeError)
+ end
+
describe "and subscribed to an address" do
before (:each) do
@@ -220,6 +263,113 @@ module Qpid
it "can send with an empty queue"
+ describe "with a an outgoing tracker" do
+
+ before(:each) do
+ @messenger.put(@msg)
+ @tracker = @messenger.outgoing_tracker
+ end
+
+ it "has an outgoing tracker" do
+ @tracker.should_not be_nil
+ end
+
+ it "returns a tracker's status"
+
+ it "raises an error when settling with a nil tracker" do
+ expect {
+ @messenger.settle(nil, Qpid::Proton::Tracker::CUMULATIVE)
+ }.to raise_error(TypeError)
+ end
+
+ it "raises an error when settling with a nil flag" do
+ expect {
+ @messenger.settle(@tracker, nil)
+ }.to raise_error(TypeError)
+ end
+
+ it "raises an error when settling with an invalid flag" do
+ expect {
+ @messenger.settle(@tracker, "farkle")
+ }.to raise_error(TypeError)
+ end
+
+ it "can settle a tracker's status" do
+ @messenger.settle(@tracker, Qpid::Proton::Tracker::CUMULATIVE)
+ end
+
+ it "raises an error when checking status on a nil tracker" do
+ expect {
+ @messenger.status(nil)
+ }.to raise_error(TypeError)
+ end
+
+ it "raises an error when checking status on an invalid tracker" do
+ expect {
+ @messenger.status(random_string(16))
+ }.to raise_error(TypeError)
+ end
+
+ it "can check the status of a tracker" do
+ @messenger.status(@tracker).should_not be_nil
+ end
+
+ end
+
+ it "has a nil incoming tracker when no messages are received" do
+ @messenger.incoming_tracker.should be_nil
+ end
+
+ it "has an incoming tracker"
+
+ it "raises an error when rejecting with a nil flag" do
+ expect {
+ @messenger.accept(@tracker, nil)
+ }.to raise_error(TypeError)
+ end
+
+ it "raises an error when rejecting with an invalid flag" do
+ flag = -1
+ expect {
+ @messenger.accept(@tracker, flag)
+ }.to raise_error(TypeError)
+ end
+
+ it "can reject an incoming message"
+
+ it "raises an error when accepting with a nil tracker" do
+ expect {
+ @messenger.reject(nil, Qpid::Proton::Tracker::CUMULATIVE)
+ }.to raise_error(TypeError)
+ end
+
+ it "raises an error when accepting with an invalid tracker" do
+ expect {
+ @messenger.accept(random_string(16),
Qpid::Proton::Tracker::CUMULATIVE)
+ }.to raise_error(TypeError)
+ end
+
+ it "raises an error when accepting with a nil flag" do
+ expect {
+ @messenger.accept(@tracker, nil)
+ }.to raise_error(TypeError)
+ end
+
+ it "raises an error when accepting with an invalid flag"
+ it "can accept a message"
+
+ it "raises an error when rejecting with a nil tracker" do
+ expect {
+ @messenger.accept(nil, Qpid::Proton::Tracker::CUMULATIVE)
+ }.to raise_error(TypeError)
+ end
+
+ it "raises an error when rejecting with an invalid tracker" do
+ expect {
+ @messenger.accept(random_string(16),
Qpid::Proton::Tracker::CUMULATIVE)
+ }.to raise_error(TypeError)
+ end
+
describe "with messages sent" do
before (:each) do
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]