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/07 19:26:49 UTC
[07/10] qpid-proton git commit: PROTON-1064: [ruby] Pass options to
open connections/sessions/links
PROTON-1064: [ruby] Pass options to open connections/sessions/links
Consistent option passing to endpoints
Minor cleanup:
- Removed UUID class, use standard library
- Fixed ruby code that was out of date with C library.
- Remove dead code.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/b3d1b074
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/b3d1b074
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/b3d1b074
Branch: refs/heads/master
Commit: b3d1b0742225b53ea2c4d950cc62788584d62f3c
Parents: 3d25815
Author: Alan Conway <ac...@redhat.com>
Authored: Mon Sep 18 22:34:42 2017 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Tue Nov 7 13:31:51 2017 -0500
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/codec/data.rb | 4 +-
proton-c/bindings/ruby/lib/codec/mapping.rb | 29 ++--
proton-c/bindings/ruby/lib/core/connection.rb | 79 ++++++-----
proton-c/bindings/ruby/lib/core/session.rb | 54 ++++----
proton-c/bindings/ruby/lib/core/terminus.rb | 8 +-
proton-c/bindings/ruby/lib/core/transport.rb | 10 ++
proton-c/bindings/ruby/lib/core/url.rb | 4 +-
proton-c/bindings/ruby/lib/event/collector.rb | 2 +-
proton-c/bindings/ruby/lib/qpid_proton.rb | 1 -
proton-c/bindings/ruby/lib/reactor/backoff.rb | 10 +-
proton-c/bindings/ruby/lib/reactor/connector.rb | 8 +-
proton-c/bindings/ruby/lib/reactor/container.rb | 134 ++++++-------------
.../bindings/ruby/lib/reactor/link_option.rb | 13 +-
proton-c/bindings/ruby/lib/util/uuid.rb | 32 -----
proton-c/bindings/ruby/spec/array_spec.rb | 2 +-
proton-c/bindings/ruby/tests/test_smoke.rb | 64 ---------
16 files changed, 170 insertions(+), 284 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/lib/codec/data.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/codec/data.rb b/proton-c/bindings/ruby/lib/codec/data.rb
index afd4e31..be13512 100644
--- a/proton-c/bindings/ruby/lib/codec/data.rb
+++ b/proton-c/bindings/ruby/lib/codec/data.rb
@@ -849,10 +849,10 @@ module Qpid::Proton::Codec
# Puts a symbolic value.
#
- # @param value [String] The symbolic string value.
+ # @param value [String|Symbol] The symbolic string value.
#
def symbol=(value)
- check(Cproton.pn_data_put_symbol(@data, value))
+ check(Cproton.pn_data_put_symbol(@data, value.to_s))
end
# If the current node is a symbol, returns its value. Otherwise, it
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/lib/codec/mapping.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/codec/mapping.rb b/proton-c/bindings/ruby/lib/codec/mapping.rb
index 421aadc..5a498b4 100644
--- a/proton-c/bindings/ruby/lib/codec/mapping.rb
+++ b/proton-c/bindings/ruby/lib/codec/mapping.rb
@@ -105,11 +105,18 @@ module Qpid::Proton::Codec
DECIMAL128 = Mapping.new(Cproton::PN_DECIMAL128, "decimal128")
UUID = Mapping.new(Cproton::PN_UUID, "uuid")
BINARY = Mapping.new(Cproton::PN_BINARY, "binary")
- STRING = Mapping.new(Cproton::PN_STRING, "string", [String, Symbol,
+ STRING = Mapping.new(Cproton::PN_STRING, "string", [::String,
Qpid::Proton::Types::UTFString,
Qpid::Proton::Types::BinaryString])
+ SYMBOL = Mapping.new(Cproton::PN_SYMBOL, "symbol", [::Symbol])
+ DESCRIBED = Mapping.new(Cproton::PN_DESCRIBED, "described", [Qpid::Proton::Types::Described], "get_described")
+ ARRAY = Mapping.new(Cproton::PN_ARRAY, "array", nil, "get_array")
+ LIST = Mapping.new(Cproton::PN_LIST, "list", [::Array], "get_array")
+ MAP = Mapping.new(Cproton::PN_MAP, "map", [::Hash], "get_map")
+
+
+ private
- # @private
class << STRING
def put(data, value)
# if we have a symbol then convert it to a string
@@ -134,17 +141,9 @@ module Qpid::Proton::Codec
data.string = value if isutf
data.binary = value if !isutf
-
end
end
- SYMBOL = Mapping.new(Cproton::PN_SYMBOL, "symbol")
- DESCRIBED = Mapping.new(Cproton::PN_DESCRIBED, "described", [Qpid::Proton::Types::Described], "get_described")
- ARRAY = Mapping.new(Cproton::PN_ARRAY, "array", nil, "get_array")
- LIST = Mapping.new(Cproton::PN_LIST, "list", [::Array], "get_array")
- MAP = Mapping.new(Cproton::PN_MAP, "map", [::Hash], "get_map")
-
- # @private
class << MAP
def put(data, map, options = {})
data.put_map
@@ -166,4 +165,14 @@ module Qpid::Proton::Codec
end
end
+ class << DESCRIBED
+ def put(data, described)
+ data.put_described
+ data.enter
+ data.object = described.descriptor
+ data.object = described.value
+ data.exit
+ end
+ end
+
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/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 784b193..ef785b2 100644
--- a/proton-c/bindings/ruby/lib/core/connection.rb
+++ b/proton-c/bindings/ruby/lib/core/connection.rb
@@ -19,15 +19,14 @@
module Qpid::Proton
- # A Connection has at most one Qpid::Proton::Transport instance.
- #
+ # An AMQP connection.
class Connection < Endpoint
- # @private
+ protected
+ PROTON_METHOD_PREFIX = "pn_connection"
include Util::SwigHelper
- # @private
- PROTON_METHOD_PREFIX = "pn_connection"
+ public
# @!attribute hostname
#
@@ -45,8 +44,6 @@ module Qpid::Proton
proton_writer :password
# @private
- proton_reader :attachments
-
attr_accessor :overrides
attr_accessor :session_policy
@@ -127,15 +124,10 @@ module Qpid::Proton
@collector = collector
end
- # Get the AMQP container name advertised by the remote connection
- # endpoint.
+ # Get the AMQP container name advertised by the remote connection.
#
# This will return nil until the REMOTE_ACTIVE state is reached.
#
- # Any non-nil container returned by this operation will be valid
- # until the connection is unbound from a transport, or freed,
- # whichever happens sooner.
- #
# @return [String] The remote connection's AMQP container name.
#
# @see #container
@@ -144,11 +136,8 @@ module Qpid::Proton
Cproton.pn_connection_remote_container(@impl)
end
- def container=(name)
- Cproton.pn_connection_set_container(@impl, name)
- end
-
- def container
+ # AMQP container ID string for the local end of the connection.
+ def container_id
Cproton.pn_connection_get_container(@impl)
end
@@ -204,18 +193,28 @@ module Qpid::Proton
data_to_object(Cproton.pn_connection_remote_properites(@impl))
end
- # Opens the connection.
+ # Open the local end of the connection.
+ #
+ # @option options [String] :container_id Unique AMQP container ID, defaults to a UUID
+ # @option [String] :link_prefix Prefix for generated link names, default is container_id
#
- def open
- object_to_data(@offered_capabilities,
- Cproton.pn_connection_offered_capabilities(@impl))
- object_to_data(@desired_capabilities,
- Cproton.pn_connection_desired_capabilities(@impl))
- object_to_data(@properties,
- Cproton.pn_connection_properties(@impl))
+ def open(options={})
+ object_to_data(@offered_capabilities, Cproton.pn_connection_offered_capabilities(@impl))
+ object_to_data(@desired_capabilities, Cproton.pn_connection_desired_capabilities(@impl))
+ object_to_data(@properties, Cproton.pn_connection_properties(@impl))
+ cid = options[:container_id] || SecureRandom.uuid
+ Cproton.pn_connection_set_container(@impl, cid)
+ @link_prefix = options[:link_prefix] || cid
+ @link_prefix = SecureRandom.uuid if !@link_prefix || @link_prefix.empty?
+ @link_count = 0
Cproton.pn_connection_open(@impl)
end
+ # @private Generate a unique link name, internal use only.
+ def link_name()
+ @link_prefix + "/" + (@link_count += 1).to_s(16)
+ end
+
# Closes the connection.
#
# Once this operation has completed, the #LOCAL_CLOSED state flag will be
@@ -239,14 +238,30 @@ module Qpid::Proton
Cproton.pn_connection_state(@impl)
end
- # Returns the session for this connection.
+ # Returns the default session for this connection.
#
# @return [Session] The session.
#
- def session
- @session ||= Session.wrap(Cproton.pn_session(@impl))
+ def default_session
+ @session ||= open_session
+ end
+
+ # @deprecated use #default_session()
+ alias_method :session, :default_session
+
+ # Open a new session on this connection.
+ def open_session
+ s = Session.wrap(Cproton.pn_session(@impl))
+ s.open
+ return s
end
+ # Open a sender on the default_session
+ def open_sender(*args, &block) default_session.open_sender(*args, &block) end
+
+ # Open a on the default_session
+ def open_receiver(*args, &block) default_session.open_receiver(*args, &block) end
+
# Returns the first session from the connection that matches the specified
# state mask.
#
@@ -322,16 +337,16 @@ module Qpid::Proton
Cproton.pn_error_code(Cproton.pn_connection_error(@impl))
end
- # @private
+ protected
+
def _local_condition
Cproton.pn_connection_condition(@impl)
end
- # @private
def _remote_condition
Cproton.pn_connection_remote_condition(@impl)
end
+ proton_reader :attachments
end
-
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/lib/core/session.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/session.rb b/proton-c/bindings/ruby/lib/core/session.rb
index 1dbb9bd..81135eb 100644
--- a/proton-c/bindings/ruby/lib/core/session.rb
+++ b/proton-c/bindings/ruby/lib/core/session.rb
@@ -120,40 +120,42 @@ module Qpid::Proton
Connection.wrap(Cproton.pn_session_connection(@impl))
end
- # Constructs a new sender.
- #
- # Each sender between two AMQP containers must be uniquely named. Note that
- # this uniqueness cannot be enforced at the library level, so some
- # consideration should be taken in choosing link names.
- #
- # @param name [String] The link name.
- #
- # @return [Sender, nil] The sender, or nil if an error occurred.
- #
- def sender(name)
- Sender.new(Cproton.pn_sender(@impl, name))
+ # @deprecated use {#open_sender}
+ def sender(name) Sender.new(Cproton.pn_sender(@impl, name)); end
+
+ # @deprecated use {#open_receiver}
+ def receiver(name) Receiver.new(Cproton.pn_receiver(@impl, name)); end
+
+ # TODO aconway 2016-01-04: doc options or target param
+ def open_receiver(options = {})
+ options = { :source => options } if options.is_a? String
+ receiver = Receiver.new Cproton.pn_receiver(@impl, options[:name] || connection.link_name)
+ receiver.source.address ||= options[:source]
+ receiver.target.address ||= options[:target]
+ receiver.source.dynamic = true if options[:dynamic]
+ receiver.handler = options[:handler] if !options[:handler].nil?
+ receiver.open
+ return receiver
end
- # Constructs a new receiver.
- #
- # Each receiver between two AMQP containers must be uniquely named. Note
- # that this uniqueness cannot be enforced at the library level, so some
- # consideration should be taken in choosing link names.
- #
- # @param name [String] The link name.
- #
- # @return [Receiver, nil] The receiver, or nil if an error occurred.
- #
- def receiver(name)
- Receiver.new(Cproton.pn_receiver(@impl, name))
+ # TODO aconway 2016-01-04: doc options or target param
+ def open_sender(options = {})
+ options = { :target => options } if options.is_a? String
+ sender = Sender.new Cproton.pn_sender(@impl, options[:name] || connection.link_name)
+ sender.target.address ||= options[:target]
+ sender.source.address ||= options[:source]
+ sender.target.dynamic = true if options[:dynamic]
+ sender.handler = options[:handler] if !options[:handler].nil?
+ sender.open
+ return sender
end
- # @private
+ private
+
def _local_condition
Cproton.pn_session_condition(@impl)
end
- # @private
def _remote_condition # :nodoc:
Cproton.pn_session_remote_condition(@impl)
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/lib/core/terminus.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/terminus.rb b/proton-c/bindings/ruby/lib/core/terminus.rb
index fa2d8ab..b4927d8 100644
--- a/proton-c/bindings/ruby/lib/core/terminus.rb
+++ b/proton-c/bindings/ruby/lib/core/terminus.rb
@@ -157,7 +157,7 @@ module Qpid::Proton
# @return [Data] The terminus properties.
#
def properties
- Data.new(Cproton.pn_terminus_properties(@impl))
+ Codec::Data.new(Cproton.pn_terminus_properties(@impl))
end
# Access and modify the AMQP capabilities data for the Terminus.
@@ -172,7 +172,7 @@ module Qpid::Proton
# @return [Data] The terminus capabilities.
#
def capabilities
- Data.new(Cproton.pn_terminus_capabilities(@impl))
+ Codec::Data.new(Cproton.pn_terminus_capabilities(@impl))
end
# Access and modify the AMQP outcomes for the Terminus.
@@ -187,7 +187,7 @@ module Qpid::Proton
# @return [Data] The terminus outcomes.
#
def outcomes
- Data.new(Cproton.pn_terminus_outcomes(@impl))
+ Codec::Data.new(Cproton.pn_terminus_outcomes(@impl))
end
# Access and modify the AMQP filter set for the Terminus.
@@ -202,7 +202,7 @@ module Qpid::Proton
# @return [Data] The terminus filter.
#
def filter
- Data.new(Cproton.pn_terminus_filter(@impl))
+ Codec::Data.new(Cproton.pn_terminus_filter(@impl))
end
# Copy another Terminus into this instance.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/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 04697a3..61767fd 100644
--- a/proton-c/bindings/ruby/lib/core/transport.rb
+++ b/proton-c/bindings/ruby/lib/core/transport.rb
@@ -252,6 +252,16 @@ module Qpid::Proton
condition_to_object Cproton.pn_transport_condition(@impl)
end
+ # Set the condition of the transport.
+ #
+ # Setting a non-empty condition before closing the transport will cause a
+ # TRANSPORT_ERROR event.
+ #
+ # @param c [Condition] The condition to set
+ def condition=(c)
+ object_to_condition c, Cproton.pn_transport_condition(@impl)
+ end
+
# Binds to the given connection.
#
# @param connection [Connection] The connection.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/lib/core/url.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/url.rb b/proton-c/bindings/ruby/lib/core/url.rb
index 9034487..30d2d87 100644
--- a/proton-c/bindings/ruby/lib/core/url.rb
+++ b/proton-c/bindings/ruby/lib/core/url.rb
@@ -30,9 +30,7 @@ module Qpid::Proton
# Parse a string, return a new URL
# @param url [#to_s] the URL string
- def initialize(url = nil, options = {})
- options[:defaults] = true
-
+ def initialize(url = nil)
if url
@url = Cproton.pn_url_parse(url.to_s)
if @url.nil?
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/lib/event/collector.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/event/collector.rb b/proton-c/bindings/ruby/lib/event/collector.rb
index c86b0f2..74e0182 100644
--- a/proton-c/bindings/ruby/lib/event/collector.rb
+++ b/proton-c/bindings/ruby/lib/event/collector.rb
@@ -112,7 +112,7 @@ module Qpid::Proton::Event
# @return [nil] if it was elided
#
def put(context, event_type)
- Cproton.pn_collector_put(@impl, Cproton.pn_rb2void(context), event_type.type_code)
+ Cproton.pn_collector_put(@impl, Cproton.pn_class(context.impl), context.impl, event_type.number)
end
# Access the head event.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/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 1d614a4..0180291 100644
--- a/proton-c/bindings/ruby/lib/qpid_proton.rb
+++ b/proton-c/bindings/ruby/lib/qpid_proton.rb
@@ -39,7 +39,6 @@ require "util/condition"
require "util/wrapper"
require "util/class_wrapper"
require "util/engine"
-require "util/uuid"
require "util/timeout"
require "util/handler"
require "util/reactor"
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/lib/reactor/backoff.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/reactor/backoff.rb b/proton-c/bindings/ruby/lib/reactor/backoff.rb
index 99682e5..54bb401 100644
--- a/proton-c/bindings/ruby/lib/reactor/backoff.rb
+++ b/proton-c/bindings/ruby/lib/reactor/backoff.rb
@@ -21,8 +21,10 @@ module Qpid::Proton::Reactor
class Backoff
- def initialize
- @delay = 0
+ def initialize min_ = 0, max_ = 3
+ @min = min_ > 0 ? min_ : 0.1
+ @max = [max_, min_].max
+ reset
end
def reset
@@ -31,11 +33,9 @@ module Qpid::Proton::Reactor
def next
current = @delay
- current = 0.1 if current.zero?
- @delay = [10, 2 * current].min
+ @delay = @delay.zero? ? @min : [@max, 2 * @delay].min
return current
end
-
end
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/lib/reactor/connector.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/reactor/connector.rb b/proton-c/bindings/ruby/lib/reactor/connector.rb
index 0971141..b2d0c66 100644
--- a/proton-c/bindings/ruby/lib/reactor/connector.rb
+++ b/proton-c/bindings/ruby/lib/reactor/connector.rb
@@ -21,10 +21,10 @@ module Qpid::Proton::Reactor
class Connector < Qpid::Proton::BaseHandler
- def initialize(connection, url, opts)
- @connection, @opts = connection, opts
+ def initialize(connection, url, options)
+ @connection, @options = connection, options
@urls = URLs.new(url) if url
- opts.each do |k,v|
+ options.each do |k,v|
case k
when :url, :urls, :address
@urls = URLs.new(v) unless @urls
@@ -80,7 +80,7 @@ module Qpid::Proton::Reactor
def connect(connection)
url = @urls.next
transport = Qpid::Proton::Transport.new
- @opts.each do |k,v|
+ @options.each do |k,v|
case k
when :user
connection.user = v
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/lib/reactor/container.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/reactor/container.rb b/proton-c/bindings/ruby/lib/reactor/container.rb
index 2828bb9..fbe199e 100644
--- a/proton-c/bindings/ruby/lib/reactor/container.rb
+++ b/proton-c/bindings/ruby/lib/reactor/container.rb
@@ -47,19 +47,18 @@ module Qpid::Proton::Reactor
include Qpid::Proton::Util::Reactor
- include Qpid::Proton::Util::UUID
-
attr_accessor :container_id
attr_accessor :global_handler
- def initialize(handlers, options = {})
- super(handlers, options)
+ def initialize(handlers, opts = {})
+ super(handlers, opts)
# only do the following if we're creating a new instance
- if !options.has_key?(:impl)
+ if !opts.has_key?(:impl)
+ @container_id = String.new(opts[:container_id] || SecureRandom.uuid).freeze
@ssl = SSLConfig.new
- if options[:global_handler]
- self.global_handler = GlobalOverrides.new(options[:global_handler])
+ if opts[:global_handler]
+ self.global_handler = GlobalOverrides.new(opts[:global_handler])
else
# very ugly, but using self.global_handler doesn't work in the constructor
ghandler = Reactor.instance_method(:global_handler).bind(self).call
@@ -67,7 +66,6 @@ module Qpid::Proton::Reactor
Reactor.instance_method(:global_handler=).bind(self).call(ghandler)
end
@trigger = nil
- @container_id = generate_uuid
end
end
@@ -95,72 +93,41 @@ module Qpid::Proton::Reactor
# @return [Connection] the new connection
#
def connect(url, opts = {})
- # Backwards compatible with old connect(options)
+ # Backwards compatible with old connect(opts)
if url.is_a? Hash and opts.empty?
opts = url
url = nil
end
conn = self.connection(opts[:handler])
- conn.container = self.container_id || generate_uuid
connector = Connector.new(conn, url, opts)
return conn
end
- private
- def _session(context)
- if context.is_a?(Qpid::Proton::URL)
- return _session(self.connect(:url => context))
- elsif context.is_a?(Qpid::Proton::Session)
- return context
- elsif context.is_a?(Qpid::Proton::Connection)
- if context.session_policy?
- return context.session_policy.session(context)
- else
- return self.create_session(context)
- end
- else
- return context.session
- end
- end
-
- public
# Initiates the establishment of a link over which messages can be sent.
#
# @param context [String, URL] The context.
- # @param opts [Hash] Additional options.
- # @option opts [String, Qpid::Proton::URL] The target address.
- # @option opts [String] :source The source address.
- # @option opts [Boolean] :dynamic
- # @option opts [Object] :handler
- # @option opts [Object] :tag_generator The tag generator.
- # @option opts [Hash] :options Addtional link options
+ # @param opts [Hash] Additional opts.
+ # @param opts [String] :target The target address.
+ # @param opts [String] :source The source address.
+ # @param opts [Boolean] :dynamic
+ # @param opts [Object] :handler
#
# @return [Sender] The sender.
#
- def create_sender(context, opts = {})
+ def open_sender(context, opts = {})
if context.is_a?(::String)
context = Qpid::Proton::URL.new(context)
end
-
- target = opts[:target]
- if context.is_a?(Qpid::Proton::URL) && target.nil?
- target = context.path
+ if context.is_a?(Qpid::Proton::URL)
+ opts[:target] ||= context.path
end
- session = _session(context)
-
- sender = session.sender(opts[:name] ||
- id(session.connection.container,
- target, opts[:source]))
- sender.source.address = opts[:source] if !opts[:source].nil?
- sender.target.address = target if target
- sender.handler = opts[:handler] if !opts[:handler].nil?
- sender.tag_generator = opts[:tag_generator] if !opts[:tag_gnenerator].nil?
- _apply_link_options(opts[:options], sender)
- sender.open
- return sender
+ return _session(context).open_sender(opts)
end
+ # @deprecated use @{#open_sender}
+ alias_method :create_sender, :open_sender
+
# Initiates the establishment of a link over which messages can be received.
#
# There are two accepted arguments for the context
@@ -172,41 +139,29 @@ module Qpid::Proton::Reactor
#
# The name will be generated for the link if one is not specified.
#
- # @param context [Connection, URL, String] The connection or the address.
- # @param opts [Hash] Additional otpions.
- # @option opts [String, Qpid::Proton::URL] The source address.
+ # @param context [Connection, URL, String] The connection or the connection address.
+ # @param opts [Hash] Additional opts.
+ # @option opts [String] :source The source address.
# @option opts [String] :target The target address
# @option opts [String] :name The link name.
# @option opts [Boolean] :dynamic
# @option opts [Object] :handler
- # @option opts [Hash] :options Additional link options.
#
- # @return [Receiver
+ # @return [Receiver]
#
- def create_receiver(context, opts = {})
+ def open_receiver(context, opts = {})
if context.is_a?(::String)
context = Qpid::Proton::URL.new(context)
end
-
- source = opts[:source]
- if context.is_a?(Qpid::Proton::URL) && source.nil?
- source = context.path
+ if context.is_a?(Qpid::Proton::URL)
+ opts[:source] ||= context.path
end
-
- session = _session(context)
-
- receiver = session.receiver(opts[:name] ||
- id(session.connection.container,
- source, opts[:target]))
- receiver.source.address = source if source
- receiver.source.dynamic = true if opts.has_key?(:dynamic) && opts[:dynamic]
- receiver.target.address = opts[:target] if !opts[:target].nil?
- receiver.handler = opts[:handler] if !opts[:handler].nil?
- _apply_link_options(opts[:options], receiver)
- receiver.open
- return receiver
+ return _session(context).open_receiver(opts)
end
+ # @deprecated use @{#open_sender}
+ alias_method :create_receiver, :open_receiver
+
def declare_transaction(context, handler = nil, settle_before_discharge = false)
if context.respond_to? :txn_ctl && !context.__send__(:txn_ctl).nil?
class << context
@@ -239,26 +194,25 @@ module Qpid::Proton::Reactor
private
- def id(container, remote, local)
- if !local.nil? && !remote.nil?
- "#{container}-#{remote}-#{local}"
- elsif !local.nil?
- "#{container}-#{local}"
- elsif !remote.nil?
- "#{container}-#{remote}"
+ def _session(context)
+ if context.is_a?(Qpid::Proton::URL)
+ return _session(self.connect(:url => context))
+ elsif context.is_a?(Qpid::Proton::Session)
+ return context
+ elsif context.is_a?(Qpid::Proton::Connection)
+ return context.default_session
else
- "#{container}-#{generate_uuid}"
+ return context.session
end
end
- def _apply_link_options(options, link)
- if !options.nil? && !options.empty?
- if !options.is_a?(::List)
- options = [Options].flatten
- end
+ def do_work(timeout = nil)
+ self.timeout = timeout unless timeout.nil?
+ self.process
+ end
- options.each {|option| o.apply(link) if o.test(link)}
- end
+ def _apply_link_opts(opts, link)
+ opts.each {|o| o.apply(link) if o.test(link)}
end
def to_s
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/lib/reactor/link_option.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/reactor/link_option.rb b/proton-c/bindings/ruby/lib/reactor/link_option.rb
index 628a811..2066bab 100644
--- a/proton-c/bindings/ruby/lib/reactor/link_option.rb
+++ b/proton-c/bindings/ruby/lib/reactor/link_option.rb
@@ -64,9 +64,9 @@ module Qpid::Proton::Reactor
def apply(link)
if link.receiver?
- link.source.properties.dict = @properties
+ link.source.properties.object = @properties
else
- link.target.properties.dict = @properties
+ link.target.properties.object = @properties
end
end
end
@@ -77,14 +77,9 @@ module Qpid::Proton::Reactor
end
def apply(receiver)
- receiver.source.filter.dict = @filter_set
+ receiver.source.filter.object = @filter_set
end
- end
- #class Selector < Filter
- # def initialize(value, name = 'selector')
- #
- # end
- #end
+ end
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/lib/util/uuid.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/util/uuid.rb b/proton-c/bindings/ruby/lib/util/uuid.rb
deleted file mode 100644
index 882715b..0000000
--- a/proton-c/bindings/ruby/lib/util/uuid.rb
+++ /dev/null
@@ -1,32 +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
-
- module UUID
-
- def generate_uuid
- # generate a UUID based on what APIs are available with the current
- # version of Ruby
- SecureRandom.uuid
- end
-
- end
-
-end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/spec/array_spec.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/spec/array_spec.rb b/proton-c/bindings/ruby/spec/array_spec.rb
index 5d91f1a..3bfe559 100644
--- a/proton-c/bindings/ruby/spec/array_spec.rb
+++ b/proton-c/bindings/ruby/spec/array_spec.rb
@@ -39,7 +39,7 @@ describe "The extended array type" do
end
it "raises an error when putting into a nil Data object" do
- expect { @list.proton_put(nil) }.must_raise
+ expect { @list.proton_put(nil) }.must_raise(TypeError)
end
it "raises an error when getting from a nil Data object" do
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b3d1b074/proton-c/bindings/ruby/tests/test_smoke.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/test_smoke.rb b/proton-c/bindings/ruby/tests/test_smoke.rb
deleted file mode 100755
index 61cc7cf..0000000
--- a/proton-c/bindings/ruby/tests/test_smoke.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'minitest/autorun'
-require 'minitest/unit'
-require 'qpid_proton'
-
-class SmokeTest < MiniTest::Test
-
- Messenger = Qpid::Proton::Messenger::Messenger
- Message = Qpid::Proton::Message
-
- def setup
- @server = Messenger.new()
- @client = Messenger.new()
- @server.blocking = false
- @client.blocking = false
- @server.subscribe("~0.0.0.0:12345")
- @server.start()
- @client.start()
- pump()
- end
-
- def pump
- while (@server.work(0) or @client.work(0)) do end
- end
-
- def teardown
- @server.stop()
- @client.stop()
-
- pump()
-
- assert @client.stopped?
- assert @server.stopped?
- end
-
- def testSmoke(count=10)
- msg = Message.new()
- msg.address = "0.0.0.0:12345"
-
- @server.receive()
-
- count.times {|i|
- msg.body = "Hello World! #{i}"
- @client.put(msg)
- }
-
- msg2 = Message.new()
-
- count.times {|i|
- if (@server.incoming == 0) then
- pump()
- end
- @server.get(msg2)
- assert msg2.body == "Hello World! #{i}"
- }
-
- assert(@client.outgoing == 0,
- "Expected 0 outgoing messages, found #{@client.outgoing}")
- assert(@server.incoming == 0,
- "Expected 0 incoming messages, found #{@server.incoming}")
- end
-
-end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org