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/12/15 21:59:08 UTC
[1/5] qpid-proton git commit: PROTON-1537: [ruby] Fix all -W2
warnings in self-tests
Repository: qpid-proton
Updated Branches:
refs/heads/ruby-api [created] 3c6537606
PROTON-1537: [ruby] Fix all -W2 warnings in self-tests
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/f252b2ff
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/f252b2ff
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/f252b2ff
Branch: refs/heads/ruby-api
Commit: f252b2ff7fb17783bbdf5167d542ee722cc48bbd
Parents: 1e256cf
Author: Alan Conway <ac...@redhat.com>
Authored: Thu Dec 14 14:59:29 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Fri Dec 15 09:59:47 2017 -0500
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/codec/data.rb | 2 +-
proton-c/bindings/ruby/lib/core/connection.rb | 7 +-----
proton-c/bindings/ruby/lib/core/container.rb | 3 +++
proton-c/bindings/ruby/lib/core/delivery.rb | 18 ++++++++------
proton-c/bindings/ruby/lib/core/event.rb | 11 ++++-----
proton-c/bindings/ruby/lib/core/sender.rb | 6 ++---
proton-c/bindings/ruby/lib/core/ssl.rb | 4 ---
proton-c/bindings/ruby/lib/core/ssl_domain.rb | 10 +++-----
proton-c/bindings/ruby/lib/core/terminus.rb | 8 +++---
proton-c/bindings/ruby/lib/core/transfer.rb | 1 +
proton-c/bindings/ruby/lib/core/transport.rb | 10 ++++----
proton-c/bindings/ruby/lib/core/url.rb | 1 -
.../bindings/ruby/lib/messenger/messenger.rb | 11 ++++-----
proton-c/bindings/ruby/lib/util/deprecation.rb | 2 +-
.../bindings/ruby/lib/util/error_handler.rb | 26 +++-----------------
15 files changed, 45 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/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 1573b5c..ec74756 100644
--- a/proton-c/bindings/ruby/lib/codec/data.rb
+++ b/proton-c/bindings/ruby/lib/codec/data.rb
@@ -75,7 +75,7 @@ module Qpid::Proton
}
end
- proton_caller :clear, :rewind, :next, :prev, :enter, :exit, :type
+ proton_caller :clear, :rewind, :next, :prev, :enter, :exit
def enter_exit()
enter
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/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 2b97f41..b9b5746 100644
--- a/proton-c/bindings/ruby/lib/core/connection.rb
+++ b/proton-c/bindings/ruby/lib/core/connection.rb
@@ -146,11 +146,6 @@ module Qpid::Proton
end
end
- # @private Generate a unique link name, internal use only.
- def link_name()
- @link_prefix + "/" + (@link_count += 1).to_s(16)
- end
-
# Closes the local end of the connection. The remote end may or may not be closed.
# @param error [Condition] Optional error condition to send with the close.
def close(error=nil)
@@ -259,7 +254,7 @@ module Qpid::Proton
# @private Generate a unique link name, internal use only.
def link_name()
- @link_prefix + "/" + (@link_count += 1).to_s(16)
+ @link_prefix + "/" + (@link_count += 1).to_s(32)
end
protected
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/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 f8c8c16..242356f 100644
--- a/proton-c/bindings/ruby/lib/core/container.rb
+++ b/proton-c/bindings/ruby/lib/core/container.rb
@@ -45,9 +45,12 @@ module Qpid::Proton
def initialize(io, handler, container)
super
+ @closing = @closed = nil
env = ENV['PN_TRACE_EVT']
if env && ["true", "1", "yes", "on"].include?(env.downcase)
@log_prefix = "[0x#{object_id.to_s(16)}](PN_LISTENER_"
+ else
+ @log_prefix = nil
end
dispatch(:on_open);
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/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 fd5c43a..cedce98 100644
--- a/proton-c/bindings/ruby/lib/core/delivery.rb
+++ b/proton-c/bindings/ruby/lib/core/delivery.rb
@@ -18,6 +18,8 @@
module Qpid::Proton
# Allow a {Receiver} to indicate the status of a received message to the {Sender}
class Delivery < Transfer
+ def initialize(*args) super; @message = nil; end
+
# @return [Receiver] The parent {Receiver} link.
def receiver() link; end
@@ -80,15 +82,15 @@ module Qpid::Proton
# @raise [UnderflowError] if the message is incomplete (check with {#complete?}
# @raise [::ArgumentError] if the delivery is not the current delivery on a receiving link.
def message
- return @message if @message
- raise AbortedError, "message aborted by sender" if aborted?
- raise UnderflowError, "incoming message incomplete" if partial?
- raise ArgumentError, "no incoming message" unless readable?
- @message = Message.new
- @message.decode(link.receive(pending))
- link.advance
+ unless @message
+ raise AbortedError, "message aborted by sender" if aborted?
+ raise UnderflowError, "incoming message incomplete" if partial?
+ raise ArgumentError, "no incoming message" unless readable?
+ @message = Message.new
+ @message.decode(link.receive(pending))
+ link.advance
+ end
@message
end
-
end
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/proton-c/bindings/ruby/lib/core/event.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/event.rb b/proton-c/bindings/ruby/lib/core/event.rb
index ee0fc02..d75cfff 100644
--- a/proton-c/bindings/ruby/lib/core/event.rb
+++ b/proton-c/bindings/ruby/lib/core/event.rb
@@ -125,12 +125,11 @@ module Qpid::Proton
# @return [Delivery, nil] delivery for this event
def delivery()
- return @delivery if @delivery
- case context
- when Delivery then @delivery = @context
- # deprecated: for backwards compat allow a Tracker to be treated as a Delivery
- when Tracker then @delivery = Delivery.new(context.impl)
- end
+ @delivery ||= case context
+ when Delivery then @delivery = @context
+ # deprecated: for backwards compat allow a Tracker to be treated as a Delivery
+ when Tracker then @delivery = Delivery.new(context.impl)
+ end
end
# @return [Tracker, nil] delivery for this event
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/proton-c/bindings/ruby/lib/core/sender.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/sender.rb b/proton-c/bindings/ruby/lib/core/sender.rb
index 4c7324c..c1ba1f8 100644
--- a/proton-c/bindings/ruby/lib/core/sender.rb
+++ b/proton-c/bindings/ruby/lib/core/sender.rb
@@ -27,9 +27,6 @@ module Qpid::Proton
# @private
include Util::ErrorHandler
- # @private
- can_raise_error :stream, :error_class => Qpid::Proton::LinkError
-
# Hint to the remote receiver about the number of messages available.
# The receiver may use this to optimize credit flow, or may ignore it.
# @param n [Integer] The number of deliveries potentially available.
@@ -71,6 +68,9 @@ module Qpid::Proton
def initialize(*arg) super; @tag_count = 0; end
def next_tag() (@tag_count += 1).to_s(32); end
+
+ # @private
+ can_raise_error :stream, :error_class => Qpid::Proton::LinkError
end
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/proton-c/bindings/ruby/lib/core/ssl.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/ssl.rb b/proton-c/bindings/ruby/lib/core/ssl.rb
index ec4f14d..bc4460a 100644
--- a/proton-c/bindings/ruby/lib/core/ssl.rb
+++ b/proton-c/bindings/ruby/lib/core/ssl.rb
@@ -66,8 +66,6 @@ module Qpid::Proton
# @private
include Util::ErrorHandler
- can_raise_error :peer_hostname=, :error_class => SSLError
-
# Returns whether SSL is supported.
#
# @return [Boolean] True if SSL support is available.
@@ -155,7 +153,5 @@ module Qpid::Proton
raise SSLError.new if error < 0
return name
end
-
end
-
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/proton-c/bindings/ruby/lib/core/ssl_domain.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/ssl_domain.rb b/proton-c/bindings/ruby/lib/core/ssl_domain.rb
index 2a3940d..31a472f 100644
--- a/proton-c/bindings/ruby/lib/core/ssl_domain.rb
+++ b/proton-c/bindings/ruby/lib/core/ssl_domain.rb
@@ -42,11 +42,6 @@ module Qpid::Proton
# @private
include Util::ErrorHandler
- can_raise_error :credentials, :error_class => Qpid::Proton::SSLError
- can_raise_error :trusted_ca_db, :error_class => Qpid::Proton::SSLError
- can_raise_error :peer_authentication, :error_class => Qpid::Proton::SSLError
- can_raise_error :allow_unsecured_client, :error_class => Qpid::Proton::SSLError
-
# @private
attr_reader :impl
@@ -150,6 +145,9 @@ module Qpid::Proton
Cproton.pn_ssl_domain_allow_unsecured_client(@impl);
end
+ can_raise_error :credentials, :error_class => Qpid::Proton::SSLError
+ can_raise_error :trusted_ca_db, :error_class => Qpid::Proton::SSLError
+ can_raise_error :peer_authentication, :error_class => Qpid::Proton::SSLError
+ can_raise_error :allow_unsecured_client, :error_class => Qpid::Proton::SSLError
end
-
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/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 82ac9f7..d3181db 100644
--- a/proton-c/bindings/ruby/lib/core/terminus.rb
+++ b/proton-c/bindings/ruby/lib/core/terminus.rb
@@ -131,10 +131,6 @@ module Qpid::Proton
# @private
include Util::ErrorHandler
- can_raise_error [:type=, :address=, :durability=, :expiry_policy=,
- :timeout=, :dynamic=, :distribution_mode=, :copy],
- :error_class => Qpid::Proton::LinkError
-
# @private
attr_reader :impl
@@ -211,6 +207,8 @@ module Qpid::Proton
Cproton.pn_terminus_copy(@impl,source.impl)
end
+ can_raise_error([:type=, :address=, :durability=, :expiry_policy=,
+ :timeout=, :dynamic=, :distribution_mode=, :copy],
+ :error_class => Qpid::Proton::LinkError)
end
-
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/proton-c/bindings/ruby/lib/core/transfer.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/transfer.rb b/proton-c/bindings/ruby/lib/core/transfer.rb
index 17f3b82..4fc21a9 100644
--- a/proton-c/bindings/ruby/lib/core/transfer.rb
+++ b/proton-c/bindings/ruby/lib/core/transfer.rb
@@ -36,6 +36,7 @@ module Qpid::Proton
def initialize(impl)
@impl = impl
+ @inspect = nil
self.class.store_instance(self, :pn_delivery_attachments)
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/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 64a8011..9b36335 100644
--- a/proton-c/bindings/ruby/lib/core/transport.rb
+++ b/proton-c/bindings/ruby/lib/core/transport.rb
@@ -201,11 +201,6 @@ module Qpid::Proton
# @private
include Util::ErrorHandler
- can_raise_error :process, :error_class => TransportError
- can_raise_error :close_tail, :error_class => TransportError
- can_raise_error :pending, :error_class => TransportError, :below => Error::EOS
- can_raise_error :close_head, :error_class => TransportError
-
# @private
def self.wrap(impl)
return nil if impl.nil?
@@ -413,5 +408,10 @@ module Qpid::Proton
# Direct use of the transport is deprecated.
self.idle_timeout= (opts[:idle_timeout]*1000).round if opts.include? :idle_timeout
end
+
+ can_raise_error :process, :error_class => TransportError
+ can_raise_error :close_tail, :error_class => TransportError
+ can_raise_error :pending, :error_class => TransportError, :below => Error::EOS
+ can_raise_error :close_head, :error_class => TransportError
end
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/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 1103e06..4fa59b6 100644
--- a/proton-c/bindings/ruby/lib/core/url.rb
+++ b/proton-c/bindings/ruby/lib/core/url.rb
@@ -27,7 +27,6 @@ module Qpid::Proton
alias user username
attr_reader :password
attr_reader :host
- attr_reader :port
attr_reader :path
# Parse a string, return a new URL
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/proton-c/bindings/ruby/lib/messenger/messenger.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/messenger/messenger.rb b/proton-c/bindings/ruby/lib/messenger/messenger.rb
index 7b992e2..912d159 100644
--- a/proton-c/bindings/ruby/lib/messenger/messenger.rb
+++ b/proton-c/bindings/ruby/lib/messenger/messenger.rb
@@ -58,11 +58,6 @@ module Qpid::Proton::Messenger
include Qpid::Proton::Util::ErrorHandler
include Qpid::Proton::Util::Deprecation
- can_raise_error [:send, :receive, :password=, :start, :stop,
- :perform_put, :perform_get, :interrupt,
- :route, :rewrite, :accept, :reject,
- :incoming_window=, :outgoing_window=]
-
# Creates a new +Messenger+.
#
# The +name+ parameter is optional. If one is not provided then
@@ -699,6 +694,10 @@ module Qpid::Proton::Messenger
!window.nil? && window.is_a?(Numeric)
end
- end
+ can_raise_error [:send, :receive, :password=, :start, :stop,
+ :perform_put, :perform_get, :interrupt,
+ :route, :rewrite, :accept, :reject,
+ :incoming_window=, :outgoing_window=]
+ end
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/proton-c/bindings/ruby/lib/util/deprecation.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/util/deprecation.rb b/proton-c/bindings/ruby/lib/util/deprecation.rb
index 8e96cd6..d9d0563 100644
--- a/proton-c/bindings/ruby/lib/util/deprecation.rb
+++ b/proton-c/bindings/ruby/lib/util/deprecation.rb
@@ -39,7 +39,7 @@ module Qpid::Proton::Util
end
def self.included(other)
- other.__send__ :extend, ClassMethods
+ other.extend ClassMethods
end
end
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f252b2ff/proton-c/bindings/ruby/lib/util/error_handler.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/util/error_handler.rb b/proton-c/bindings/ruby/lib/util/error_handler.rb
index 58545fb..9280fb0 100644
--- a/proton-c/bindings/ruby/lib/util/error_handler.rb
+++ b/proton-c/bindings/ruby/lib/util/error_handler.rb
@@ -23,35 +23,15 @@ module Qpid::Proton::Util
# @private
module ErrorHandler
- def self.included(base)
- base.extend(self)
-
- unless defined? base.to_be_wrapped
- class << base
- @@to_be_wrapped = []
- end
- end
-
- define_method :method_added do |name|
- if (!@@to_be_wrapped.nil?) && (@@to_be_wrapped.include? name)
- @@to_be_wrapped.delete name
- create_exception_handler_wrapper(name)
- end
- end
- end
+ def self.included(other) other.extend(self); end
def can_raise_error(method_names, options = {})
error_class = options[:error_class]
below = options[:below] || 0
# coerce the names to be an array
Array(method_names).each do |method_name|
- # if the method doesn't already exist then queue this aliasing
- unless self.method_defined? method_name
- @@to_be_wrapped ||= []
- @@to_be_wrapped << method_name
- else
- create_exception_handler_wrapper(method_name, error_class, below)
- end
+ raise "missing method #{method_name.inspect}" unless method_defined?(method_name) || private_method_defined?(method_name)
+ create_exception_handler_wrapper(method_name, error_class, below)
end
end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[3/5] qpid-proton git commit: PROTON-1537: [ruby] added Tracker#abort
Posted by ac...@apache.org.
PROTON-1537: [ruby] added Tracker#abort
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/a4c50ca4
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/a4c50ca4
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/a4c50ca4
Branch: refs/heads/ruby-api
Commit: a4c50ca4a1d20a31a9ac0aa3e27fb41f3084724b
Parents: 4859de4
Author: Alan Conway <ac...@redhat.com>
Authored: Wed Dec 13 16:21:32 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Fri Dec 15 09:59:47 2017 -0500
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/core/tracker.rb | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a4c50ca4/proton-c/bindings/ruby/lib/core/tracker.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/tracker.rb b/proton-c/bindings/ruby/lib/core/tracker.rb
index cf04be9..da6ac0a 100644
--- a/proton-c/bindings/ruby/lib/core/tracker.rb
+++ b/proton-c/bindings/ruby/lib/core/tracker.rb
@@ -35,6 +35,11 @@ module Qpid::Proton
:annotations => Codec::Data.to_object(Cproton.pn_disposition_annotations(d))
}
end
- end
+ # Abort a partially-sent message.
+ # The tracker can no longer be used after calling {#abort}.
+ def abort()
+ Cproton.pn_delivery_abort(@impl)
+ end
+ end
end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[2/5] qpid-proton git commit: PROTON-1537: [ruby] Replace head/next
with each
Posted by ac...@apache.org.
PROTON-1537: [ruby] Replace head/next with each
Connection provides each_session, Connection and Session provide each_link,
each_sender, each_receiver
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/1e256cf7
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/1e256cf7
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/1e256cf7
Branch: refs/heads/ruby-api
Commit: 1e256cf72c283a6998c36baa98e069fa90275706
Parents: a4c50ca
Author: Alan Conway <ac...@redhat.com>
Authored: Thu Dec 14 11:35:32 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Fri Dec 15 09:59:47 2017 -0500
----------------------------------------------------------------------
examples/ruby/broker.rb | 6 +-
proton-c/bindings/ruby/lib/core/connection.rb | 107 ++++++++-----------
proton-c/bindings/ruby/lib/core/link.rb | 15 +--
proton-c/bindings/ruby/lib/core/session.rb | 34 ++++--
proton-c/bindings/ruby/lib/util/deprecation.rb | 9 +-
.../ruby/tests/test_connection_driver.rb | 41 +++++++
6 files changed, 121 insertions(+), 91 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1e256cf7/examples/ruby/broker.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/broker.rb b/examples/ruby/broker.rb
index aad32a9..9595e2f 100644
--- a/examples/ruby/broker.rb
+++ b/examples/ruby/broker.rb
@@ -127,11 +127,7 @@ class Broker < Qpid::Proton::MessagingHandler
end
def remove_stale_consumers(connection)
- l = connection.link_head(Qpid::Proton::Endpoint::REMOTE_ACTIVE)
- while !l.nil?
- self.unsubscribe(l) if l.sender?
- l = l.next(Qpid::Proton::Endpoint::REMOTE_ACTIVE)
- end
+ connection.each_sender { |s| unsubscribe(s) }
end
def on_sendable(sender)
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1e256cf7/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 3ec7c26..2b97f41 100644
--- a/proton-c/bindings/ruby/lib/core/connection.rb
+++ b/proton-c/bindings/ruby/lib/core/connection.rb
@@ -197,78 +197,63 @@ module Qpid::Proton
# @option opts (see Session#open_receiver)
def open_receiver(opts=nil) default_session.open_receiver(opts) end
- # Returns the first session from the connection that matches the specified
- # state mask.
- #
- # Examines the state of each session owned by the connection, and returns
- # the first session that matches the given state mask. If the state mask
- # contains *both* local and remote flags, then an exact match against
- # those flags is performed. If the state mask contains only local *or*
- # remote flags, then a match occurs if a*any* of the local or remote flags
- # are set, respectively.
- #
- # @param mask [Integer] The state mask to be matched.
- #
- # @return [Session] The first matching session, or nil if none matched.
- #
- # @see Endpoint#LOCAL_UNINIT
- # @see Endpoint#LOCAL_ACTIVE
- # @see Endpoint#LOCAL_CLOSED
- # @see Endpoint#REMOTE_UNINIT
- # @see Endpoint#REMOTE_ACTIVE
- # @see Endpoint#REMOTE_CLOSED
- #
- def session_head(mask)
- Session.wrap(Cproton.pn_session_header(@impl, mask))
+ # @deprecated use {#each_session}
+ def session_head(mask)
+ deprecated __method__, "#each_session"
+ Session.wrap(Cproton.pn_session_head(@impl, mask))
end
- # Returns the first link that matches the given state mask.
- #
- # Examines the state of each link owned by the connection and returns the
- # first that matches the given state mask. If the state mask contains
- # *both* local and remote flags, then an exact match against those flags
- # is performed. If the state mask contains *only* local or remote flags,
- # then a match occurs if *any* of the local ore remote flags are set,
- # respectively.
- #
- # @param mask [Integer] The state mask to be matched.
- #
- # @return [Link] The first matching link, or nil if none matched.
- #
- # @see Endpoint#LOCAL_UNINIT
- # @see Endpoint#LOCAL_ACTIVE
- # @see Endpoint#LOCAL_CLOSED
- # @see Endpoint#REMOTE_UNINIT
- # @see Endpoint#REMOTE_ACTIVE
- # @see Endpoint#REMOTE_CLOSED
- #
+ # Get the sessions on this connection.
+ # @overload each_session
+ # @yieldparam s [Session] pass each session to block
+ # @overload each_session
+ # @return [Enumerator] enumerator over sessions
+ def each_session(&block)
+ return enum_for(:each_session) unless block_given?
+ s = Cproton.pn_session_head(@impl, 0);
+ while s
+ yield Session.wrap(s)
+ s = Cproton.pn_session_next(s, 0)
+ end
+ self
+ end
+
+ # @deprecated use {#each_link}
def link_head(mask)
+ deprecated __method__, "#each_link"
Link.wrap(Cproton.pn_link_head(@impl, mask))
end
- # Extracts the first delivery on the connection that has pending
- # operations.
- #
- # A readable delivery indicates message data is waiting to be read. A
- # A writable delivery indcates that message data may be sent. An updated
- # delivery indicates that the delivery's disposition has changed.
- #
- # A delivery will never be *both* readable and writable, but it may be
- # both readable or writable and updated.
- #
- # @return [Delivery] The delivery, or nil if none are available.
- #
- # @see Delivery#next
- #
+ # Get the links on this connection.
+ # @overload each_link
+ # @yieldparam l [Link] pass each link to block
+ # @overload each_link
+ # @return [Enumerator] enumerator over links
+ def each_link
+ return enum_for(:each_link) unless block_given?
+ l = Cproton.pn_link_head(@impl, 0);
+ while l
+ yield Link.wrap(l)
+ l = Cproton.pn_link_next(l, 0)
+ end
+ self
+ end
+
+ # Get the {Sender} links - see {#each_link}
+ def each_sender() each_link.select { |l| l.sender? }; end
+
+ # Get the {Receiver} links - see {#each_link}
+ def each_receiver() each_link.select { |l| l.receiver? }; end
+
+ # @deprecated use {#MessagingHandler} to handle work
def work_head
+ deprecated __method__
Delivery.wrap(Cproton.pn_work_head(@impl))
end
- # Returns the code for a connection error.
- #
- # @return [Integer] The error code.
- #
+ # @deprecated use {#condition}
def error
+ deprecated __method__, "#condition"
Cproton.pn_error_code(Cproton.pn_connection_error(@impl))
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1e256cf7/proton-c/bindings/ruby/lib/core/link.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/link.rb b/proton-c/bindings/ruby/lib/core/link.rb
index 88c0e52..2e656c2 100644
--- a/proton-c/bindings/ruby/lib/core/link.rb
+++ b/proton-c/bindings/ruby/lib/core/link.rb
@@ -48,12 +48,7 @@ module Qpid::Proton
#
proton_caller :state
- # @!method open
- #
- # Opens the link. Once this operation has completed, the state flag will be
- # set.
- #
- # @see Endpoint::LOCAL_ACTIVE
+ # @deprecated use {Session#open_sender} and {#Session#open_receiver}
proton_caller :open
# Close the local end of the link. The remote end may or may not be closed.
@@ -226,13 +221,9 @@ module Qpid::Proton
Cproton.pn_link_error(@impl)
end
- # Returns the next link that matches the given state mask.
- #
- # @param state_mask [Integer] The state mask.
- #
- # @return [Sender, Receiver] The next link.
- #
+ # @deprecated use {Session#each_link, Connection#each_link}
def next(state_mask)
+ deprecated __method__, "Session#each_link, Connection#each_link"
return Link.wrap(Cproton.pn_link_next(@impl, state_mask))
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1e256cf7/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 14f1a67..78e78a2 100644
--- a/proton-c/bindings/ruby/lib/core/session.rb
+++ b/proton-c/bindings/ruby/lib/core/session.rb
@@ -90,17 +90,9 @@ module Qpid::Proton
Cproton.pn_session_close(@impl)
end
- # Retrieves the next session from a given connection that matches the
- # specified state mask.
- #
- # When uses with Connection#session_head an application can access all of
- # the session son the connection that match the given state.
- #
- # @param state_mask [Integer] The state mask to match.
- #
- # @return [Session, nil] The next session if one matches, or nil.
- #
+ # @deprecated use {Connection#each_session}
def next(state_mask)
+ deprecated __method__, "Connection#each_session"
Session.wrap(Cproton.pn_session_next(@impl, state_mask))
end
@@ -150,6 +142,28 @@ module Qpid::Proton
return sender
end
+ # Get the links on this Session.
+ # @overload each_link
+ # @yieldparam l [Link] pass each link to block
+ # @overload each_link
+ # @return [Enumerator] enumerator over links
+ def each_link
+ return enum_for(:each_link) unless block_given?
+ l = Cproton.pn_link_head(Cproton.pn_session_connection(@impl), 0);
+ while l
+ link = Link.wrap(l)
+ yield link if link.session == self
+ l = Cproton.pn_link_next(l, 0)
+ end
+ self
+ end
+
+ # Get the {Sender} links - see {#each_link}
+ def each_sender() each_link.select { |l| l.sender? }; end
+
+ # Get the {Receiver} links - see {#each_link}
+ def each_receiver() each_link.select { |l| l.receiver? }; end
+
private
def _local_condition
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1e256cf7/proton-c/bindings/ruby/lib/util/deprecation.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/util/deprecation.rb b/proton-c/bindings/ruby/lib/util/deprecation.rb
index 2e83783..8e96cd6 100644
--- a/proton-c/bindings/ruby/lib/util/deprecation.rb
+++ b/proton-c/bindings/ruby/lib/util/deprecation.rb
@@ -18,9 +18,12 @@
module Qpid::Proton::Util
# @private
module Deprecation
- def self.deprecated(old, new=nil, skip=2)
+ MATCH_DIR = /#{File.dirname(File.dirname(__FILE__))}/
+
+ def self.deprecated(old, new=nil)
replace = new ? "use `#{new}`" : "internal use only"
- warn "[DEPRECATION] `#{old}` is deprecated, #{replace}. Called from\n #{caller(skip).first}"
+ line = caller.find { |l| not MATCH_DIR.match(l) }
+ warn "[DEPRECATION] `#{old}` is deprecated, #{replace}. Called from #{line}"
end
def deprecated(*arg) Deprecation.deprecated(*arg); end
@@ -29,7 +32,7 @@ module Qpid::Proton::Util
def deprecated_alias(bad, good)
bad, good = bad.to_sym, good.to_sym
define_method(bad) do |*args, &block|
- self.deprecated bad, good, 3
+ self.deprecated bad, good
self.__send__(good, *args, &block)
end
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1e256cf7/proton-c/bindings/ruby/tests/test_connection_driver.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/test_connection_driver.rb b/proton-c/bindings/ruby/tests/test_connection_driver.rb
index 3386e49..d8cce2a 100644
--- a/proton-c/bindings/ruby/tests/test_connection_driver.rb
+++ b/proton-c/bindings/ruby/tests/test_connection_driver.rb
@@ -86,4 +86,45 @@ class RawDriverTest < Minitest::Test
d.run(start + secs*2) # After 2x timeout, connections should close
assert_equal [[:on_transport_error, :on_transport_tail_closed, :on_transport_head_closed, :on_transport_closed], [:on_connection_remote_close, :on_transport_tail_closed, :on_transport_head_closed, :on_transport_closed]], d.collect { |x| x.handler.calls }
end
+
+ # Test each_session/each_link methods both with a block and returning Enumerator
+ def test_enumerators
+ connection = Connection.new()
+ (3.times.collect { connection.open_session }).each { |s|
+ s.open_sender; s.open_receiver
+ }
+
+ assert_equal 3, connection.each_session.to_a.size
+ assert_equal 6, connection.each_link.to_a.size
+
+ # Build Session => Set<Links> map using connection link enumerator
+ map1 = {}
+ connection.each_link { |l| map1[l.session] ||= Set.new; map1[l.session] << l }
+ assert_equal 3, map1.size
+ map1.each do |session,links|
+ assert_equal 2, links.size
+ links.each { |l| assert_equal session, l.session }
+ end
+
+ # Build Session => Set<Links> map using connection and session blocks
+ map2 = {}
+ connection.each_session do |session|
+ map2[session] = Set.new
+ session.each_link { |l| map2[session] << l }
+ end
+ assert_equal map1, map2
+
+ # Build Session => Set<Links> map using connection session and session enumerators
+ map3 = Hash[connection.each_session.collect { |s| [s, Set.new(s.each_link)] }]
+ assert_equal map1, map3
+
+ assert_equal [true, true, true], connection.each_sender.collect { |l| l.is_a? Sender }
+ assert_equal [true, true, true], connection.each_receiver.collect { |l| l.is_a? Receiver }
+ connection.each_session { |session|
+ assert_equal [true], session.each_sender.collect { |l| l.is_a? Sender }
+ assert_equal [true], session.each_receiver.collect { |l| l.is_a? Receiver }
+ }
+
+
+ end
end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[5/5] qpid-proton git commit: WIP: [ruby] Add missing connection
options, update Connection API.
Posted by ac...@apache.org.
WIP: [ruby] Add missing connection options, update Connection API.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/3c653760
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/3c653760
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/3c653760
Branch: refs/heads/ruby-api
Commit: 3c65376068cbd48c7f8dcad06c3748e0024b2b25
Parents: 5cb9775
Author: Alan Conway <ac...@redhat.com>
Authored: Fri Dec 15 16:53:30 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Fri Dec 15 16:53:30 2017 -0500
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/core/connection.rb | 121 +++++++++++--------
.../bindings/ruby/lib/core/connection_driver.rb | 1 -
proton-c/bindings/ruby/lib/core/container.rb | 3 +-
proton-c/bindings/ruby/lib/core/message.rb | 6 +-
proton-c/bindings/ruby/lib/core/transport.rb | 54 ++-------
proton-c/bindings/ruby/lib/reactor/container.rb | 3 +
proton-c/bindings/ruby/lib/types/array.rb | 6 +-
proton-c/bindings/ruby/lib/types/hash.rb | 13 +-
proton-c/bindings/ruby/lib/util/deprecation.rb | 7 +-
proton-c/bindings/ruby/tests/test_container.rb | 63 +++++++++-
10 files changed, 169 insertions(+), 108 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3c653760/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 b9b5746..f5fcc09 100644
--- a/proton-c/bindings/ruby/lib/core/connection.rb
+++ b/proton-c/bindings/ruby/lib/core/connection.rb
@@ -20,32 +20,17 @@ module Qpid::Proton
# An AMQP connection.
class Connection < Endpoint
- include Util::Deprecation
-
- # @private
PROTON_METHOD_PREFIX = "pn_connection"
- # @private
include Util::Wrapper
+ include Util::Deprecation
- # @!attribute hostname
- # @return [String] The AMQP hostname for the connection.
- proton_set_get :hostname
-
- # @!attribute user
- # @return [String] User name used for authentication (outgoing connection) or the authenticated user name (incoming connection)
- proton_set_get :user
-
- private
-
- proton_set :password
- attr_accessor :overrides
- attr_accessor :session_policy
-
+ # @private
def self.wrap(impl)
return nil if impl.nil?
self.fetch_instance(impl, :pn_connection_attachments) || Connection.new(impl)
end
+ # @private
def initialize(impl = Cproton.pn_connection)
super()
@impl = impl
@@ -56,7 +41,19 @@ module Qpid::Proton
self.class.store_instance(self, :pn_connection_attachments)
end
- public
+ # @return [String] The AMQP hostname for the connection.
+ def virtual_host() Cproton.pn_connection_remote_hostname(@impl); end
+ deprecated_alias :remote_hostname, :virtual_host
+
+ # @!attribute hostname
+ # @deprecated use {#virtual_host}
+ proton_set_get :hostname
+
+ # @return [String] User name used for authentication (outgoing connection)
+ # or the authenticated user name (incoming connection)
+ def user()
+ Cproton.pn_connection_get_user(impl) or (connection.transport && connection.transport.user)
+ end
# @deprecated no replacement
def overrides?() deprecated __method__; false; end
@@ -68,49 +65,54 @@ module Qpid::Proton
def connection() self; end
# @return [Transport, nil] transport bound to this connection, or nil if unbound.
- #
def transport() Transport.wrap(Cproton.pn_connection_transport(@impl)); end
- # @return AMQP container ID advertised by the remote peer
- def remote_container_id() Cproton.pn_connection_remote_container(@impl); end
-
- alias remote_container remote_container_id
+ # @return AMQP container ID advertised by the remote peer.
+ # To get the local container ID use {#container} and {Container#id}
+ def container_id() Cproton.pn_connection_remote_container(@impl); end
+ deprecated_alias :remote_container, :container_id
# @return [Container] the container managing this connection
attr_reader :container
- # @return AMQP container ID for the local end of the connection
- def container_id() Cproton.pn_connection_get_container(@impl); end
-
- # @return [String] hostname used by the remote end of the connection
- def remote_hostname() Cproton.pn_connection_remote_hostname(@impl); end
-
# @return [Array<Symbol>] offered capabilities provided by the remote peer
- def remote_offered_capabilities
+ def offered_capabilities
Codec::Data.to_object(Cproton.pn_connection_remote_offered_capabilities(@impl))
end
+ deprecated_alias :remote_offered_capabilities, :desired_offered_capabilities
# @return [Array<Symbol>] desired capabilities provided by the remote peer
- def remote_desired_capabilities
+ def desired_capabilities
Codec::Data.to_object(Cproton.pn_connection_remote_desired_capabilities(@impl))
end
+ deprecated_alias :remote_desired_capabilities, :desired_capabilities
# @return [Hash] connection-properties provided by the remote peer
- def remote_properties
- Codec::Data.to_object(Cproton.pn_connection_remote_properites(@impl))
+ def properties
+ Codec::Data.to_object(Cproton.pn_connection_remote_properties(@impl))
end
+ deprecated_alias :remote_properties, :properties
# Open the local end of the connection.
#
# @option opts [MessagingHandler] :handler handler for events related to this connection.
- # @option opts [String] :user user-name for authentication.
- # @option opts [String] :password password for authentication.
- # @option opts [Numeric] :idle_timeout seconds before closing an idle connection
- # @option opts [Boolean] :sasl_enabled Enable or disable SASL.
- # @option opts [Boolean] :sasl_allow_insecure_mechs Allow mechanisms that disclose clear text
- # passwords, even over an insecure connection.
- # @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}
+ #
+ # @option opts [String] :user User name for authentication
+ # @option opts [String] :password Authentication secret
+ # @option opts [String] :virtual_host Virtual host name
+ # @option opts [String] :container_id (provided by {Container}) override advertised container-id
+ #
+ # @option opts [Hash<Symbol=>Object>] :properties Application-defined properties
+ # @option opts [Array<Symbol>] :offered_capabilities Extensions the endpoint supports
+ # @option opts [Array<Symbol>] :desired_capabilities Extensions the endpoint can use
+ #
+ # @option opts [Numeric] :idle_timeout Seconds before closing an idle connection
+ # @option opts [Integer] :max_sessions Limit the number of active sessions
+ # @option opts [Integer] :max_frame_size Limit the size of AMQP frames
+ #
+ # @option opts [Boolean] :sasl_enabled (false) Enable or disable SASL.
+ # @option opts [Boolean] :sasl_allow_insecure_mechs (false) Allow mechanisms send secrets in clear text
+ # @option opts [String] :sasl_allowed_mechs SASL mechanisms allowed by this end of the connection
#
def open(opts=nil)
return if local_active?
@@ -129,23 +131,44 @@ module Qpid::Proton
Cproton.pn_connection_set_container(@impl, cid)
Cproton.pn_connection_set_user(@impl, opts[:user]) if opts[:user]
Cproton.pn_connection_set_password(@impl, opts[:password]) if opts[:password]
- @link_prefix = opts[:link_prefix] || container_id
- Codec::Data.from_object(Cproton.pn_connection_offered_capabilities(@impl), opts[:offered_capabilities])
- Codec::Data.from_object(Cproton.pn_connection_desired_capabilities(@impl), opts[:desired_capabilities])
- Codec::Data.from_object(Cproton.pn_connection_properties(@impl), opts[:properties])
+ Cproton.pn_connection_set_hostname(@impl, opts[:virtual_host]) if opts[:virtual_host]
+ @link_prefix = opts[:link_prefix] || cid
+ Codec::Data.from_object(Cproton.pn_connection_offered_capabilities(@impl),
+ Types.symbol_array(opts[:offered_capabilities]))
+ Codec::Data.from_object(Cproton.pn_connection_desired_capabilities(@impl),
+ Types.symbol_array(opts[:desired_capabilities]))
+ Codec::Data.from_object(Cproton.pn_connection_properties(@impl),
+ Types.symbol_keys(opts[:properties]))
end
# Idle-timeout advertised by the remote peer, in seconds.
- # Set by {Connection#open} with the +:idle_timeout+ option.
# @return [Numeric] Idle-timeout advertised by the remote peer, in seconds.
- # @return [nil] if The peer does not advertise an idle time-out
- # @option :idle_timeout (see {#open})
+ # @return [nil] if the peer does not advertise an idle time-out
def idle_timeout()
if transport && (t = transport.remote_idle_timeout)
Rational(t, 1000) # More precise than Float
end
end
+ # Session limit advertised by the remote peer. See {Connection#open :max_sessions}
+ # @return [Integer] maximum number of sessions per connection allowed by remote peer.
+ # @return [nil] no specific limit is set.
+ def max_sessions()
+ raise StateError, "connection not bound to transport" unless transport
+ max = transport.remote_channel_max
+ return max.zero? ? nil : max
+ end
+
+ # Maximum frame size, in bytes, advertised by the remote peer.
+ # See {Connection#open :max_frame_size}
+ # @return [Integer] maximum frame size
+ # @return [nil] no limit
+ def max_frame_size()
+ raise StateError, "connection not bound to transport" unless transport
+ max = transport.remote_max_frame
+ return max.zero? ? nil : max
+ end
+
# Closes the local end of the connection. The remote end may or may not be closed.
# @param error [Condition] Optional error condition to send with the close.
def close(error=nil)
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3c653760/proton-c/bindings/ruby/lib/core/connection_driver.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/connection_driver.rb b/proton-c/bindings/ruby/lib/core/connection_driver.rb
index 2ce132e..12dcb68 100644
--- a/proton-c/bindings/ruby/lib/core/connection_driver.rb
+++ b/proton-c/bindings/ruby/lib/core/connection_driver.rb
@@ -181,7 +181,6 @@ module Qpid::Proton
case e.method # Events that affect the driver
when :on_transport_tail_closed then close_read
when :on_transport_head_closed then close_write
- when :on_transport_authenticated then connection.user = transport.user
end
e.dispatch @adapter
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3c653760/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 5dc9d60..9d9463e 100644
--- a/proton-c/bindings/ruby/lib/core/container.rb
+++ b/proton-c/bindings/ruby/lib/core/container.rb
@@ -125,7 +125,8 @@ module Qpid::Proton
@handler = args[0] unless @id
else raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..2"
end
- @adapter = Handler::Adapter.adapt(@handler)
+ # Use an empty messaging adapter to give default behaviour if there's no global handler.
+ @adapter = Handler::Adapter.adapt(@handler) || Handler::MessagingAdapter.new(nil)
@id = (@id || SecureRandom.uuid).freeze
# Implementation note:
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3c653760/proton-c/bindings/ruby/lib/core/message.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/message.rb b/proton-c/bindings/ruby/lib/core/message.rb
index 8b13de2..9afaa0a 100644
--- a/proton-c/bindings/ruby/lib/core/message.rb
+++ b/proton-c/bindings/ruby/lib/core/message.rb
@@ -73,8 +73,10 @@ module Qpid::Proton
# @private
def pre_encode
# encode elements from the message
- Codec::Data.from_object(Cproton::pn_message_properties(@impl), !@properties.empty? && @properties)
- Codec::Data.from_object(Cproton::pn_message_instructions(@impl), !@instructions.empty? && @instructions)
+ Codec::Data.from_object(Cproton::pn_message_properties(@impl),
+ !@properties.empty? && Types.symbol_keys!(@properties))
+ Codec::Data.from_object(Cproton::pn_message_instructions(@impl),
+ !@instructions.empty? && Types.symbol_keys!(@instructions))
if @annotations # Make sure keys are symbols
@annotations.keys.each do |k|
@annotations[k.to_sym] = @annotations.delete(k) unless k.is_a? Symbol
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3c653760/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 9b36335..eb5fb01 100644
--- a/proton-c/bindings/ruby/lib/core/transport.rb
+++ b/proton-c/bindings/ruby/lib/core/transport.rb
@@ -18,49 +18,7 @@
module Qpid::Proton
- # A transport is used by a connection to interface with the network.
- #
- # A transport is associated with, at most, one Connection.
- #
- # == Client And Server Mode
- #
- # Initially, a transport is configured to be a client tranpsort. It can be
- # configured to act as a server when it is created.
- #
- # A client transport initiates outgoing connections.
- #
- # A client transport must be configured with the protocol layers to use and
- # cannot configure itself automatically.
- #
- # A server transport accepts incoming connections. It can automatically
- # configure itself to include the various protocol layers depending on the
- # incoming protocol headers.
- #
- # == Tracing Data
- #
- # Data can be traced into and out of the transport programmatically by setting
- # the #trace level to one of the defined trace values (TRACE_RAW, TRACE_FRM or
- # TRACE_DRV). Tracing can also be turned off programmatically by setting the
- # #trace level to TRACE_OFF.
- #
- # @example
- #
- # # turns on frame tracing
- # @transport.trace = Qpid::Proton::Transport::TRACE_FRM
- #
- # # ... do something where the frames are of interest, such as debugging
- #
- # # turn tracing off again
- # @transport.trace = Qpid::Proton::Transport::TRACE_NONE
- #
- # Tracing can also be enabled from the command line by defining the similarly
- # named environment variable before starting a Proton application:
- #
- # @example
- #
- # # enable tracing from the command line
- # PN_TRACE_FRM=1 ruby my_proton_app.rb
- #
+ # @deprecated all important features are available from {#Connection}
class Transport
include Util::Deprecation
@@ -78,6 +36,7 @@ module Qpid::Proton
# Log driver related events; i.e., initialization, end of stream, etc.
TRACE_DRV = Cproton::PN_TRACE_DRV
+ proton_get :user
# @!attribute channel_max
#
@@ -94,8 +53,8 @@ module Qpid::Proton
# @!attribute max_frame_size
#
# @return [Integer] The maximum frame size.
- #
- proton_set_get :max_frame_size
+ proton_set_get :max_frame
+ proton_get :remote_max_frame
# @!attribute [r] remote_max_frame_size
#
@@ -394,14 +353,15 @@ module Qpid::Proton
end
# @private
+ # Options are documented {Connection#open}, keep that consistent with this
def apply opts
sasl if opts[:sasl_enabled] # Explicitly enabled
unless opts.include?(:sasl_enabled) && !opts[:sasl_enabled] # Not explicitly disabled
sasl.allowed_mechs = opts[:sasl_allowed_mechs] if opts.include? :sasl_allowed_mechs
sasl.allow_insecure_mechs = opts[:sasl_allow_insecure_mechs] if opts.include? :sasl_allow_insecure_mechs
end
- self.channel_max= opts[:channel_max] if opts.include? :channel_max
- self.max_frame_size= opts[:max_frame_size] if opts.include? :max_frame_size
+ self.channel_max= opts[:max_sessions] if opts.include? :max_sessions
+ self.max_frame = opts[:max_frame_size] if opts.include? :max_frame_size
# NOTE: The idle_timeout option is in Numeric *seconds*, can be Integer, Float or Rational.
# This is consistent with idiomatic ruby.
# The transport #idle_timeout property is in *milliseconds* passed direct to C.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3c653760/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 22cb0e8..0576647 100644
--- a/proton-c/bindings/ruby/lib/reactor/container.rb
+++ b/proton-c/bindings/ruby/lib/reactor/container.rb
@@ -42,6 +42,9 @@ module Qpid::Proton
def connect(opts=nil)
url = opts && (opts[:url] || opts[:address])
raise ::ArgumentError.new, "no :url or :address option provided" unless url
+ # Default to ReactorMessagingAdapter default behavior
+ opts ||= {}
+ opts[:handler] ||= Handler::ReactorMessagingAdapter.new
super(url, opts)
end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3c653760/proton-c/bindings/ruby/lib/types/array.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/types/array.rb b/proton-c/bindings/ruby/lib/types/array.rb
index 7a20adb..d7e15e6 100644
--- a/proton-c/bindings/ruby/lib/types/array.rb
+++ b/proton-c/bindings/ruby/lib/types/array.rb
@@ -51,7 +51,11 @@ module Qpid::Proton
@type, @descriptor = type, descriptor
raise ArgumentError, "no type specified for array" if @type.nil?
super elements if elements
- @proton_array_header = ArrayHeader.new(@type, @descriptor) # Deprecated
+ end
+
+ # @deprecated backwards compatibility {UniformArray}
+ def proton_array_header
+ @proton_array_header ||= ArrayHeader.new(@type, @descriptor) # Deprecated
end
# @return [Type] Array elements must be convertible to this AMQP type
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3c653760/proton-c/bindings/ruby/lib/types/hash.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/types/hash.rb b/proton-c/bindings/ruby/lib/types/hash.rb
index 2d78f74..2702ab2 100644
--- a/proton-c/bindings/ruby/lib/types/hash.rb
+++ b/proton-c/bindings/ruby/lib/types/hash.rb
@@ -23,7 +23,6 @@
# @private
class Hash # :nodoc:
-
# @deprecated
def proton_data_put(data)
@@ -37,3 +36,15 @@ class Hash # :nodoc:
data.map
end
end
+
+module Qpid::Proton::Types
+ # @private
+ def self.symbol_keys(h)
+ h && h.reduce({}) { |x, (k, v)| x[k.to_sym] = v; x }
+ end
+
+ # @private
+ def self.symbol_array(a)
+ a && UniformArray.new(SYMBOL, a.collect { |v| v.to_sym })
+ end
+end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3c653760/proton-c/bindings/ruby/lib/util/deprecation.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/util/deprecation.rb b/proton-c/bindings/ruby/lib/util/deprecation.rb
index d9d0563..4980a9e 100644
--- a/proton-c/bindings/ruby/lib/util/deprecation.rb
+++ b/proton-c/bindings/ruby/lib/util/deprecation.rb
@@ -20,10 +20,13 @@ module Qpid::Proton::Util
module Deprecation
MATCH_DIR = /#{File.dirname(File.dirname(__FILE__))}/
+ DEPRECATE_FULL_TRACE = false
+
def self.deprecated(old, new=nil)
replace = new ? "use `#{new}`" : "internal use only"
- line = caller.find { |l| not MATCH_DIR.match(l) }
- warn "[DEPRECATION] `#{old}` is deprecated, #{replace}. Called from #{line}"
+
+ from = DEPRECATE_FULL_TRACE ? caller(2).join("\n") : caller.find { |l| not MATCH_DIR.match(l) }
+ warn "[DEPRECATION] `#{old}` is deprecated, #{replace}. Called from #{from}"
end
def deprecated(*arg) Deprecation.deprecated(*arg); end
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3c653760/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 d8bd52c..82c34e2 100644
--- a/proton-c/bindings/ruby/tests/test_container.rb
+++ b/proton-c/bindings/ruby/tests/test_container.rb
@@ -75,7 +75,7 @@ class ContainerTest < Minitest::Test
end
class CloseOnOpenHandler < TestHandler
- def on_connection_open(c) c.close; end
+ def on_connection_open(c) super; c.close; end
end
def test_auto_stop_one
@@ -159,6 +159,61 @@ class ContainerTest < Minitest::Test
assert_match(/badconnect.example.com:999/, c.transport.condition.description)
end
+ # Verify that connection options are sent to the peer and available as Connection methods
+ def test_connection_options
+ # Note: user, password and sasl_xxx options are tested by ContainerSASLTest below
+ server_handler = Class.new(MessagingHandler) do
+ def on_error(e) raise e.inspect; end
+ def on_connection_open(c) @connection = c
+ c.open({
+ :virtual_host => "server.to.client",
+ :properties => { :server => :client },
+ :offered_capabilities => [ :s1 ],
+ :desired_capabilities => [ :s2 ],
+ :container_id => "box",
+ })
+ c.close
+ end
+ attr_reader :connection
+ end.new
+ # Transport options must be provided to the listener, by Connection#open it is too late
+ cont = TestContainer.new(nil, {
+ :handler => server_handler,
+ :idle_timeout => 88,
+ :max_sessions =>1000,
+ :max_frame_size => 8888,
+ })
+ client = cont.connect(cont.url,
+ {:virtual_host => "client.to.server",
+ :properties => { :foo => :bar, "str" => "str" },
+ :offered_capabilities => [:c1 ],
+ :desired_capabilities => ["c2" ],
+ :idle_timeout => 42,
+ :max_sessions =>100,
+ :max_frame_size => 4096,
+ :container_id => "bowl"
+ })
+ cont.run
+ c = server_handler.connection
+ assert_equal "client.to.server", c.virtual_host
+ assert_equal({ :foo => :bar, :str => "str" }, c.properties)
+ assert_equal([:c1], c.offered_capabilities)
+ assert_equal([:c2], c.desired_capabilities)
+ assert_equal 21, c.idle_timeout # Proton divides by 2
+ assert_equal 100, c.max_sessions
+ assert_equal 4096, c.max_frame_size
+ assert_equal "bowl", c.container_id
+
+ c = client
+ assert_equal "server.to.client", c.virtual_host
+ assert_equal({ :server => :client }, c.properties)
+ assert_equal([:s1], c.offered_capabilities)
+ assert_equal([:s2], c.desired_capabilities)
+ assert_equal "box", c.container_id
+ assert_equal 8888, c.max_frame_size
+ assert_equal 44, c.idle_timeout # Proton divides by 2
+ assert_equal 100, c.max_sessions
+ end
end
@@ -184,7 +239,7 @@ class ContainerSASLTest < Minitest::Test
if connection == @client
connection.close
else
- @auth_user = connection.transport.sasl.user
+ @auth_user = connection.user
end
end
end
@@ -231,7 +286,7 @@ mech_list: EXTERNAL DIGEST-MD5 SCRAM-SHA-1 CRAM-MD5 PLAIN ANONYMOUS
def test_sasl_anonymous()
s = SASLHandler.new("amqp://", {:sasl_allowed_mechs => "ANONYMOUS"})
TestContainer.new(s, {:sasl_allowed_mechs => "ANONYMOUS"}, __method__).run
- assert_nil(s.connections[0].user)
+ assert_equal "anonymous", s.connections[0].user
end
def test_sasl_plain_url()
@@ -239,7 +294,7 @@ mech_list: EXTERNAL DIGEST-MD5 SCRAM-SHA-1 CRAM-MD5 PLAIN ANONYMOUS
# Use default realm with URL, should authenticate with "default_password"
opts = {:sasl_allowed_mechs => "PLAIN", :sasl_allow_insecure_mechs => true}
s = SASLHandler.new("amqp://user:default_password@", opts)
- TestContainer.new(s, opts).run
+ TestContainer.new(s, opts, __method__).run
assert_equal(2, s.connections.size)
assert_equal("user", s.auth_user)
end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[4/5] qpid-proton git commit: WIP: Fix bad connect/listen host
resolve error
Posted by ac...@apache.org.
WIP: Fix bad connect/listen host resolve error
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/5cb9775d
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/5cb9775d
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/5cb9775d
Branch: refs/heads/ruby-api
Commit: 5cb9775d5924198b17e189f8692a265181090388
Parents: f252b2f
Author: Alan Conway <ac...@redhat.com>
Authored: Fri Dec 15 11:34:44 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Fri Dec 15 11:34:44 2017 -0500
----------------------------------------------------------------------
proton-c/bindings/ruby/lib/core/container.rb | 26 +++++++++++++++++++--
proton-c/bindings/ruby/tests/test_container.rb | 14 +++++++++--
2 files changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5cb9775d/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 242356f..5dc9d60 100644
--- a/proton-c/bindings/ruby/lib/core/container.rb
+++ b/proton-c/bindings/ruby/lib/core/container.rb
@@ -41,6 +41,18 @@ module Qpid::Proton
end
end
+ # Used as the @io when a socket cannot be created due to an erro (e.g resolver fails)
+ # Saves the error and raises it in on_readable so it can be reported via normal channels.
+ class BrokenSocket
+ def initialize(msg) @error = IOError.new(msg); end
+ [:read_nonblock, :write_nonblock, :accept].each do |m|
+ define_method(m) { |*args| raise @error }
+ end
+ [:close_read, :close_write, :close].each do |m|
+ define_method(m) {}
+ end
+ end
+
class ListenTask < Listener
def initialize(io, handler, container)
@@ -177,7 +189,12 @@ module Qpid::Proton
opts[:password] ||= url.password
end
# TODO aconway 2017-10-26: Use SSL for amqps URLs
- connect_io(TCPSocket.new(url.host, url.port), opts)
+ socket = begin
+ TCPSocket.new(url.host, url.port)
+ rescue => e
+ BrokenSocket.new("connect(#{url}): #{e}")
+ end
+ connect_io(socket, opts)
end
# Open an AMQP protocol connection on an existing {IO} object
@@ -202,7 +219,12 @@ module Qpid::Proton
not_stopped
url = Qpid::Proton::uri url
# TODO aconway 2017-11-01: amqps, SSL
- listen_io(TCPServer.new(url.host, url.port), handler)
+ server = begin
+ TCPServer.new(url.host, url.port)
+ rescue => e
+ BrokenSocket.new("listen(#{url}): #{e}")
+ end
+ listen_io(server, handler)
end
# Listen for incoming AMQP connections on an existing server socket.
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5cb9775d/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 044ebf4..d8bd52c 100644
--- a/proton-c/bindings/ruby/tests/test_container.rb
+++ b/proton-c/bindings/ruby/tests/test_container.rb
@@ -149,6 +149,16 @@ class ContainerTest < Minitest::Test
assert_nil l.condition
assert_nil conn.condition
end
+
+ def test_bad_host
+ cont = Container.new(__method__)
+ l = cont.listen("badlisten.example.com:999")
+ c = cont.connect("badconnect.example.com:999")
+ cont.run
+ assert_match(/badlisten.example.com:999/, l.condition.description)
+ assert_match(/badconnect.example.com:999/, c.transport.condition.description)
+ end
+
end
@@ -201,8 +211,8 @@ mech_list: EXTERNAL DIGEST-MD5 SCRAM-SHA-1 CRAM-MD5 PLAIN ANONYMOUS
")
end
# Tell proton library to use the new configuration
- SASL.config_path(conf_dir)
- SASL.config_name(conf_name)
+ SASL.config_path = conf_dir
+ SASL.config_name = conf_name
end
end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org