qpid_proton 0.9.0 → 0.10

Sign up to get free protection for your applications and to get access to all the features.
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,411 @@
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
+ # A transport is used by a connection to interface with the network.
23
+ #
24
+ # A transport is associated with, at most, one Connection.
25
+ #
26
+ # == Client And Server Mode
27
+ #
28
+ # Initially, a transport is configured to be a client tranpsort. It can be
29
+ # configured to act as a server when it is created.
30
+ #
31
+ # A client transport initiates outgoing connections.
32
+ #
33
+ # A client transport must be configured with the protocol layers to use and
34
+ # cannot configure itself automatically.
35
+ #
36
+ # A server transport accepts incoming connections. It can automatically
37
+ # configure itself to include the various protocol layers depending on the
38
+ # incoming protocol headers.
39
+ #
40
+ # == Tracing Data
41
+ #
42
+ # Data can be traced into and out of the transport programmatically by setting
43
+ # the #trace level to one of the defined trace values (TRACE_RAW, TRACE_FRM or
44
+ # TRACE_DRV). Tracing can also be turned off programmatically by setting the
45
+ # #trace level to TRACE_OFF.
46
+ #
47
+ # @example
48
+ #
49
+ # # turns on frame tracing
50
+ # @transport.trace = Qpid::Proton::Transport::TRACE_FRM
51
+ #
52
+ # # ... do something where the frames are of interest, such as debugging
53
+ #
54
+ # # turn tracing off again
55
+ # @transport.trace = Qpid::Proton::Transport::TRACE_NONE
56
+ #
57
+ # Tracing can also be enabled from the command line by defining the similarly
58
+ # named environment variable before starting a Proton application:
59
+ #
60
+ # @example
61
+ #
62
+ # # enable tracing from the command line
63
+ # PN_TRACE_FRM=1 ruby my_proton_app.rb
64
+ #
65
+ class Transport
66
+
67
+ # @private
68
+ include Util::Engine
69
+
70
+ # Turn logging off entirely.
71
+ TRACE_OFF = Cproton::PN_TRACE_OFF
72
+ # Log raw binary data into/out of the transport.
73
+ TRACE_RAW = Cproton::PN_TRACE_RAW
74
+ # Log frames into/out of the transport.
75
+ TRACE_FRM = Cproton::PN_TRACE_FRM
76
+ # Log driver related events; i.e., initialization, end of stream, etc.
77
+ TRACE_DRV = Cproton::PN_TRACE_DRV
78
+
79
+ # @private
80
+ CLIENT = 1
81
+ # @private
82
+ SERVER = 2
83
+
84
+ # @private
85
+ include Util::SwigHelper
86
+
87
+ # @private
88
+ PROTON_METHOD_PREFIX = "pn_transport"
89
+
90
+ # @!attribute channel_max
91
+ #
92
+ # @return [Fixnum] The maximum allowed channel.
93
+ #
94
+ proton_accessor :channel_max
95
+
96
+ # @!attribute [r] remote_channel_max
97
+ #
98
+ # @return [Fixnum] The maximum allowed channel of a transport's remote peer.
99
+ #
100
+ proton_caller :remote_channel_max
101
+
102
+ # @!attribute max_frame_size
103
+ #
104
+ # @return [Fixnum] The maximum frame size.
105
+ #
106
+ proton_accessor :max_frame_size
107
+
108
+ # @!attribute [r] remote_max_frame_size
109
+ #
110
+ # @return [Fixnum] The maximum frame size of the transport's remote peer.
111
+ #
112
+ proton_reader :remote_max_frame_size
113
+
114
+ # @!attribute idle_timeout
115
+ #
116
+ # @return [Fixnum] The idle timeout.
117
+ #
118
+ proton_accessor :idle_timeout
119
+
120
+ # @!attribute [r] remote_idle_timeout
121
+ #
122
+ # @return [Fixnum] The idle timeout for the transport's remote peer.
123
+ #
124
+ proton_accessor :remote_idle_timeout
125
+
126
+ # @!attribute [r] capacity
127
+ #
128
+ # If the engine is in an exception state such as encountering an error
129
+ # condition or reaching the end of stream state, a negative value will
130
+ # be returned indicating the condition.
131
+ #
132
+ # If an error is indicated, further deteails can be obtained from
133
+ # #error.
134
+ #
135
+ # Calls to #process may alter the value of this value. See #process for
136
+ # more details
137
+ #
138
+ # @return [Fixnum] The amount of free space for input following the
139
+ # transport's tail pointer.
140
+ #
141
+ proton_caller :capacity
142
+
143
+ # @!attribute [r] head
144
+ #
145
+ # This referneces queued output data. It reports the bytes of output data.
146
+ #
147
+ # Calls to #pop may alter this attribute, and any data it references.
148
+ #
149
+ # @return [String] The transport's head pointer.
150
+ #
151
+ proton_caller :head
152
+
153
+ # @!attribute [r] tail
154
+ #
155
+ # The amount of free space following this data is reported by #capacity.
156
+ #
157
+ # Calls to #process may alter the value of this attribute.
158
+ #
159
+ # @return [String] The transport's tail pointer.
160
+ #
161
+ proton_caller :tail
162
+
163
+ # @!attribute [r] pending
164
+ #
165
+ # If the ending is in an exceptional state, such as encountering an error
166
+ # condition or reachign the end of the stream state, a negative value will
167
+ # be returned indicating the condition.
168
+ #
169
+ # If an error is indicated, further details can be obtained from #error.
170
+ #
171
+ # Calls to #pop may alter the value of this pointer as well.
172
+ #
173
+ # @return [Fixnum] The number of pending output bytes following the header
174
+ # pointer.
175
+ #
176
+ # @raise [TransportError] If any error other than an end of stream occurs.
177
+ #
178
+ proton_caller :pending
179
+
180
+ # @!attribute [r] closed?
181
+ #
182
+ # A transport is defined to be closed when both the tail and the head are
183
+ # closed. In other words, when both #capacity < 0 and #pending < 0.
184
+ #
185
+ # @return [Boolean] Returns true if the tranpsort is closed.
186
+ #
187
+ proton_caller :closed?
188
+
189
+ # @!attribute [r] frames_output
190
+ #
191
+ # @return [Fixnum] The number of frames output by a transport.
192
+ #
193
+ proton_reader :frames_output
194
+
195
+ # @!attribute [r] frames_input
196
+ #
197
+ # @return [Fixnum] The number of frames input by a transport.
198
+ #
199
+ proton_reader :frames_input
200
+
201
+ # @private
202
+ include Util::ErrorHandler
203
+
204
+ can_raise_error :process, :error_class => TransportError
205
+ can_raise_error :close_tail, :error_class => TransportError
206
+ can_raise_error :pending, :error_class => TransportError, :below => Error::EOS
207
+ can_raise_error :close_head, :error_class => TransportError
208
+
209
+ # @private
210
+ include Util::Wrapper
211
+
212
+ # @private
213
+ def self.wrap(impl)
214
+ return nil if impl.nil?
215
+
216
+ self.fetch_instance(impl, :pn_transport_attachments) || Transport.new(nil, impl)
217
+ end
218
+
219
+ # Creates a new transport instance.
220
+ #
221
+ # @param mode [Fixnum] The transport mode, either CLIENT or SERVER
222
+ # @param impl [pn_transport_t] Should not be used.
223
+ #
224
+ # @raise [TransportError] If the mode is invalid.
225
+ #
226
+ def initialize(mode = nil, impl = Cproton.pn_transport)
227
+ @impl = impl
228
+ if mode == SERVER
229
+ Cproton.pn_transport_set_server(@impl)
230
+ elsif (!mode.nil? && mode != CLIENT)
231
+ raise TransportError.new("cannot create transport for mode: #{mode}")
232
+ end
233
+ self.class.store_instance(self, :pn_transport_attachments)
234
+ end
235
+
236
+ # Returns whether the transport has any buffered data.
237
+ #
238
+ # @return [Boolean] True if the transport has no buffered data.
239
+ #
240
+ def quiesced?
241
+ Cproton.pn_transport_quiesced(@impl)
242
+ end
243
+
244
+ # Returns additional information about the condition of the transport.
245
+ #
246
+ # When a TRANSPORT_ERROR event occurs, this operaiton can be used to
247
+ # access the details of the error condition.
248
+ #
249
+ # The object returned is valid until the Transport is discarded.
250
+ #
251
+ def condition
252
+ condition_to_object Cproton.pn_transport_condition(@impl)
253
+ end
254
+
255
+ # Binds to the given connection.
256
+ #
257
+ # @param connection [Connection] The connection.
258
+ #
259
+ def bind(connection)
260
+ Cproton.pn_transport_bind(@impl, connection.impl)
261
+ end
262
+
263
+ # Unbinds from the previous connection.
264
+ #
265
+ def unbind
266
+ Cproton.pn_transport_unbind(@impl)
267
+ end
268
+
269
+ # Updates the transports trace flags.
270
+ #
271
+ # @param level [Fixnum] The trace level.
272
+ #
273
+ # @see TRACE_OFF
274
+ # @see TRACE_RAW
275
+ # @see TRACE_FRM
276
+ # @see TRACE_DRV
277
+ #
278
+ def trace(level)
279
+ Cproton.pn_transport_trace(@impl, level)
280
+ end
281
+
282
+ # Return the AMQP connection associated with the transport.
283
+ #
284
+ # @return [Connection, nil] The bound connection, or nil.
285
+ #
286
+ def connection
287
+ Connection.wrap(Cproton.pn_transport_connection(@impl))
288
+ end
289
+
290
+ # Log a message to the transport's logging mechanism.
291
+ #
292
+ # This can be using in a debugging scenario as the message will be
293
+ # prepended with the transport's identifier.
294
+ #
295
+ # @param message [String] The message to be logged.
296
+ #
297
+ def log(message)
298
+ Cproton.pn_transport_log(@impl, message)
299
+ end
300
+
301
+ # Pushes the supplied bytes into the tail of the transport.
302
+ #
303
+ # @param data [String] The bytes to be pushed.
304
+ #
305
+ # @return [Fixnum] The number of bytes pushed.
306
+ #
307
+ def push(data)
308
+ Cproton.pn_transport_push(@impl, data, data.length)
309
+ end
310
+
311
+ # Process input data following the tail pointer.
312
+ #
313
+ # Calling this function will cause the transport to consume the specified
314
+ # number of bytes of input occupying the free space following the tail
315
+ # pointer. It may also change the value for #tail, as well as the amount of
316
+ # free space reported by #capacity.
317
+ #
318
+ # @param size [Fixnum] The number of bytes to process.
319
+ #
320
+ # @raise [TransportError] If an error occurs.
321
+ #
322
+ def process(size)
323
+ Cproton.pn_transport_process(@impl, size)
324
+ end
325
+
326
+ # Indicate that the input has reached EOS (end of stream).
327
+ #
328
+ # This tells the transport that no more input will be forthcoming.
329
+ #
330
+ # @raise [TransportError] If an error occurs.
331
+ #
332
+ def close_tail
333
+ Cproton.pn_transport_close_tail(@impl)
334
+ end
335
+
336
+ # Returns the specified number of bytes from the transport's buffers.
337
+ #
338
+ # @param size [Fixnum] The number of bytes to return.
339
+ #
340
+ # @return [String] The data peeked.
341
+ #
342
+ # @raise [TransportError] If an error occurs.
343
+ #
344
+ def peek(size)
345
+ cd, out = Cproton.pn_transport_peek(@impl, size)
346
+ return nil if cd == Qpid::Proton::Error::EOS
347
+ raise TransportError.new if cd < -1
348
+ out
349
+ end
350
+
351
+ # Removes the specified number of bytes from the pending output queue
352
+ # following the transport's head pointer.
353
+ #
354
+ # @param size [Fixnum] The number of bytes to remove.
355
+ #
356
+ def pop(size)
357
+ Cproton.pn_transport_pop(@impl, size)
358
+ end
359
+
360
+ # Indicate that the output has closed.
361
+ #
362
+ # Tells the transport that no more output will be popped.
363
+ #
364
+ # @raise [TransportError] If an error occurs.
365
+ #
366
+ def close_head
367
+ Cproton.pn_transport_close_head(@impl)
368
+ end
369
+
370
+ # Process any pending transport timer events.
371
+ #
372
+ # This method should be called after all pending input has been
373
+ # processed by the transport (see #input), and before generating
374
+ # output (see #output).
375
+ #
376
+ # It returns the deadline for the next pending timer event, if any
377
+ # art present.
378
+ #
379
+ # @param now [Time] The timestamp.
380
+ #
381
+ # @return [Fixnum] If non-zero, the expiration time of the next pending
382
+ # timer event for the transport. The caller must invoke #tick again at
383
+ # least once at or before this deadline occurs.
384
+ #
385
+ def tick(now)
386
+ Cproton.pn_transport_tick(@impl, now)
387
+ end
388
+
389
+ def sasl
390
+ SASL.new(self)
391
+ end
392
+
393
+ # Creates, or returns an existing, SSL object for the transport.
394
+ #
395
+ # @param domain [SSLDomain] The SSL domain.
396
+ # @param session_details [SSLDetails] The SSL session details.
397
+ #
398
+ # @return [SSL] The SSL object.
399
+ #
400
+ def ssl(domain = nil, session_details = nil)
401
+ @ssl ||= SSL.create(self, domain, session_details) if @ssl.nil?
402
+ end
403
+
404
+ # @private
405
+ def ssl?
406
+ !@ssl.nil?
407
+ end
408
+
409
+ end
410
+
411
+ end
data/lib/core/url.rb ADDED
@@ -0,0 +1,77 @@
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
+ class URL
23
+
24
+ attr_reader :scheme
25
+ attr_reader :username
26
+ attr_reader :password
27
+ attr_reader :host
28
+ attr_reader :port
29
+ attr_reader :path
30
+
31
+ def initialize(url = nil, options = {})
32
+ options[:defaults] = true
33
+
34
+ if url
35
+ @url = Cproton.pn_url_parse(url)
36
+ if @url.nil?
37
+ raise ::ArgumentError.new("invalid url: #{url}")
38
+ end
39
+ else
40
+ @url = Cproton.pn_url
41
+ end
42
+ @scheme = Cproton.pn_url_get_scheme(@url)
43
+ @username = Cproton.pn_url_get_username(@url)
44
+ @password = Cproton.pn_url_get_password(@url)
45
+ @host = Cproton.pn_url_get_host(@url)
46
+ @port = Cproton.pn_url_get_port(@url)
47
+ @path = Cproton.pn_url_get_path(@url)
48
+ defaults
49
+ end
50
+
51
+ def port=(port)
52
+ if port.nil?
53
+ Cproton.pn_url_set_port(@url, nil)
54
+ else
55
+ Cproton.pn_url_set_port(@url, port)
56
+ end
57
+ end
58
+
59
+ def port
60
+ Cproton.pn_url_get_port(@url).to_i
61
+ end
62
+
63
+ def to_s
64
+ "#{@scheme}://#{@username.nil? ? '' : @username}#{@password.nil? ? '' : '@' + @password + ':'}#{@host}:#{@port}/#{@path}"
65
+ end
66
+
67
+ private
68
+
69
+ def defaults
70
+ @scheme = @scheme || "ampq"
71
+ @host = @host || "0.0.0.0"
72
+ @port = @port || 5672
73
+ end
74
+
75
+ end
76
+
77
+ end