qpid_proton 0.18.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/ext/cproton/cproton.c +863 -75
  3. data/lib/codec/data.rb +589 -815
  4. data/lib/codec/mapping.rb +142 -126
  5. data/lib/core/condition.rb +89 -0
  6. data/lib/core/connection.rb +188 -228
  7. data/lib/core/connection_driver.rb +202 -0
  8. data/lib/core/container.rb +366 -0
  9. data/lib/core/delivery.rb +76 -251
  10. data/lib/core/disposition.rb +21 -35
  11. data/lib/core/endpoint.rb +21 -53
  12. data/lib/core/event.rb +156 -0
  13. data/lib/core/exceptions.rb +109 -106
  14. data/lib/core/link.rb +24 -49
  15. data/lib/core/listener.rb +82 -0
  16. data/lib/core/message.rb +59 -155
  17. data/lib/core/messaging_handler.rb +190 -0
  18. data/lib/core/receiver.rb +38 -7
  19. data/lib/core/sasl.rb +43 -46
  20. data/lib/core/sender.rb +55 -32
  21. data/lib/core/session.rb +58 -58
  22. data/lib/core/ssl.rb +5 -13
  23. data/lib/core/ssl_details.rb +1 -2
  24. data/lib/core/ssl_domain.rb +5 -8
  25. data/lib/core/terminus.rb +62 -30
  26. data/lib/core/tracker.rb +45 -0
  27. data/lib/core/transfer.rb +121 -0
  28. data/lib/core/transport.rb +62 -97
  29. data/lib/core/uri.rb +73 -0
  30. data/lib/core/url.rb +11 -7
  31. data/lib/handler/adapter.rb +78 -0
  32. data/lib/handler/messaging_adapter.rb +127 -0
  33. data/lib/handler/messaging_handler.rb +128 -178
  34. data/lib/handler/reactor_messaging_adapter.rb +158 -0
  35. data/lib/messenger/messenger.rb +9 -8
  36. data/lib/messenger/subscription.rb +1 -2
  37. data/lib/messenger/tracker.rb +1 -2
  38. data/lib/messenger/tracker_status.rb +1 -2
  39. data/lib/qpid_proton.rb +36 -66
  40. data/lib/reactor/container.rb +40 -234
  41. data/lib/types/array.rb +73 -130
  42. data/lib/types/described.rb +2 -44
  43. data/lib/types/hash.rb +19 -56
  44. data/lib/types/strings.rb +1 -2
  45. data/lib/types/type.rb +68 -0
  46. data/lib/util/{handler.rb → deprecation.rb} +22 -15
  47. data/lib/util/error_handler.rb +4 -25
  48. data/lib/util/timeout.rb +1 -2
  49. data/lib/util/version.rb +1 -2
  50. data/lib/util/wrapper.rb +58 -38
  51. metadata +16 -33
  52. data/lib/core/base_handler.rb +0 -31
  53. data/lib/core/selectable.rb +0 -130
  54. data/lib/event/collector.rb +0 -148
  55. data/lib/event/event.rb +0 -318
  56. data/lib/event/event_base.rb +0 -91
  57. data/lib/event/event_type.rb +0 -71
  58. data/lib/handler/acking.rb +0 -70
  59. data/lib/handler/c_adaptor.rb +0 -47
  60. data/lib/handler/c_flow_controller.rb +0 -33
  61. data/lib/handler/endpoint_state_handler.rb +0 -217
  62. data/lib/handler/incoming_message_handler.rb +0 -74
  63. data/lib/handler/outgoing_message_handler.rb +0 -100
  64. data/lib/handler/wrapped_handler.rb +0 -76
  65. data/lib/reactor/acceptor.rb +0 -41
  66. data/lib/reactor/backoff.rb +0 -41
  67. data/lib/reactor/connector.rb +0 -115
  68. data/lib/reactor/global_overrides.rb +0 -44
  69. data/lib/reactor/link_option.rb +0 -90
  70. data/lib/reactor/reactor.rb +0 -196
  71. data/lib/reactor/session_per_connection.rb +0 -45
  72. data/lib/reactor/ssl_config.rb +0 -41
  73. data/lib/reactor/task.rb +0 -39
  74. data/lib/reactor/urls.rb +0 -45
  75. data/lib/util/class_wrapper.rb +0 -54
  76. data/lib/util/condition.rb +0 -47
  77. data/lib/util/constants.rb +0 -85
  78. data/lib/util/engine.rb +0 -82
  79. data/lib/util/reactor.rb +0 -32
  80. data/lib/util/swig_helper.rb +0 -114
  81. data/lib/util/uuid.rb +0 -32
@@ -0,0 +1,158 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+
19
+ # @private
20
+ module Qpid::Proton
21
+ module Handler
22
+
23
+ # Adapter to convert raw proton events for the old {Handler::MessagingHandler}
24
+ # used by the Reactor.
25
+ class ReactorMessagingAdapter < Adapter
26
+ def initialize handler
27
+ super
28
+ @opts = (handler.options if handler.respond_to?(:options)) || {}
29
+ @opts[:prefetch] ||= 10
30
+ @opts[:peer_close_is_error] = false unless @opts.include? :peer_close_is_error
31
+ [:auto_accept, :auto_settle, :auto_open, :auto_close].each do |k|
32
+ @opts[k] = true unless @opts.include? k
33
+ end
34
+ end
35
+
36
+ alias dispatch forward
37
+
38
+ def delegate(method, event)
39
+ event.method = method # Update the event with the new method
40
+ event.dispatch(@handler) or dispatch(:on_unhandled, event)
41
+ end
42
+
43
+ def delegate_error(method, event)
44
+ event.method = method
45
+ unless event.dispatch(@handler) || dispatch(:on_error, event)
46
+ dispatch(:on_unhandled, event)
47
+ event.connection.close(event.context.condition) if @opts[:auto_close]
48
+ end
49
+ end
50
+
51
+ def on_container_start(container) delegate(:on_start, Event.new(nil, nil, container)); end
52
+ def on_container_stop(container) delegate(:on_stop, Event.new(nil, nil, container)); end
53
+
54
+ # Define repetative on_xxx_open/close methods for each endpoint type
55
+ def self.open_close(endpoint)
56
+ on_opening = :"on_#{endpoint}_opening"
57
+ on_opened = :"on_#{endpoint}_opened"
58
+ on_closing = :"on_#{endpoint}_closing"
59
+ on_closed = :"on_#{endpoint}_closed"
60
+ on_error = :"on_#{endpoint}_error"
61
+
62
+ Module.new do
63
+ define_method(:"on_#{endpoint}_local_open") do |event|
64
+ delegate(on_opened, event) if event.context.remote_open?
65
+ end
66
+
67
+ define_method(:"on_#{endpoint}_remote_open") do |event|
68
+ if event.context.local_open?
69
+ delegate(on_opened, event)
70
+ elsif event.context.local_uninit?
71
+ delegate(on_opening, event)
72
+ event.context.open if @opts[:auto_open]
73
+ end
74
+ end
75
+
76
+ define_method(:"on_#{endpoint}_local_close") do |event|
77
+ delegate(on_closed, event) if event.context.remote_closed?
78
+ end
79
+
80
+ define_method(:"on_#{endpoint}_remote_close") do |event|
81
+ if event.context.remote_condition
82
+ delegate_error(on_error, event)
83
+ elsif event.context.local_closed?
84
+ delegate(on_closed, event)
85
+ elsif @opts[:peer_close_is_error]
86
+ Condition.assign(event.context.__send__(:_remote_condition), "unexpected peer close")
87
+ delegate_error(on_error, event)
88
+ else
89
+ delegate(on_closing, event)
90
+ end
91
+ event.context.close if @opts[:auto_close]
92
+ end
93
+ end
94
+ end
95
+ # Generate and include open_close modules for each endpoint type
96
+ [:connection, :session, :link].each { |endpoint| include open_close(endpoint) }
97
+
98
+ def on_transport_error(event) delegate_error(:on_transport_error, event); end
99
+ def on_transport_closed(event) delegate(:on_transport_closed, event); end
100
+
101
+ # Add flow control for link opening events
102
+ def on_link_local_open(event) super; add_credit(event); end
103
+ def on_link_remote_open(event) super; add_credit(event); end
104
+
105
+
106
+ def on_delivery(event)
107
+ if event.link.receiver? # Incoming message
108
+ d = event.delivery
109
+ if d.aborted?
110
+ delegate(:on_aborted, event)
111
+ d.settle
112
+ elsif d.complete?
113
+ if d.link.local_closed? && @opts[:auto_accept]
114
+ d.release
115
+ else
116
+ begin
117
+ delegate(:on_message, event)
118
+ d.accept if @opts[:auto_accept] && !d.settled?
119
+ rescue Qpid::Proton::Reject
120
+ d.reject
121
+ rescue Qpid::Proton::Release
122
+ d.release(true)
123
+ end
124
+ end
125
+ end
126
+ delegate(:on_settled, event) if d.settled?
127
+ add_credit(event)
128
+ else # Outgoing message
129
+ t = event.tracker
130
+ if t.updated?
131
+ case t.state
132
+ when Qpid::Proton::Delivery::ACCEPTED then delegate(:on_accepted, event)
133
+ when Qpid::Proton::Delivery::REJECTED then delegate(:on_rejected, event)
134
+ when Qpid::Proton::Delivery::RELEASED then delegate(:on_released, event)
135
+ when Qpid::Proton::Delivery::MODIFIED then delegate(:on_modified, event)
136
+ end
137
+ delegate(:on_settled, event) if t.settled?
138
+ t.settle if @opts[:auto_settle]
139
+ end
140
+ end
141
+ end
142
+
143
+ def on_link_flow(event)
144
+ add_credit(event)
145
+ l = event.link
146
+ delegate(:on_sendable, event) if l.sender? && l.open? && l.credit > 0
147
+ end
148
+
149
+ def add_credit(event)
150
+ r = event.receiver
151
+ prefetch = @opts[:prefetch]
152
+ if r && r.open? && (r.drained == 0) && prefetch && (prefetch > r.credit)
153
+ r.flow(prefetch - r.credit)
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
@@ -1,4 +1,3 @@
1
- #
2
1
  # Licensed to the Apache Software Foundation (ASF) under one
