qpid_proton 0.18.1 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,148 +0,0 @@
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::Event
21
-
22
- # A Collector is used to register interest in events produced by one
23
- # or more Connection objects.
24
- #
25
- # == Events
26
- #
27
- # @see Qpid::Proton::Event The list of predefined events.
28
- #
29
- # @example
30
- #
31
- # conn = Qpid::Proton::Connection.new
32
- # coll = Qpid::Proton::Event::Collector.new
33
- # conn.collect(coll)
34
- #
35
- # # transport setup not included here for brevity
36
- #
37
- # loop do
38
- #
39
- # # wait for an event and then perform the following
40
- #
41
- # event = collector.peek
42
- #
43
- # unless event.nil?
44
- # case event.type
45
- #
46
- # when Qpid::Proton::Event::CONNECTION_REMOTE_CLOSE
47
- # conn = event.context # the context here is the connection
48
- # # the remote connection closed, so only close our side if it's
49
- # # still open
50
- # if !(conn.state & Qpid::Proton::Endpoint::LOCAL_CLOSED)
51
- # conn.close
52
- # end
53
- #
54
- # when Qpid::proton::Event::SESSION_REMOTE_OPEN
55
- # session = event.session # the context here is the session
56
- # # the remote session is now open, so if the local session is
57
- # # uninitialized, then open it
58
- # if session.state & Qpid::Proton::Endpoint::LOCAL_UNINIT
59
- # session.incoming_capacity = 1000000
60
- # session.open
61
- # end
62
- #
63
- # end
64
- #
65
- # # remove the processed event and get the next event
66
- # # the loop will exit when we have no more events to process
67
- # collector.pop
68
- # event = collector.peek
69
- #
70
- # end
71
- #
72
- class Collector
73
-
74
- # @private
75
- attr_reader :impl
76
-
77
- # Creates a new Collector.
78
- #
79
- def initialize
80
- @impl = Cproton.pn_collector
81
- ObjectSpace.define_finalizer(self, self.class.finalize!(@impl))
82
- end
83
-
84
- # @private
85
- def self.finalize!(impl)
86
- proc {
87
- Cproton.pn_collector_free(impl)
88
- }
89
- end
90
-
91
- # Releases the collector.
92
- #
93
- # Once in a released state, a collector will drain any internally queued
94
- # events, shrink its memory footprint to a minimu, and discard any newly
95
- # created events.
96
- #
97
- def release
98
- Cproton.pn_collector_release(@impl)
99
- end
100
-
101
- # Place a new event on the collector.
102
- #
103
- # This operation will create a new event of the given type and context
104
- # and return a new Event instance. In some cases an event of a given
105
- # type can be elided. When this happens, this operation will return
106
- # nil.
107
- #
108
- # @param context [Object] The event context.
109
- # @param event_type [EventType] The event type.
110
- #
111
- # @return [Event] the event if it was queued
112
- # @return [nil] if it was elided
113
- #
114
- def put(context, event_type)
115
- Cproton.pn_collector_put(@impl, Cproton.pn_rb2void(context), event_type.type_code)
116
- end
117
-
118
- # Access the head event.
119
- #
120
- # This operation will continue to return the same event until it is
121
- # cleared by using #pop. The pointer return by this operation will be
122
- # valid until ::pn_collector_pop is invoked or #free is called, whichever
123
- # happens sooner.
124
- #
125
- # @return [Event] the head event
126
- # @return [nil] if there are no events
127
- #
128
- # @see #pop
129
- # @see #put
130
- #
131
- def peek
132
- Event.wrap(Cproton.pn_collector_peek(@impl))
133
- end
134
-
135
- # Clear the head event.
136
- #
137
- # @return [Boolean] true if an event was removed
138
- #
139
- # @see #release
140
- # @see #peek
141
- #
142
- def pop
143
- Cproton.pn_collector_pop(@impl)
144
- end
145
-
146
- end
147
-
148
- end
data/lib/event/event.rb DELETED
@@ -1,318 +0,0 @@
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
21
-
22
- module Event
23
-
24
- # @private
25
- def self.event_type(const_name, method_name = nil) # :nodoc:
26
- unless Cproton.const_defined?(const_name)
27
- raise RuntimeError.new("no such constant: #{const_name}")
28
- end
29
-
30
- const_value = Cproton.const_get(const_name)
31
- method_name = "on_#{const_name.to_s[3..-1]}".downcase if method_name.nil?
32
-
33
- EventType.new(const_value, method_name)
34
- end
35
-
36
- # Defined as a programming convenience. No even of this type will ever
37
- # be generated.
38
- NONE = event_type(:PN_EVENT_NONE)
39
-
40
- # A reactor has been started.
41
- REACTOR_INIT = event_type(:PN_REACTOR_INIT)
42
- # A reactor has no more events to process.
43
- REACTOR_QUIESCED = event_type(:PN_REACTOR_QUIESCED)
44
- # A reactor has been stopred.
45
- REACTOR_FINAL = event_type(:PN_REACTOR_FINAL)
46
-
47
- # A timer event has occurred.
48
- TIMER_TASK = event_type(:PN_TIMER_TASK)
49
-
50
- # A connection has been created. This is the first even that will ever
51
- # be issued for a connection.
52
- CONNECTION_INIT = event_type(:PN_CONNECTION_INIT)
53
- # A conneciton has been bound toa transport.
54
- CONNECTION_BOUND = event_type(:PN_CONNECTION_BOUND)
55
- # A connection has been unbound from its transport.
56
- CONNECTION_UNBOUND = event_type(:PN_CONNECTION_UNBOUND)
57
- # A local connection endpoint has been opened.
58
- CONNECTION_LOCAL_OPEN = event_type(:PN_CONNECTION_LOCAL_OPEN)
59
- # A local connection endpoint has been closed.
60
- CONNECTION_LOCAL_CLOSE = event_type(:PN_CONNECTION_LOCAL_CLOSE)
61
- # A remote endpoint has opened its connection.
62
- CONNECTION_REMOTE_OPEN = event_type(:PN_CONNECTION_REMOTE_OPEN)
63
- # A remote endpoint has closed its connection.
64
- CONNECTION_REMOTE_CLOSE = event_type(:PN_CONNECTION_REMOTE_CLOSE)
65
- # A connection has been freed and any outstanding processing has been
66
- # completed. This is the final event htat will ever be issued for a
67
- # connection
68
- CONNECTION_FINAL = event_type(:PN_CONNECTION_FINAL)
69
-
70
- # A session has been created. This is the first event that will ever be
71
- # issues for a session.
72
- SESSION_INIT = event_type(:PN_SESSION_INIT)
73
- # A local session endpoint has been opened.
74
- SESSION_LOCAL_OPEN = event_type(:PN_SESSION_LOCAL_OPEN)
75
- # A local session endpoint has been closed.
76
- SESSION_LOCAL_CLOSE = event_type(:PN_SESSION_LOCAL_CLOSE)
77
- # A remote endpoint has opened its session.
78
- SESSION_REMOTE_OPEN = event_type(:PN_SESSION_REMOTE_OPEN)
79
- # A remote endpoint has closed its session.
80
- SESSION_REMOTE_CLOSE = event_type(:PN_SESSION_REMOTE_CLOSE)
81
- # A session has been freed and any outstanding processing has been
82
- # completed. This is the final event that will ever be issued for a
83
- # session
84
- SESSION_FINAL = event_type(:PN_SESSION_FINAL)
85
-
86
- # A link has been created. This is the first event that will ever be
87
- # issued for a link.
88
- LINK_INIT = event_type(:PN_LINK_INIT)
89
- # A local link endpoint has been opened.
90
- LINK_LOCAL_OPEN = event_type(:PN_LINK_LOCAL_OPEN)
91
- # A local link endpoint has been closed.
92
- LINK_LOCAL_CLOSE = event_type(:PN_LINK_LOCAL_CLOSE)
93
- # A local link endpoint has been detached.
94
- LINK_LOCAL_DETACH = event_type(:PN_LINK_LOCAL_DETACH)
95
- # A remote endpoint has opened its link.
96
- LINK_REMOTE_OPEN = event_type(:PN_LINK_REMOTE_OPEN)
97
- # A remote endpoint has closed its link.
98
- LINK_REMOTE_CLOSE = event_type(:PN_LINK_REMOTE_CLOSE)
99
- # A remote endpoint has detached its link.
100
- LINK_REMOTE_DETACH = event_type(:PN_LINK_REMOTE_DETACH)
101
- # The flow control state for a link has changed.
102
- LINK_FLOW = event_type(:PN_LINK_FLOW)
103
- # A link has been freed and any outstanding processing has been completed.
104
- # This is the final event htat will ever be issued for a link.
105
- LINK_FINAL = event_type(:PN_LINK_FINAL)
106
-
107
- # A delivery has been created or updated.
108
- DELIVERY = event_type(:PN_DELIVERY)
109
-
110
- # A transport has new data to read and/or write.
111
- TRANSPORT = event_type(:PN_TRANSPORT)
112
- # Indicates that a transport error has occurred.
113
- # @see Transport#condition To access the details of the error.
114
- TRANSPORT_ERROR = event_type(:PN_TRANSPORT_ERROR)
115
- # Indicates that the head of a transport has been closed. This means the
116
- # transport will never produce more bytes for output to the network.
117
- TRANSPORT_HEAD_CLOSED = event_type(:PN_TRANSPORT_HEAD_CLOSED)
118
- # Indicates that the trail of a transport has been closed. This means the
119
- # transport will never be able to process more bytes from the network.
120
- TRANSPORT_TAIL_CLOSED = event_type(:PN_TRANSPORT_TAIL_CLOSED)
121
- # Indicates that both the head and tail of a transport are closed.
122
- TRANSPORT_CLOSED = event_type(:PN_TRANSPORT_CLOSED)
123
-
124
- SELECTABLE_INIT = event_type(:PN_SELECTABLE_INIT)
125
- SELECTABLE_UPDATED = event_type(:PN_SELECTABLE_UPDATED)
126
- SELECTABLE_READABLE = event_type(:PN_SELECTABLE_READABLE)
127
- SELECTABLE_WRITABLE = event_type(:PN_SELECTABLE_WRITABLE)
128
- SELECTABLE_EXPIRED = event_type(:PN_SELECTABLE_EXPIRED)
129
- SELECTABLE_ERROR = event_type(:PN_SELECTABLE_ERROR)
130
- SELECTABLE_FINAL = event_type(:PN_SELECTABLE_FINAL)
131
-
132
- # An Event provides notification of a state change within the protocol
133
- # engine.
134
- #
135
- # Every event has a type that identifies what sort of state change has
136
- # occurred, along with a pointer to the object whose state has changed,
137
- # and also any associated objects.
138
- #
139
- # For more details on working with Event, please refer to Collector.
140
- #
141
- # @see Qpid::Proton::Event The list of predefined events.
142
- #
143
- class Event < EventBase
144
-
145
- # @private
146
- include Qpid::Proton::Util::ClassWrapper
147
- # @private
148
- include Qpid::Proton::Util::Wrapper
149
-
150
- # Creates a Ruby object for the given pn_event_t.
151
- #
152
- # @private
153
- def self.wrap(impl, number = nil)
154
- return nil if impl.nil?
155
-
156
- result = self.fetch_instance(impl, :pn_event_attachments)
157
- return result unless result.nil?
158
- number = Cproton.pn_event_type(impl) if number.nil?
159
- event = Event.new(impl, number)
160
- return event.context if event.context.is_a? EventBase
161
- return event
162
- end
163
-
164
- # @private
165
- def initialize(impl, number)
166
- @impl = impl
167
- class_name = Cproton.pn_class_name(Cproton.pn_event_class(impl))
168
- context = class_wrapper(class_name, Cproton.pn_event_context(impl))
169
- event_type = EventType.by_type(Cproton.pn_event_type(impl))
170
- super(class_name, context, event_type)
171
- @type = EventType.by_type(number)
172
- self.class.store_instance(self, :pn_event_attachments)
173
- end
174
-
175
- # Notifies the handler(s) of this event.
176
- #
177
- # If a handler responds to the event's method then that method is invoked
178
- # and passed the event. Otherwise, if the handler defines the
179
- # +on_unhandled+ method, then that will be invoked instead.
180
- #
181
- # If the handler defines a +handlers+ method then that will be invoked and
182
- # passed the event afterward.
183
- #
184
- # @example
185
- #
186
- # class FallbackEventHandler
187
- #
188
- # # since it now defines a handlers method, any event will iterate
189
- # # through them and invoke the +dispatch+ method on each
190
- # attr_accessor handlers
191
- #
192
- # def initialize
193
- # @handlers = []
194
- # end
195
- #
196
- # # invoked for any event not otherwise handled
197
- # def on_unhandled(event)
198
- # puts "Unable to invoke #{event.type.method} on #{event.context}."
199
- # end
200
- #
201
- # end
202
- #
203
- # @param handler [Object] An object which implements either the event's
204
- # handler method or else responds to :handlers with an array of other
205
- # handlers.
206
- #
207
- def dispatch(handler, type = nil)
208
- type = @type if type.nil?
209
- if handler.is_a?(Qpid::Proton::Handler::WrappedHandler)
210
- Cproton.pn_handler_dispatch(handler.impl, @impl, type.number)
211
- else
212
- result = Qpid::Proton::Event.dispatch(handler, type.method, self)
213
- if (result != "DELEGATED") && handler.respond_to?(:handlers)
214
- handler.handlers.each do |hndlr|
215
- self.dispatch(hndlr)
216
- end
217
- end
218
- end
219
- end
220
-
221
- # Returns the reactor for this event.
222
- #
223
- # @return [Reactor, nil] The reactor.
224
- #
225
- def reactor
226
- impl = Cproton.pn_event_reactor(@impl)
227
- Qpid::Proton::Util::ClassWrapper::WRAPPERS["pn_reactor"].call(impl)
228
- end
229
-
230
- def container
231
- impl = Cproton.pn_event_reactor(@impl)
232
- Qpid::Proton::Util::ClassWrapper::WRAPPERS["pn_reactor"].call(impl)
233
- end
234
-
235
- # Returns the transport for this event.
236
- #
237
- # @return [Transport, nil] The transport.
238
- #
239
- def transport
240
- Qpid::Proton::Transport.wrap(Cproton.pn_event_transport(@impl))
241
- end
242
-
243
- # Returns the Connection for this event.
244
- #
245
- # @return [Connection, nil] The connection.
246
- #
247
- def connection
248
- Qpid::Proton::Connection.wrap(Cproton.pn_event_connection(@impl))
249
- end
250
-
251
- # Returns the Session for this event.
252
- #
253
- # @return [Session, nil] The session
254
- #
255
- def session
256
- Qpid::Proton::Session.wrap(Cproton.pn_event_session(@impl))
257
- end
258
-
259
- # Returns the Link for this event.
260
- #
261
- # @return [Link, nil] The link.
262
- #
263
- def link
264
- Qpid::Proton::Link.wrap(Cproton.pn_event_link(@impl))
265
- end
266
-
267
- # Returns the Sender, or nil if there is no Link, associated with this
268
- # event if that link is a sender.
269
- #
270
- # @return [Sender, nil] The sender.
271
- #
272
- def sender
273
- return self.link if !self.link.nil? && self.link.sender?
274
- end
275
-
276
- # Returns the Receiver, or nil if there is no Link, associated with this
277
- # event if that link is a receiver.
278
- #
279
- # @return [Receiver, nil] The receiver.
280
- #
281
- def receiver
282
- return self.link if !self.link.nil? && self.link.receiver?
283
- end
284
-
285
- # Returns the Delivery associated with this event.
286
- #
287
- # @return [Delivery, nil] The delivery.
288
- #
289
- def delivery
290
- Qpid::Proton::Delivery.wrap(Cproton.pn_event_delivery(@impl))
291
- end
292
-
293
- # Sets the message.
294
- #
295
- # @param message [Qpid::Proton::Message] The message
296
- #
297
- def message=(message)
298
- @message = message
299
- end
300
-
301
- # Returns the message.
302
- #
303
- # @return [Qpid::Proton::Message] The message.
304
- #
305
- def message
306
- @message
307
- end
308
-
309
- # @private
310
- def to_s
311
- "#{self.type}(#{self.context})"
312
- end
313
-
314
- end
315
-
316
- end
317
-
318
- end