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:36 UTC
[05/12] qpid-proton git commit: PROTON-1064: [ruby] Consistent option
handling, handle nil options
PROTON-1064: [ruby] Consistent option handling, handle nil options
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/f70764f5
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/f70764f5
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/f70764f5
Branch: refs/heads/master
Commit: f70764f52811b81008dec6a1dd00b68611139185
Parents: 12aaab9
Author: Alan Conway <ac...@redhat.com>
Authored: Tue Nov 21 14:58:59 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Thu Nov 30 16:36:26 2017 -0500
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/core/connection.rb | 8 +++---
proton-c/bindings/ruby/lib/core/container.rb | 19 ++++++------
proton-c/bindings/ruby/lib/core/listener.rb | 2 +-
proton-c/bindings/ruby/lib/core/session.rb | 32 +++++++++++----------
proton-c/bindings/ruby/tests/test_container.rb | 4 +--
proton-c/bindings/ruby/tests/test_tools.rb | 4 +--
6 files changed, 36 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f70764f5/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 0c878d4..4bd7e4f 100644
--- a/proton-c/bindings/ruby/lib/core/connection.rb
+++ b/proton-c/bindings/ruby/lib/core/connection.rb
@@ -201,9 +201,9 @@ module Qpid::Proton
# @option opts [String] :sasl_allowed_mechs the allowed SASL mechanisms for use on the connection.
# @option opts [String] :container_id AMQP container ID, normally provided by {Container}
#
- def open(opts={})
+ def open(opts=nil)
return if local_active?
- apply opts
+ apply opts if opts
Cproton.pn_connection_open(@impl)
end
@@ -272,10 +272,10 @@ module Qpid::Proton
end
# Open a sender on the default_session
- def open_sender(opts = {}) default_session.open_sender(opts) end
+ def open_sender(opts=nil) default_session.open_sender(opts) end
# Open a on the default_session
- def open_receiver(opts = {}) default_session.open_receiver(opts) end
+ def open_receiver(opts=nil) default_session.open_receiver(opts) end
# Returns the first session from the connection that matches the specified
# state mask.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f70764f5/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 39ac150..05c45ed 100644
--- a/proton-c/bindings/ruby/lib/core/container.rb
+++ b/proton-c/bindings/ruby/lib/core/container.rb
@@ -170,11 +170,14 @@ module Qpid::Proton
# url.user, url.password are used as defaults if opts[:user], opts[:password] are nil
# @option (see Connection#open)
# @return [Connection] The new AMQP connection
- def connect(url, opts = {})
+ def connect(url, opts=nil)
not_stopped
- url = Qpid::Proton::uri(url)
- opts[:user] ||= url.user
- opts[:password] ||= url.password
+ url = Qpid::Proton::uri url
+ if url.user || url.password
+ opts ||= {}
+ opts[:user] ||= url.user
+ opts[:password] ||= url.password
+ end
# TODO aconway 2017-10-26: Use SSL for amqps URLs
connect_io(TCPSocket.new(url.host, url.port), opts)
end
@@ -182,7 +185,7 @@ module Qpid::Proton
# Open an AMQP protocol connection on an existing {IO} object
# @param io [IO] An existing {IO} object, e.g. a {TCPSocket}
# @option (see Connection#open)
- def connect_io(io, opts = {})
+ def connect_io(io, opts=nil)
not_stopped
cd = connection_driver(io, opts)
cd.connection.open()
@@ -199,8 +202,8 @@ module Qpid::Proton
#
def listen(url, handler=Listener::Handler.new)
not_stopped
- url = Qpid::Proton::uri(url)
- # TODO aconway 2017-11-01: amqps
+ url = Qpid::Proton::uri url
+ # TODO aconway 2017-11-01: amqps, SSL
listen_io(TCPServer.new(url.host, url.port), handler)
end
@@ -321,7 +324,7 @@ module Qpid::Proton
end
end
- def connection_driver(io, opts, server=false)
+ def connection_driver(io, opts=nil, server=false)
opts ||= {}
opts[:container_id] ||= @id
opts[:handler] ||= @handler
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f70764f5/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 0584807..35dfe20 100644
--- a/proton-c/bindings/ruby/lib/core/listener.rb
+++ b/proton-c/bindings/ruby/lib/core/listener.rb
@@ -32,7 +32,7 @@ module Qpid::Proton
# methods to provide more interesting behaviour.
class Handler
# @param opts [Hash] Options to return from on_accept.
- def initialize(opts={}) @opts = opts; end
+ def initialize(opts=nil) @opts = opts || {}; end
# Called when the listener is ready to accept connections.
# @param listener [Listener] The listener
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f70764f5/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 3120d3f..a21c152 100644
--- a/proton-c/bindings/ruby/lib/core/session.rb
+++ b/proton-c/bindings/ruby/lib/core/session.rb
@@ -127,25 +127,27 @@ module Qpid::Proton
def receiver(name) Receiver.new(Cproton.pn_receiver(@impl, name)); end
# TODO aconway 2016-01-04: doc options or target param, move option handling to Link.
- 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?
+ def open_receiver(opts=nil)
+ opts = { :source => opts } if opts.is_a? String
+ opts ||= {}
+ receiver = Receiver.new Cproton.pn_receiver(@impl, opts[:name] || connection.link_name)
+ receiver.source.address ||= opts[:source]
+ receiver.target.address ||= opts[:target]
+ receiver.source.dynamic = true if opts[:dynamic]
+ receiver.handler = opts[:handler] if !opts[:handler].nil?
receiver.open
return receiver
end
- # 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?
+ # TODO aconway 2016-01-04: doc opts or target param
+ def open_sender(opts=nil)
+ opts = { :target => opts } if opts.is_a? String
+ opts ||= {}
+ sender = Sender.new Cproton.pn_sender(@impl, opts[:name] || connection.link_name)
+ sender.target.address ||= opts[:target]
+ sender.source.address ||= opts[:source]
+ sender.target.dynamic = true if opts[:dynamic]
+ sender.handler = opts[:handler] if !opts[:handler].nil?
sender.open
return sender
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f70764f5/proton-c/bindings/ruby/tests/test_container.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/test_container.rb b/proton-c/bindings/ruby/tests/test_container.rb
index 988acfb..f89ffbe 100644
--- a/proton-c/bindings/ruby/tests/test_container.rb
+++ b/proton-c/bindings/ruby/tests/test_container.rb
@@ -31,7 +31,7 @@ Thread::abort_on_exception=true
# Container that listens on a random port
class TestContainer < Container
- def initialize(handler, lopts = {}, id=nil)
+ def initialize(handler, lopts=nil, id=nil)
super handler, id
@server = TCPServer.open(0)
@listener = listen_io(@server, ListenOnceHandler.new(lopts))
@@ -160,7 +160,7 @@ class ContainerSASLTest < Minitest::Test
# Handler for test client/server that sets up server and client SASL options
class SASLHandler < TestHandler
- def initialize(url="amqp://", opts={}, mechanisms=nil, insecure=nil, realm=nil)
+ def initialize(url="amqp://", opts=nil, mechanisms=nil, insecure=nil, realm=nil)
super()
@url, @opts, @mechanisms, @insecure, @realm = url, opts, mechanisms, insecure, realm
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f70764f5/proton-c/bindings/ruby/tests/test_tools.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/test_tools.rb b/proton-c/bindings/ruby/tests/test_tools.rb
index 3b89cd0..e64d36b 100644
--- a/proton-c/bindings/ruby/tests/test_tools.rb
+++ b/proton-c/bindings/ruby/tests/test_tools.rb
@@ -112,8 +112,6 @@ end
# ListenHandler that closes the Listener after first accept
class ListenOnceHandler < ListenHandler
- def initialize(opts={}) @opts=opts; end
def on_error(l, e) raise TestError, e.inspect; end
- def on_accept(l) l.close; return @opts; end
- attr_reader :opts
+ def on_accept(l) l.close; super; end
end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org