3
2
  # or more contributor license agreements. See the NOTICE file
4
3
  # distributed with this work for additional information
@@ -15,9 +14,10 @@
15
14
  # KIND, either express or implied. See the License for the
16
15
  # specific language governing permissions and limitations
17
16
  # under the License.
18
- #
17
+
19
18
 
20
19
  module Qpid::Proton::Messenger
20
+ # @deprecated use {Qpid::Proton::Container}
21
21
  #
22
22
  # The +Messenger+ class defines a high level interface for
23
23
  # sending and receiving Messages. Every Messenger contains
@@ -56,11 +56,7 @@ module Qpid::Proton::Messenger
56
56
  class Messenger
57
57
 
58
58
  include Qpid::Proton::Util::ErrorHandler
59
-
60
- can_raise_error [:send, :receive, :password=, :start, :stop,
61
- :perform_put, :perform_get, :interrupt,
62
- :route, :rewrite, :accept, :reject,
63
- :incoming_window=, :outgoing_window=]
59
+ include Qpid::Proton::Util::Deprecation
64
60
 
65
61
  # Creates a new +Messenger+.
66
62
  #
@@ -72,6 +68,7 @@ module Qpid::Proton::Messenger
72
68
  # * name - the name (def. nil)
73
69
  #
74
70
  def initialize(name = nil)
71
+ deprecated Qpid::Proton::Messenger, Qpid::Proton::Container
75
72
  @impl = Cproton.pn_messenger(name)
76
73
  @selectables = {}
77
74
  ObjectSpace.define_finalizer(self, self.class.finalize!(@impl))
@@ -697,6 +694,10 @@ module Qpid::Proton::Messenger
697
694
  !window.nil? && window.is_a?(Numeric)
698
695
  end
699
696
 
700
- end
697
+ can_raise_error [:send, :receive, :password=, :start, :stop,
698
+ :perform_put, :perform_get, :interrupt,
699
+ :route, :rewrite, :accept, :reject,
700
+ :incoming_window=, :outgoing_window=]
701
701
 
702
+ end
702
703
  end
@@ -1,4 +1,3 @@
1
- #--
2
1
  # Licensed to the Apache Software Foundation (ASF) under one
3
2
  # or more contributor license agreements. See the NOTICE file
4
3
  # distributed with this work for additional information
@@ -15,7 +14,7 @@
15
14
  # KIND, either express or implied. See the License for the
16
15
  # specific language governing permissions and limitations
17
16
  # under the License.
18
- #++
17
+
19
18
 
20
19
  module Qpid::Proton::Messenger
21
20
 
@@ -1,4 +1,3 @@
1
- #--
2
1
  # Licensed to the Apache Software Foundation (ASF) under one
3
2
  # or more contributor license agreements. See the NOTICE file
4
3
  # distributed with this work for additional information
@@ -15,7 +14,7 @@
15
14
  # KIND, either express or implied. See the License for the
16
15
  # specific language governing permissions and limitations
17
16
  # under the License.
18
- #++
17
+
19
18
 
20
19
  module Qpid::Proton::Messenger
21
20
 
@@ -1,4 +1,3 @@
1
- #--
2
1
  # Licensed to the Apache Software Foundation (ASF) under one
3
2
  # or more contributor license agreements. See the NOTICE file
4
3
  # distributed with this work for additional information
@@ -15,7 +14,7 @@
15
14
  # KIND, either express or implied. See the License for the
16
15
  # specific language governing permissions and limitations
17
16
  # under the License.
18
- #++
17
+
19
18
 
20
19
  module Qpid::Proton::Messenger
21
20
 
data/lib/qpid_proton.rb CHANGED
@@ -1,4 +1,3 @@
1
- #--
2
1
  # Licensed to the Apache Software Foundation (ASF) under one
3
2
  # or more contributor license agreements. See the NOTICE file
4
3
  # distributed with this work for additional information
@@ -15,36 +14,40 @@
15
14
  # KIND, either express or implied. See the License for the
16
15
  # specific language governing permissions and limitations
17
16
  # under the License.
18
- #++
17
+
19
18
 
20
19
  require "cproton"
21
20
  require "date"
22
21
  require "weakref"
23
22
 
24
- if RUBY_VERSION < "1.9"
25
- require "kconv"
26
- else
23
+ begin
27
24
  require "securerandom"
25
+ rescue LoadError
26
+ require "kconv" # Ruby < 1.9
27
+ end
28
+
29
+ # Qpid is the top level module for the Qpid project http://qpid.apache.org
30
+ # Definitions for this library are in module {Qpid::Proton}
31
+ module Qpid
32
+ # Proton is a ruby API for sending and receiving AMQP messages in clients or servers.
33
+ # See the {overview}[../file.README.html] for more.
34
+ module Proton
35
+ # Only opened here for module doc comment
36
+ end
28
37
  end
29
38
 
30
39
  # Exception classes
31
40
  require "core/exceptions"
32
41
 
33
42
  # Utility classes
43
+ require "util/deprecation"
34
44
  require "util/version"
35
45
  require "util/error_handler"
36
- require "util/constants"
37
- require "util/swig_helper"
38
- require "util/condition"
39
46
  require "util/wrapper"
40
- require "util/class_wrapper"
41
- require "util/engine"
42
- require "util/uuid"
43
47
  require "util/timeout"
44
- require "util/handler"
45
- require "util/reactor"
46
48
 
47
49
  # Types
50
+ require "types/type"
48
51
  require "types/strings"
49
52
  require "types/hash"
50
53
  require "types/array"
@@ -54,20 +57,18 @@ require "types/described"
54
57
  require "codec/mapping"
55
58
  require "codec/data"
56
59
 
57
- # Event API classes
58
- require "event/event_type"
59
- require "event/event_base"
60
- require "event/event"
61
- require "event/collector"
62
-
63
60
  # Main Proton classes
64
- require "core/selectable"
61
+ require "core/condition"
62
+ require "core/event"
63
+ require "core/uri"
65
64
  require "core/message"
66
65
  require "core/endpoint"
67
66
  require "core/session"
68
67
  require "core/terminus"
69
68
  require "core/disposition"
69
+ require "core/transfer"
70
70
  require "core/delivery"
71
+ require "core/tracker"
71
72
  require "core/link"
72
73
  require "core/sender"
73
74
  require "core/receiver"
@@ -77,56 +78,25 @@ require "core/ssl_domain"
77
78
  require "core/ssl_details"
78
79
  require "core/ssl"
79
80
  require "core/transport"
80
- require "core/base_handler"
81
81
  require "core/url"
82
+ require "core/connection_driver"
82
83
 
83
- # Messenger API classes
84
- require "messenger/subscription"
85
- require "messenger/tracker_status"
86
- require "messenger/tracker"
87
- require "messenger/messenger"
84
+ # Handlers and adapters
85
+ require "handler/adapter"
86
+ require "handler/messaging_adapter"
87
+ require "core/messaging_handler"
88
88
 
