qpid_proton 0.9.0 → 0.10

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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/lib/codec/data.rb +912 -0
  3. data/lib/codec/mapping.rb +169 -0
  4. data/lib/{qpid_proton/tracker.rb → core/base_handler.rb} +4 -15
  5. data/lib/core/connection.rb +328 -0
  6. data/lib/core/delivery.rb +271 -0
  7. data/lib/core/disposition.rb +158 -0
  8. data/lib/core/endpoint.rb +140 -0
  9. data/lib/{qpid_proton → core}/exceptions.rb +43 -2
  10. data/lib/core/link.rb +387 -0
  11. data/lib/core/message.rb +633 -0
  12. data/lib/core/receiver.rb +95 -0
  13. data/lib/core/sasl.rb +94 -0
  14. data/lib/core/selectable.rb +130 -0
  15. data/lib/core/sender.rb +76 -0
  16. data/lib/core/session.rb +163 -0
  17. data/lib/core/ssl.rb +164 -0
  18. data/lib/{qpid_proton/version.rb → core/ssl_details.rb} +7 -6
  19. data/lib/core/ssl_domain.rb +156 -0
  20. data/lib/core/terminus.rb +218 -0
  21. data/lib/core/transport.rb +411 -0
  22. data/lib/core/url.rb +77 -0
  23. data/lib/event/collector.rb +148 -0
  24. data/lib/event/event.rb +318 -0
  25. data/lib/event/event_base.rb +91 -0
  26. data/lib/event/event_type.rb +71 -0
  27. data/lib/handler/acking.rb +70 -0
  28. data/lib/handler/c_adaptor.rb +47 -0
  29. data/lib/handler/c_flow_controller.rb +33 -0
  30. data/lib/handler/endpoint_state_handler.rb +217 -0
  31. data/lib/handler/incoming_message_handler.rb +74 -0
  32. data/lib/handler/messaging_handler.rb +218 -0
  33. data/lib/handler/outgoing_message_handler.rb +98 -0
  34. data/lib/handler/wrapped_handler.rb +76 -0
  35. data/lib/messenger/messenger.rb +702 -0
  36. data/lib/messenger/subscription.rb +37 -0
  37. data/lib/messenger/tracker.rb +38 -0
  38. data/lib/messenger/tracker_status.rb +69 -0
  39. data/lib/qpid_proton.rb +106 -16
  40. data/lib/reactor/acceptor.rb +41 -0
  41. data/lib/reactor/backoff.rb +41 -0
  42. data/lib/reactor/connector.rb +98 -0
  43. data/lib/reactor/container.rb +272 -0
  44. data/lib/reactor/global_overrides.rb +44 -0
  45. data/lib/reactor/link_option.rb +90 -0
  46. data/lib/reactor/reactor.rb +198 -0
  47. data/lib/reactor/session_per_connection.rb +45 -0
  48. data/lib/reactor/ssl_config.rb +41 -0
  49. data/lib/reactor/task.rb +39 -0
  50. data/lib/{qpid_proton/subscription.rb → reactor/urls.rb} +12 -13
  51. data/lib/{qpid_proton → types}/array.rb +28 -29
  52. data/lib/types/described.rb +63 -0
  53. data/lib/{qpid_proton → types}/hash.rb +4 -3
  54. data/lib/types/strings.rb +62 -0
  55. data/lib/util/class_wrapper.rb +54 -0
  56. data/lib/util/condition.rb +45 -0
  57. data/lib/util/constants.rb +85 -0
  58. data/lib/util/engine.rb +82 -0
  59. data/lib/util/error_handler.rb +127 -0
  60. data/lib/util/handler.rb +41 -0
  61. data/lib/util/reactor.rb +32 -0
  62. data/lib/util/swig_helper.rb +114 -0
  63. data/lib/util/timeout.rb +50 -0
  64. data/lib/util/uuid.rb +32 -0
  65. data/lib/util/version.rb +30 -0
  66. data/lib/util/wrapper.rb +124 -0
  67. metadata +67 -21
  68. data/ext/cproton/cproton.c +0 -22196
  69. data/lib/qpid_proton/data.rb +0 -788
  70. data/lib/qpid_proton/described.rb +0 -66
  71. data/lib/qpid_proton/exception_handling.rb +0 -127
  72. data/lib/qpid_proton/filters.rb +0 -67
  73. data/lib/qpid_proton/mapping.rb +0 -170
  74. data/lib/qpid_proton/message.rb +0 -621
  75. data/lib/qpid_proton/messenger.rb +0 -702
  76. data/lib/qpid_proton/selectable.rb +0 -126
  77. data/lib/qpid_proton/strings.rb +0 -65
  78. data/lib/qpid_proton/tracker_status.rb +0 -73