89
- # Handler classes
90
- require "handler/c_adaptor"
91
- require "handler/wrapped_handler"
92
- require "handler/acking"
93
- require "handler/endpoint_state_handler"
94
- require "handler/incoming_message_handler"
95
- require "handler/outgoing_message_handler"
96
- require "handler/c_flow_controller"
97
- require "handler/messaging_handler"
89
+ # Main container class
90
+ require "core/container"
98
91
 
99
- # Reactor classes
100
- require "reactor/task"
101
- require "reactor/acceptor"
102
- require "reactor/reactor"
103
- require "reactor/ssl_config"
104
- require "reactor/global_overrides"
105
- require "reactor/urls"
106
- require "reactor/connector"
107
- require "reactor/backoff"
108
- require "reactor/session_per_connection"
92
+ # DEPRECATED Backwards compatibility shims for Reactor API
93
+ require "handler/reactor_messaging_adapter"
94
+ require "handler/messaging_handler" # Keep original name for compatibility
109
95
  require "reactor/container"
110
- require "reactor/link_option"
111
-
112
- module Qpid::Proton
113
- # @private
114
- def self.registry
115
- @registry ||= {}
116
- end
117
-
118
- # @private
119
- def self.add_to_registry(key, value)
120
- self.registry[key] = value
121
- end
122
96
 
123
- # @private
124
- def self.get_from_registry(key)
125
- self.registry[key]
126
- end
97
+ # DEPRECATED Messenger API classes
98
+ require "messenger/subscription"
99
+ require "messenger/tracker_status"
100
+ require "messenger/tracker"
101
+ require "messenger/messenger"
127
102
 
128
- # @private
129
- def self.delete_from_registry(key)
130
- self.registry.delete(key)
131
- end
132
- end
@@ -1,4 +1,3 @@
1
- #--
2
1
  # Licensed to the Apache Software Foundation (ASF) under one
3
2
  # or more contributor license agreements. See the NOTICE file
4
3
  # distributed with this work for additional information
@@ -15,256 +14,63 @@
15
14
  # KIND, either express or implied. See the License for the
16
15
  # specific language governing permissions and limitations
17
16
  # under the License.
18
- #++
19
17
 
20
- module Qpid::Proton::Reactor
21
18
 
22
- private
23
- class InternalTransactionHandler < Qpid::Proton::Handler::OutgoingMessageHandler
19
+ module Qpid::Proton
20
+ module Reactor
24
21
 
25
- def initialize
26
- super
27
- end
28
-
29
- def on_settled(event)
30
- if event.delivery.respond_to? :transaction
31
- event.transaction = event.delivery.transaction
32
- event.delivery.transaction.handle_outcome(event)
33
- end
34
- end
35
-
36
- end
37
-
38
- public
39
- # A representation of the AMQP concept of a container which, loosely
40
- # speaking, is something that establishes links to or from another
41
- # container on which messages are transferred.
42
- #
43
- # This is an extension to the Reactor classthat adds convenience methods
44
- # for creating instances of Qpid::Proton::Connection, Qpid::Proton::Sender
45
- # and Qpid::Proton::Receiver.
46
- class Container < Reactor
47
-
48
- include Qpid::Proton::Util::Reactor
49
-
50
- include Qpid::Proton::Util::UUID
51
-
52
- attr_accessor :container_id
53
- attr_accessor :global_handler
54
-
55
- def initialize(handlers, options = {})
56
- super(handlers, options)
22
+ # @deprecated use {Qpid::Proton::Container}
23
+ class Container < Qpid::Proton::Container
24
+ include Util::Deprecation
57
25
 
58
- # only do the following if we're creating a new instance
59
- if !options.has_key?(:impl)
60
- @ssl = SSLConfig.new
61
- if options[:global_handler]
62
- self.global_handler = GlobalOverrides.new(options[:global_handler])
63
- else
64
- # very ugly, but using self.global_handler doesn't work in the constructor
65
- ghandler = Reactor.instance_method(:global_handler).bind(self).call
66
- ghandler = GlobalOverrides.new(ghandler)
67
- Reactor.instance_method(:global_handler=).bind(self).call(ghandler)
68
- end
69
- @trigger = nil
70
- @container_id = generate_uuid
71
- end
72
- end
26
+ private
27
+ alias super_connect connect # Access to superclass method
73
28
 
74
- # Initiate an AMQP connection.
75
- #
76
- # @param url [String] Connect to URL host:port, using user:password@ if present
77
- # @param opts [Hash] Named options
78
- # For backwards compatibility, can be called with a single parameter opts.
79
- #
80
- # @option opts [String] :url Connect to URL host:port using user:password@ if present.
81
- # @option opts [String] :user user name for authentication if not given by URL
82
- # @option opts [String] :password password for authentication if not given by URL
83
- # @option opts [Numeric] :idle_timeout seconds before closing an idle connection,
84
- # can be a fractional value.
85
- # @option opts [Boolean] :sasl_enabled Enable or disable SASL.
86
- # @option opts [Boolean] :sasl_allow_insecure_mechs Allow mechanisms that disclose clear text
87
- # passwords, even over an insecure connection. By default, such mechanisms are only allowed
88
- # when SSL is enabled.
89
- # @option opts [String] :sasl_allowed_mechs the allowed SASL mechanisms for use on the connection.
90
- #
91
- # @option opts [String] :address *deprecated* use the :url option
92
- # @option opts [Numeric] :heartbeat milliseconds before closing an idle connection.
93
- # *deprecated* use :idle_timeout => heartbeat/1000
94
- #
95
- # @return [Connection] the new connection
96
- #
97
- def connect(url, opts = {})
98
- # Backwards compatible with old connect(options)
99
- if url.is_a? Hash and opts.empty?
100
- opts = url
101
- url = nil
102
- end
103
- conn = self.connection(opts[:handler])
104
- conn.container = self.container_id || generate_uuid
105
- connector = Connector.new(conn, url, opts)
106
- return conn
107
- end
29
+ public
108
30
 
109
- private
110
- def _session(context)
111
- if context.is_a?(Qpid::Proton::URL)
112
- return _session(self.connect(:url => context))
113
- elsif context.is_a?(Qpid::Proton::Session)
114
- return context
115
- elsif context.is_a?(Qpid::Proton::Connection)
116
- if context.session_policy?
117
- return context.session_policy.session(context)
118
- else
119
- return self.create_session(context)
120
- end
121
- else
122
- return context.session
31
+ # @deprecated use {Qpid::Proton::Container}
32
+ def initialize(handlers, opts=nil)
33
+ deprecated Qpid::Proton::Reactor::Container, Qpid::Proton::Container
34
+ h = handlers || (opts && opts[:global_handler]) || Handler::ReactorMessagingAdapter.new(nil)
35
+ id = opts && opts[:container_id]
36
+ super(h, id)
123
37
  end
124
- end
125
38
 
126
- public
127
- # Initiates the establishment of a link over which messages can be sent.
128
- #
129
- # @param context [String, URL] The context.
130
- # @param opts [Hash] Additional options.
131
- # @option opts [String, Qpid::Proton::URL] The target address.
132
- # @option opts [String] :source The source address.
133
- # @option opts [Boolean] :dynamic
134
- # @option opts [Object] :handler
135
- # @option opts [Object] :tag_generator The tag generator.
136
- # @option opts [Hash] :options Addtional link options
137
- #
138
- # @return [Sender] The sender.
139
- #
140
- def create_sender(context, opts = {})
141
- if context.is_a?(::String)
142
- context = Qpid::Proton::URL.new(context)
143
- end
39
+ alias container_id id
40
+ alias global_handler handler
144
41
 
145
- target = opts[:target]
146
- if context.is_a?(Qpid::Proton::URL) && target.nil?
147
- target = context.path
42
+ def connect(opts=nil)
43
+ url = opts && (opts[:url] || opts[:address])
44
+ raise ::ArgumentError.new, "no :url or :address option provided" unless url
45
+ super(url, opts)
148
46
  end
149
47
 
150
- session = _session(context)
151
-
152
- sender = session.sender(opts[:name] ||
153
- id(session.connection.container,
154
- target, opts[:source]))
155
- sender.source.address = opts[:source] if !opts[:source].nil?
156
- sender.target.address = target if target
157
- sender.handler = opts[:handler] if !opts[:handler].nil?
158
- sender.tag_generator = opts[:tag_generator] if !opts[:tag_gnenerator].nil?
159
- _apply_link_options(opts[:options], sender)
160
- sender.open
161
- return sender
162
- end
163
-
164
- # Initiates the establishment of a link over which messages can be received.
165
- #
166
- # There are two accepted arguments for the context
167
- # 1. If a Connection is supplied then the link is established using that
168
- # object. The source, and optionally the target, address can be supplied
169
- # 2. If it is a String or a URL then a new Connection is created on which
170
- # the link will be attached. If a path is specified, but not the source
171
- # address, then the path of the URL is used as the target address.
172
- #
173
- # The name will be generated for the link if one is not specified.
174
- #
175
- # @param context [Connection, URL, String] The connection or the address.
176
- # @param opts [Hash] Additional otpions.
177
- # @option opts [String, Qpid::Proton::URL] The source address.
178
- # @option opts [String] :target The target address
179
- # @option opts [String] :name The link name.
180
- # @option opts [Boolean] :dynamic
181
- # @option opts [Object] :handler
182
- # @option opts [Hash] :options Additional link options.
183
- #
184
- # @return [Receiver
185
- #
186
- def create_receiver(context, opts = {})
187
- if context.is_a?(::String)
188
- context = Qpid::Proton::URL.new(context)
189
- end
190
-
191
- source = opts[:source]
192
- if context.is_a?(Qpid::Proton::URL) && source.nil?
193
- source = context.path
194
- end
195
-
196
- session = _session(context)
197
-
198
- receiver = session.receiver(opts[:name] ||
199
- id(session.connection.container,
200
- source, opts[:target]))
201
- receiver.source.address = source if source
202
- receiver.source.dynamic = true if opts.has_key?(:dynamic) && opts[:dynamic]
203
- receiver.target.address = opts[:target] if !opts[:target].nil?
204
- receiver.handler = opts[:handler] if !opts[:handler].nil?
205
- _apply_link_options(opts[:options], receiver)
206
- receiver.open
207
- return receiver
208
- end
209
-
210
- def declare_transaction(context, handler = nil, settle_before_discharge = false)
211
- if context.respond_to? :txn_ctl && !context.__send__(:txn_ctl).nil?
212
- class << context
213
- attr_accessor :txn_ctl
48
+ def create_sender(context, opts=nil)
49
+ c = context if context.is_a? Qpid::Proton::Connection
50
+ unless c
51
+ url = Qpid::Proton::uri context
52
+ c = super_connect(url, opts)
53
+ opts ||= {}
54
+ opts[:target] ||= url.amqp_address
214
55
  end
215
- context.txn_ctl = self.create_sender(context, nil, "txn-ctl",
216
- InternalTransactionHandler.new())
56
+ c.open_sender opts
217
57
  end
218
- return Transaction.new(context.txn_ctl, handler, settle_before_discharge)
219
- end
220
58
 
221
- # Initiates a server socket, accepting incoming AMQP connections on the
222
- # interface and port specified.
223
- #
224
- # @param url []
225
- # @param ssl_domain []
226
- #
227
- def listen(url, ssl_domain = nil)
228
- url = Qpid::Proton::URL.new(url)
229
- acceptor = self.acceptor(url.host, url.port)
230
- ssl_config = ssl_domain
231
- if ssl_config.nil? && (url.scheme == 'amqps') && @ssl
232
- ssl_config = @ssl.server
233
- end
234
- if !ssl_config.nil?
235
- acceptor.ssl_domain(ssl_config)
236
- end
237
- return acceptor
238
- end
239
-
240
- private
241
-
242
- def id(container, remote, local)
243
- if !local.nil? && !remote.nil?
244
- "#{container}-#{remote}-#{local}"
245
- elsif !local.nil?
246
- "#{container}-#{local}"
247
- elsif !remote.nil?
248
- "#{container}-#{remote}"
249
- else
250
- "#{container}-#{generate_uuid}"
251
- end
252
- end
253
-
254
- def _apply_link_options(options, link)
255
- if !options.nil? && !options.empty?
256
- if !options.is_a?(::List)
257
- options = [Options].flatten
59
+ def create_receiver(context, opts=nil)
60
+ c = context if context.is_a? Qpid::Proton::Connection
61
+ unless c
62
+ url = Qpid::Proton::uri context
63
+ c = super_connect(url, opts)
64
+ opts ||= {}
65
+ opts[:source] ||= url.amqp_address
258
66
  end
259
-
260
- options.each {|option| o.apply(link) if o.test(link)}
67
+ c.open_receiver opts
261
68
  end
262
- end
263
69
 
264
- def to_s
265
- "#{self.class}<@impl=#{Cproton.pni_address_of(@impl)}>"
70
+ def listen(url, ssl_domain = nil)
71
+ # TODO aconway 2017-11-29: ssl_domain
72
+ super(url)
73
+ end
266
74
  end
267
-
268
75
  end
269
-
270
76
  end