@@ -0,0 +1,74 @@
1
+ #--
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #++
19
+
20
+ module Qpid::Proton::Handler
21
+
22
+ # A utility for simpler and more intuitive handling of delivery events
23
+ # related to incoming messages.
24
+ #
25
+ class IncomingMessageHandler < Qpid::Proton::BaseHandler
26
+
27
+ include Acking
28
+
29
+ def initialize(auto_accept = true, delegate = nil)
30
+ @delegate = delegate
31
+ @auto_accept = auto_accept
32
+ end
33
+
34
+ def on_delivery(event)
35
+ delivery = event.delivery
36
+ return unless delivery.link.receiver?
37
+ if delivery.readable? && !delivery.partial?
38
+ event.message = Qpid::Proton::Util::Engine.receive_message(delivery)
39
+ if event.link.local_closed?
40
+ if @auto_accept
41
+ delivery.update(Qpid::Proton::Disposition::RELEASED)
42
+ delivery.settle
43
+ end
44
+ else
45
+ begin
46
+ self.on_message(event)
47
+ if @auto_accept
48
+ delivery.update(Qpid::Proton::Disposition::ACCEPTED)
49
+ delivery.settle
50
+ end
51
+ rescue Qpid::Proton::Reject
52
+ delivery.update(Qpid::Proton::Disposition::REJECTED)
53
+ delivery.settle
54
+ rescue Qpid::Proton::Release
55
+ delivery.update(Qpid::Proton::Disposition::MODIFIED)
56
+ delivery.settle
57
+ end
58
+ end
59
+ elsif delivery.updated? && delivery.settled?
60
+ self.on_settled(event)
61
+ end
62
+ end
63
+
64
+ def on_message(event)
65
+ Qpid::Proton::Event.dispatch(@delegate, :on_message, event) if !@delegate.nil?
66
+ end
67
+
68
+ def on_settled(event)
69
+ Qpid::Proton::Event.dispatch(@delegate, :on_settled, event) if !@delegate.nil?
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,218 @@
1
+ #--
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #++
19
+
20
+ module Qpid::Proton::Handler
21
+
22
+ # A general purpose handler that simplifies processing events.
23
+ #
24
+ # @example
25
+ #
26
+ class MessagingHandler < Qpid::Proton::BaseHandler
27
+
28
+ attr_reader :handlers
29
+
30
+ # Creates a new instance.
31
+ #
32
+ # @param [Fixnum] prefetch
33
+ # @param [Boolean] auto_accept
34
+ # @param [Boolean] auto_settle
35
+ # @param [Boolean] peer_close_is_error
36
+ #
37
+ def initialize(prefetch = 10, auto_accept = true, auto_settle = true, peer_close_is_error = false)
38
+ @handlers = Array.new
39
+ @handlers << CFlowController.new(prefetch) unless prefetch.zero?
40
+ @handlers << EndpointStateHandler.new(peer_close_is_error, self)
41
+ @handlers << IncomingMessageHandler.new(auto_accept, self)
42
+ @handlers << OutgoingMessageHandler.new(auto_settle,self)
43
+ end
44
+
45
+ # Called when the peer closes the connection with an error condition.
46
+ #
47
+ # @param event [Qpid::Proton::Event::Event] The event.
48
+ #
49
+ def on_connection_error(event)
50
+ EndpointStateHandler.print_error(event.connection, "connection")
51
+ end
52
+
53
+ # Called when the peer closes the session with an error condition.
54
+ #
55
+ # @param event [Qpid:Proton::Event::Event] The event.
56
+ #
57
+ def on_session_error(event)
58
+ EndpointStateHandler.print_error(event.session, "session")
59
+ event.connection.close
60
+ end
61
+
62
+ # Called when the peer closes the link with an error condition.
63
+ #
64
+ # @param event [Qpid::Proton::Event::Event] The event.
65
+ #
66
+ def on_link_error(event)
67
+ EndpointStateHandler.print_error(event.link, "link")
68
+ event.connection.close
69
+ end
70
+
71
+ # Called when the event loop starts.
72
+ #
73
+ # @param event [Qpid::Proton::Event::Event] The event.
74
+ #
75
+ def on_reactor_init(event)
76
+ self.on_start(event)
77
+ end
78
+
79
+ # Called when the event loop starts.
80
+ #
81
+ # This method needs to be overridden.
82
+ #
83
+ # @param event [Qpid::Proton::Event::Event] The event.
84
+ #
85
+ def on_start(event)
86
+ end
87
+
88
+ # Called when the connection is closed.
89
+ #
90
+ # This method needs to be overridden.
91
+ #
92
+ # @param event [Qpid::Proton::Event::Event] The event.
93
+ #
94
+ def on_connection_closed(event)
95
+ end
96
+
97
+ # Called when the session is closed.
98
+ #
99
+ # This method needs to be overridden.
100
+ #
101
+ # @param event [Qpid::Proton::Event::Event] The event.
102
+ #
103
+ def on_session_closed(event)
104
+ end
105
+
106
+ # Called when the link is closed.
107
+ #
108
+ # This method needs to be overridden.
109
+ #
110
+ # @param event [Qpid::Proton::Event::Event] The event.
111
+ #
112
+ def on_link_closed(event)
113
+ end
114
+
115
+ # Called when the peer initiates the closing of the connection.
116
+ #
117
+ # This method needs to be overridden.
118
+ #
119
+ # @param event [Qpid::Proton::Event::Event] The event.
120
+ #
121
+ def on_connection_closing(event)
122
+ end
123
+
124
+ # Called when the peer initiates the closing of the session.
125
+ #
126
+ # This method needs to be overridden.
127
+ #
128
+ # @param event [Qpid::Proton::Event::Event] The event.
129
+ #
130
+ def on_session_closing(event)
131
+ end
132
+
133
+ # Called when the peer initiates the closing of the link.
134
+ #
135
+ # This method needs to be overridden.
136
+ #
137
+ # @param event [Qpid::Proton::Event::Event] The event.
138
+ #
139
+ def on_link_closing(event)
140
+ end
141
+
142
+ # Called when the socket is disconnected.
143
+ #
144
+ # This method needs to be overridden.
145
+ #
146
+ # @param event [Qpid::Proton::Event::Event] The event.
147
+ #
148
+ def on_disconnected(event)
149
+ end
150
+
151
+ # Called when the sender link has credit and messages can therefore
152
+ # be transferred.
153
+ #
154
+ # This method needs to be overridden.
155
+ #
156
+ # @param event [Qpid::Proton::Event::Event] The event.
157
+ #
158
+ def on_sendable(event)
159
+ end
160
+
161
+ # Called when the remote peer accepts an outgoing message.
162
+ #
163
+ # This method needs to be overridden.
164
+ #
165
+ # @param event [Qpid::Proton::Event::Event] The event.
166
+ #
167
+ def on_accepted(event)
168
+ end
169
+
170
+ # Called when the remote peer rejects an outgoing message.
171
+ #
172
+ # This method needs to be overridden.
173
+ #
174
+ # @param event [Qpid::Proton::Event::Event] The event.
175
+ #
176
+ def on_rejected(event)
177
+ end
178
+
179
+ # Called when the remote peer releases an outgoing message.
180
+ #
181
+ # Note that this may be in response to either the RELEASE or
182
+ # MODIFIED state as defined by the AMPQ specification.
183
+ #
184
+ # This method needs to be overridden.
185
+ #
186
+ # @param event [Qpid::Proton::Event::Event] The event.
187
+ #
188
+ def on_released(event)
189
+ end
190
+
191
+ # Called when the remote peer has settled hte outgoing message.
192
+ #
193
+ # This is the point at which it should never be retransmitted.
194
+ #
195
+ # This method needs to be overridden.
196
+ #
197
+ # @param event [Qpid::Proton::Event::Event] The event.
198
+ #
199
+ def on_settled(event)
200
+ end
201
+
202
+ # Called when a message is received.
203
+ #
204
+ # The message itself can be obtained as a property on the event. For
205
+ # the purpose of referring to this message in further actions, such as
206
+ # explicitly accepting it) the delivery should be used. This is also
207
+ # obtainable vi a property on the event.
208
+ #
209
+ # This method needs to be overridden.
210
+ #
211
+ # @param event [Qpid::Proton::Event::Event] The event.
212
+ #
213
+ def on_message(event)
214
+ end
215
+
216
+ end
217
+
218
+ end
@@ -0,0 +1,98 @@
1
+ #--
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #++
19
+
20
+ module Qpid::Proton::Handler
21
+
22
+ # A utility for simpler and more intuitive handling of delivery events
23
+ # related to outgoing messages.
24
+ #
25
+ class OutgoingMessageHandler < Qpid::Proton::BaseHandler
26
+
27
+ def initialize(auto_settle = true, delegate = nil)
28
+ @auto_settle = auto_settle
29
+ @delegate = delegate
30
+ end
31
+
32
+ def on_link_flow(event)
33
+ self.on_sendable(event) if event.link.sender? && event.link.credit > 0
34
+ end
35
+
36
+ def on_delivery(event)
37
+ delivery = event.delivery
38
+ if delivery.link.sender? && delivery.updated?
39
+ if delivery.remote_accepted?
40
+ self.on_accepted(event)
41
+ elsif delivery.remote_rejected?
42
+ self.on_rejected(event)
43
+ elsif delivery.remote_released? || delivery.remote_modified?
44
+ self.on_released(event)
45
+ end
46
+ self.on_settled(event) if delivery.settled?
47
+ delivery.settle if @auto_settle
48
+ end
49
+ end
50
+
51
+ # Called when the sender link has credit and messages and be transferred.
52
+ #
53
+ # @param event [Qpid::Proton::Event::Event] The event.
54
+ #
55
+ def on_sendable(event)
56
+ Qpid::Proton::Event.dispatch(@delegate, :on_sendable, event) if !@delegate.nil?
57
+ end
58
+
59
+ # Called when the remote peer accepts a sent message.
60
+ #
61
+ # @param event [Qpid::Proton::Event::Event] The event.
62
+ #
63
+ def on_accepted(event)
64
+ Qpid::Proton::Event.dispatch(@delegate, :on_accepted, event) if !@delegate.nil?
65
+ end
66
+
67
+ # Called when the remote peer rejects a sent message.
68
+ #
69
+ # @param event [Qpid::Proton::Event::Event] The event.
70
+ #
71
+ def on_rejected(event)
72
+ Qpid::Proton::Event.dispatch(@delegate, :on_rejected, event) if !@delegate.nil?
73
+ end
74
+
75
+ # Called when the remote peer releases an outgoing message.
76
+ #
77
+ # Note that this may be in resposnse to either the REELAASE or MODIFIED
78
+ # state as defined by the AMQP specification.
79
+ #
80
+ # @param event [Qpid::Proton::Event::Event] The event.
81
+ #
82
+ def on_released(event)
83
+ Qpid::Proton::Event.dispatch(@delegate, :on_released, event) if !@delegate.nil?
84
+ end
85
+
86
+ # Called when the remote peer has settled the outgoing message.
87
+ #
88
+ # This is the point at which it should never be retransmitted.
89
+ #
90
+ # @param event [Qpid::Proton::Event::Event] The event.
91
+ #
92
+ def on_settled(event)
93
+ Qpid::Proton::Event.dispatch(@delegate, :on_settled, event) if !@delegate.nil?
94
+ end
95
+
96
+ end
97
+
98
+ end
@@ -0,0 +1,76 @@
1
+ #--
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #++
19
+
20
+ module Qpid::Proton::Handler
21
+
22
+ class WrappedHandler
23
+
24
+ # @private
25
+ include Qpid::Proton::Util::Wrapper
26
+
27
+ def self.wrap(impl, on_error = nil)
28
+ return nil if impl.nil?
29
+
30
+ result = self.fetch_instance(impl) || WrappedHandler.new(impl)
31
+ result.on_error = on_error
32
+ return result
33
+ end
34
+
35
+ include Qpid::Proton::Util::Handler
36
+
37
+ def initialize(impl_or_constructor)
38
+ if impl_or_constructor.is_a?(Method)
39
+ @impl = impl_or_constructor.call
40
+ else
41
+ @impl = impl_or_constructor
42
+ Cproton.pn_incref(@impl)
43
+ end
44
+ @on_error = nil
45
+ self.class.store_instance(self)
46
+ end
47
+
48
+ def add(handler)
49
+ return if handler.nil?
50
+
51
+ impl = chandler(handler, self.method(:_on_error))
52
+ Cproton.pn_handler_add(@impl, impl)
53
+ Cproton.pn_decref(impl)
54
+ end
55
+
56
+ def clear
57
+ Cproton.pn_handler_clear(@impl)
58
+ end
59
+
60
+ def on_error=(on_error)
61
+ @on_error = on_error
62
+ end
63
+
64
+ private
65
+
66
+ def _on_error(info)
67
+ if self.has?['on_error']
68
+ self['on_error'].call(info)
69
+ else
70
+ raise info
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ end