qpid_proton 0.9.0 → 0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/codec/data.rb +912 -0
- data/lib/codec/mapping.rb +169 -0
- data/lib/{qpid_proton/tracker.rb → core/base_handler.rb} +4 -15
- data/lib/core/connection.rb +328 -0
- data/lib/core/delivery.rb +271 -0
- data/lib/core/disposition.rb +158 -0
- data/lib/core/endpoint.rb +140 -0
- data/lib/{qpid_proton → core}/exceptions.rb +43 -2
- data/lib/core/link.rb +387 -0
- data/lib/core/message.rb +633 -0
- data/lib/core/receiver.rb +95 -0
- data/lib/core/sasl.rb +94 -0
- data/lib/core/selectable.rb +130 -0
- data/lib/core/sender.rb +76 -0
- data/lib/core/session.rb +163 -0
- data/lib/core/ssl.rb +164 -0
- data/lib/{qpid_proton/version.rb → core/ssl_details.rb} +7 -6
- data/lib/core/ssl_domain.rb +156 -0
- data/lib/core/terminus.rb +218 -0
- data/lib/core/transport.rb +411 -0
- data/lib/core/url.rb +77 -0
- data/lib/event/collector.rb +148 -0
- data/lib/event/event.rb +318 -0
- data/lib/event/event_base.rb +91 -0
- data/lib/event/event_type.rb +71 -0
- data/lib/handler/acking.rb +70 -0
- data/lib/handler/c_adaptor.rb +47 -0
- data/lib/handler/c_flow_controller.rb +33 -0
- data/lib/handler/endpoint_state_handler.rb +217 -0
- data/lib/handler/incoming_message_handler.rb +74 -0
- data/lib/handler/messaging_handler.rb +218 -0
- data/lib/handler/outgoing_message_handler.rb +98 -0
- data/lib/handler/wrapped_handler.rb +76 -0
- data/lib/messenger/messenger.rb +702 -0
- data/lib/messenger/subscription.rb +37 -0
- data/lib/messenger/tracker.rb +38 -0
- data/lib/messenger/tracker_status.rb +69 -0
- data/lib/qpid_proton.rb +106 -16
- data/lib/reactor/acceptor.rb +41 -0
- data/lib/reactor/backoff.rb +41 -0
- data/lib/reactor/connector.rb +98 -0
- data/lib/reactor/container.rb +272 -0
- data/lib/reactor/global_overrides.rb +44 -0
- data/lib/reactor/link_option.rb +90 -0
- data/lib/reactor/reactor.rb +198 -0
- data/lib/reactor/session_per_connection.rb +45 -0
- data/lib/reactor/ssl_config.rb +41 -0
- data/lib/reactor/task.rb +39 -0
- data/lib/{qpid_proton/subscription.rb → reactor/urls.rb} +12 -13
- data/lib/{qpid_proton → types}/array.rb +28 -29
- data/lib/types/described.rb +63 -0
- data/lib/{qpid_proton → types}/hash.rb +4 -3
- data/lib/types/strings.rb +62 -0
- data/lib/util/class_wrapper.rb +54 -0
- data/lib/util/condition.rb +45 -0
- data/lib/util/constants.rb +85 -0
- data/lib/util/engine.rb +82 -0
- data/lib/util/error_handler.rb +127 -0
- data/lib/util/handler.rb +41 -0
- data/lib/util/reactor.rb +32 -0
- data/lib/util/swig_helper.rb +114 -0
- data/lib/util/timeout.rb +50 -0
- data/lib/util/uuid.rb +32 -0
- data/lib/util/version.rb +30 -0
- data/lib/util/wrapper.rb +124 -0
- metadata +67 -21
- data/ext/cproton/cproton.c +0 -22196
- data/lib/qpid_proton/data.rb +0 -788
- data/lib/qpid_proton/described.rb +0 -66
- data/lib/qpid_proton/exception_handling.rb +0 -127
- data/lib/qpid_proton/filters.rb +0 -67
- data/lib/qpid_proton/mapping.rb +0 -170
- data/lib/qpid_proton/message.rb +0 -621
- data/lib/qpid_proton/messenger.rb +0 -702
- data/lib/qpid_proton/selectable.rb +0 -126
- data/lib/qpid_proton/strings.rb +0 -65
- data/lib/qpid_proton/tracker_status.rb +0 -73
@@ -1,702 +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 # :nodoc:
|
21
|
-
|
22
|
-
module Proton # :nodoc:
|
23
|
-
|
24
|
-
# The +Messenger+ class defines a high level interface for
|
25
|
-
# sending and receiving Messages. Every Messenger contains
|
26
|
-
# a single logical queue of incoming messages and a single
|
27
|
-
# logical queue of outgoing messages. These messages in these
|
28
|
-
# queues may be destined for, or originate from, a variety of
|
29
|
-
# addresses.
|
30
|
-
#
|
31
|
-
# The messenger interface is single-threaded. All methods
|
32
|
-
# except one ( #interrupt ) are intended to be used from within
|
33
|
-
# the messenger thread.
|
34
|
-
#
|
35
|
-
# === Sending & Receiving Messages
|
36
|
-
#
|
37
|
-
# The Messenger class works in conjuction with the Message class. The
|
38
|
-
# Message class is a mutable holder of message content.
|
39
|
-
#
|
40
|
-
# The put method copies its Message to the outgoing queue, and may
|
41
|
-
# send queued messages if it can do so without blocking. The send
|
42
|
-
# method blocks until it has sent the requested number of messages,
|
43
|
-
# or until a timeout interrupts the attempt.
|
44
|
-
#
|
45
|
-
# Similarly, the recv method receives messages into the incoming
|
46
|
-
# queue, and may block as it attempts to receive the requested number
|
47
|
-
# of messages, or until timeout is reached. It may receive fewer
|
48
|
-
# than the requested number. The get method pops the
|
49
|
-
# eldest Message off the incoming queue and copies it into the Message
|
50
|
-
# object that you supply. It will not block.
|
51
|
-
#
|
52
|
-
# The blocking attribute allows you to turn off blocking behavior entirely,
|
53
|
-
# in which case send and recv will do whatever they can without
|
54
|
-
# blocking, and then return. You can then look at the number
|
55
|
-
# of incoming and outgoing messages to see how much outstanding work
|
56
|
-
# still remains.
|
57
|
-
#
|
58
|
-
class Messenger
|
59
|
-
|
60
|
-
include Qpid::Proton::ExceptionHandling
|
61
|
-
|
62
|
-
can_raise_exception [:send, :receive, :password=, :start, :stop,
|
63
|
-
:perform_put, :perform_get, :interrupt,
|
64
|
-
:route, :rewrite, :accept, :reject,
|
65
|
-
:incoming_window=, :outgoing_window=]
|
66
|
-
|
67
|
-
# Creates a new +Messenger+.
|
68
|
-
#
|
69
|
-
# The +name+ parameter is optional. If one is not provided then
|
70
|
-
# a unique name is generated.
|
71
|
-
#
|
72
|
-
# ==== Options
|
73
|
-
#
|
74
|
-
# * name - the name (def. nil)
|
75
|
-
#
|
76
|
-
def initialize(name = nil)
|
77
|
-
@impl = Cproton.pn_messenger(name)
|
78
|
-
@selectables = {}
|
79
|
-
ObjectSpace.define_finalizer(self, self.class.finalize!(@impl))
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.finalize!(impl) # :nodoc:
|
83
|
-
proc {
|
84
|
-
Cproton.pn_messenger_free(impl)
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
# Returns the name.
|
89
|
-
#
|
90
|
-
def name
|
91
|
-
Cproton.pn_messenger_name(@impl)
|
92
|
-
end
|
93
|
-
|
94
|
-
# This property contains the password for the Messenger.private_key
|
95
|
-
# file, or +nil+ if the file is not encrypted.
|
96
|
-
#
|
97
|
-
# ==== Arguments
|
98
|
-
#
|
99
|
-
# * password - the password
|
100
|
-
#
|
101
|
-
def password=(password)
|
102
|
-
Cproton.pn_messenger_set_password(@impl, password)
|
103
|
-
end
|
104
|
-
|
105
|
-
# Returns the password property for the Messenger.private_key file.
|
106
|
-
#
|
107
|
-
def password
|
108
|
-
Cproton.pn_messenger_get_password(@impl)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Sets the timeout period, in milliseconds.
|
112
|
-
#
|
113
|
-
# A negative timeout period implies an infinite timeout.
|
114
|
-
#
|
115
|
-
# ==== Options
|
116
|
-
#
|
117
|
-
# * timeout - the timeout period
|
118
|
-
#
|
119
|
-
def timeout=(timeout)
|
120
|
-
raise TypeError.new("invalid timeout: #{timeout}") if timeout.nil?
|
121
|
-
Cproton.pn_messenger_set_timeout(@impl, timeout)
|
122
|
-
end
|
123
|
-
|
124
|
-
# Returns the timeout period
|
125
|
-
#
|
126
|
-
def timeout
|
127
|
-
Cproton.pn_messenger_get_timeout(@impl)
|
128
|
-
end
|
129
|
-
|
130
|
-
# Returns true if blocking mode is enabled.
|
131
|
-
#
|
132
|
-
# Enable or disable blocking behavior during message sending
|
133
|
-
# and receiving. This affects every blocking call, with the
|
134
|
-
# exception of work(). Currently, the affected calls are
|
135
|
-
# send, recv, and stop.
|
136
|
-
def blocking?
|
137
|
-
Cproton.pn_messenger_is_blocking(@impl)
|
138
|
-
end
|
139
|
-
|
140
|
-
# Sets the blocking mode.
|
141
|
-
def blocking=(blocking)
|
142
|
-
Cproton.pn_messenger_set_blocking(@impl, blocking)
|
143
|
-
end
|
144
|
-
|
145
|
-
# Returns true if passive mode is enabled.
|
146
|
-
#
|
147
|
-
def passive?
|
148
|
-
Cproton.pn_messenger_is_passive(@impl)
|
149
|
-
end
|
150
|
-
|
151
|
-
# Turns passive mode on or off.
|
152
|
-
#
|
153
|
-
# When set to passive mode, Messenger will not attempt to perform I/O
|
154
|
-
# operations internally. In this mode it is necesssary to use the
|
155
|
-
# Selectable type to drive any I/O needed to perform requestioned
|
156
|
-
# actions.
|
157
|
-
#
|
158
|
-
# In this mode Messenger will never block.
|
159
|
-
#
|
160
|
-
def passive=(mode)
|
161
|
-
Cproton.pn_messenger_set_passive(@impl, mode)
|
162
|
-
end
|
163
|
-
|
164
|
-
def deadline
|
165
|
-
tstamp = Cproton.pn_messenger_deadline(@impl)
|
166
|
-
return tstamp / 1000.0 unless tstamp.nil?
|
167
|
-
end
|
168
|
-
|
169
|
-
# Reports whether an error occurred.
|
170
|
-
#
|
171
|
-
def error?
|
172
|
-
!Cproton.pn_messenger_errno(@impl).zero?
|
173
|
-
end
|
174
|
-
|
175
|
-
# Returns the most recent error number.
|
176
|
-
#
|
177
|
-
def errno
|
178
|
-
Cproton.pn_messenger_errno(@impl)
|
179
|
-
end
|
180
|
-
|
181
|
-
# Returns the most recent error message.
|
182
|
-
#
|
183
|
-
def error
|
184
|
-
Cproton.pn_error_text(Cproton.pn_messenger_error(@impl))
|
185
|
-
end
|
186
|
-
|
187
|
-
# Clears the current error state.
|
188
|
-
#
|
189
|
-
def clear_error
|
190
|
-
error = Cproton.pn_messenger_error(@impl)
|
191
|
-
unless error.nil?
|
192
|
-
Cproton.pn_error_clear(error)
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
# Currently a no-op placeholder.
|
197
|
-
# For future compatibility, do not send or recv messages
|
198
|
-
# before starting the +Messenger+.
|
199
|
-
#
|
200
|
-
def start
|
201
|
-
Cproton.pn_messenger_start(@impl)
|
202
|
-
end
|
203
|
-
|
204
|
-
# Stops the +Messenger+, preventing it from sending or receiving
|
205
|
-
# any more messages.
|
206
|
-
#
|
207
|
-
def stop
|
208
|
-
Cproton.pn_messenger_stop(@impl)
|
209
|
-
end
|
210
|
-
|
211
|
-
# Returns true if a Messenger is in the stopped state.
|
212
|
-
# This function does not block.
|
213
|
-
#
|
214
|
-
def stopped?
|
215
|
-
Cproton.pn_messenger_stopped(@impl)
|
216
|
-
end
|
217
|
-
|
218
|
-
# Subscribes the Messenger to messages originating from the
|
219
|
-
# specified source. The source is an address as specified in the
|
220
|
-
# Messenger introduction with the following addition. If the
|
221
|
-
# domain portion of the address begins with the '~' character, the
|
222
|
-
# Messenger will interpret the domain as host/port, bind to it,
|
223
|
-
# and listen for incoming messages. For example "~0.0.0.0",
|
224
|
-
# "amqp://~0.0.0.0" will all bind to any local interface and
|
225
|
-
# listen for incoming messages. An address of "amqps://~0.0.0.0"
|
226
|
-
# will only permit incoming SSL connections.
|
227
|
-
#
|
228
|
-
# ==== Options
|
229
|
-
#
|
230
|
-
# * address - the source address to be subscribe
|
231
|
-
# * timeout - an optional time-to-live value, in seconds, for the
|
232
|
-
# subscription
|
233
|
-
#
|
234
|
-
def subscribe(address, timeout=0)
|
235
|
-
raise TypeError.new("invalid address: #{address}") if address.nil?
|
236
|
-
subscription = Cproton.pn_messenger_subscribe_ttl(@impl, address, timeout)
|
237
|
-
raise Qpid::Proton::ProtonError.new("Subscribe failed") if subscription.nil?
|
238
|
-
Qpid::Proton::Subscription.new(subscription)
|
239
|
-
end
|
240
|
-
|
241
|
-
# Path to a certificate file for the +Messenger+.
|
242
|
-
#
|
243
|
-
# This certificate is used when the +Messenger+ accepts or establishes
|
244
|
-
# SSL/TLS connections. This property must be specified for the
|
245
|
-
# Messenger to accept incoming SSL/TLS connections and to establish
|
246
|
-
# client authenticated outgoing SSL/TLS connection. Non client authenticated
|
247
|
-
# outgoing SSL/TLS connections do not require this property.
|
248
|
-
#
|
249
|
-
# ==== Options
|
250
|
-
#
|
251
|
-
# * certificate - the certificate
|
252
|
-
#
|
253
|
-
def certificate=(certificate)
|
254
|
-
Cproton.pn_messenger_set_certificate(@impl, certificate)
|
255
|
-
end
|
256
|
-
|
257
|
-
# Returns the path to a certificate file.
|
258
|
-
#
|
259
|
-
def certificate
|
260
|
-
Cproton.pn_messenger_get_certificate(@impl)
|
261
|
-
end
|
262
|
-
|
263
|
-
# Path to a private key file for the +Messenger+.
|
264
|
-
#
|
265
|
-
# The property must be specified for the +Messenger+ to accept incoming
|
266
|
-
# SSL/TLS connections and to establish client authenticated outgoing
|
267
|
-
# SSL/TLS connections. Non client authenticated SSL/TLS connections
|
268
|
-
# do not require this property.
|
269
|
-
#
|
270
|
-
# ==== Options
|
271
|
-
#
|
272
|
-
# * key - the key file
|
273
|
-
#
|
274
|
-
def private_key=(key)
|
275
|
-
Cproton.pn_messenger_set_private_key(@impl, key)
|
276
|
-
end
|
277
|
-
|
278
|
-
# Returns the path to a private key file.
|
279
|
-
#
|
280
|
-
def private_key
|
281
|
-
Cproton.pn_messenger_get_private_key(@impl)
|
282
|
-
end
|
283
|
-
|
284
|
-
# A path to a database of trusted certificates for use in verifying the
|
285
|
-
# peer on an SSL/TLS connection. If this property is +nil+, then the
|
286
|
-
# peer will not be verified.
|
287
|
-
#
|
288
|
-
# ==== Options
|
289
|
-
#
|
290
|
-
# * certificates - the certificates path
|
291
|
-
#
|
292
|
-
def trusted_certificates=(certificates)
|
293
|
-
Cproton.pn_messenger_set_trusted_certificates(@impl,certificates)
|
294
|
-
end
|
295
|
-
|
296
|
-
# The path to the databse of trusted certificates.
|
297
|
-
#
|
298
|
-
def trusted_certificates
|
299
|
-
Cproton.pn_messenger_get_trusted_certificates(@impl)
|
300
|
-
end
|
301
|
-
|
302
|
-
# Places the content contained in the message onto the outgoing
|
303
|
-
# queue of the Messenger.
|
304
|
-
#
|
305
|
-
# This method will never block, however it will send any unblocked
|
306
|
-
# Messages in the outgoing queue immediately and leave any blocked
|
307
|
-
# Messages remaining in the outgoing queue.
|
308
|
-
# The send call may then be used to block until the outgoing queue
|
309
|
-
# is empty. The outgoing attribute may be used to check the depth
|
310
|
-
# of the outgoing queue.
|
311
|
-
#
|
312
|
-
# ==== Options
|
313
|
-
#
|
314
|
-
# * message - the message
|
315
|
-
#
|
316
|
-
def put(message)
|
317
|
-
raise TypeError.new("invalid message: #{message}") if message.nil?
|
318
|
-
raise ArgumentError.new("invalid message type: #{message.class}") unless message.kind_of?(Message)
|
319
|
-
# encode the message first
|
320
|
-
message.pre_encode
|
321
|
-
perform_put(message)
|
322
|
-
return outgoing_tracker
|
323
|
-
end
|
324
|
-
|
325
|
-
private
|
326
|
-
|
327
|
-
def perform_put(message) # :nodoc:
|
328
|
-
Cproton.pn_messenger_put(@impl, message.impl)
|
329
|
-
end
|
330
|
-
|
331
|
-
public
|
332
|
-
|
333
|
-
|
334
|
-
# This call will block until the indicated number of messages
|
335
|
-
# have been sent, or until the operation times out.
|
336
|
-
# If n is -1 this call will block until all outgoing messages
|
337
|
-
# have been sent. If n is 0 then this call will send whatever
|
338
|
-
# it can without blocking.
|
339
|
-
#
|
340
|
-
def send(n = -1)
|
341
|
-
Cproton.pn_messenger_send(@impl, n)
|
342
|
-
end
|
343
|
-
|
344
|
-
# Moves the message from the head of the incoming message queue into
|
345
|
-
# the supplied message object. Any content in the supplied message
|
346
|
-
# will be overwritten.
|
347
|
-
# A tracker for the incoming Message is returned. The tracker can
|
348
|
-
# later be used to communicate your acceptance or rejection of the
|
349
|
-
# Message.
|
350
|
-
#
|
351
|
-
# If no message is provided in the argument, then one is created. In
|
352
|
-
# either case, the one returned will be the fetched message.
|
353
|
-
#
|
354
|
-
# ==== Options
|
355
|
-
#
|
356
|
-
# * msg - the (optional) +Message+ instance to be used
|
357
|
-
#
|
358
|
-
def get(msg = nil)
|
359
|
-
msg_impl = nil
|
360
|
-
if msg.nil? then
|
361
|
-
msg_impl = nil
|
362
|
-
else
|
363
|
-
msg_impl = msg.impl
|
364
|
-
end
|
365
|
-
perform_get(msg_impl)
|
366
|
-
msg.post_decode unless msg.nil?
|
367
|
-
return incoming_tracker
|
368
|
-
end
|
369
|
-
|
370
|
-
private
|
371
|
-
|
372
|
-
def perform_get(msg) # :nodoc:
|
373
|
-
Cproton.pn_messenger_get(@impl, msg)
|
374
|
-
end
|
375
|
-
|
376
|
-
public
|
377
|
-
|
378
|
-
# Receives up to limit messages into the incoming queue. If no value
|
379
|
-
# for limit is supplied, this call will receive as many messages as it
|
380
|
-
# can buffer internally. If the Messenger is in blocking mode, this
|
381
|
-
# call will block until at least one Message is available in the
|
382
|
-
# incoming queue.
|
383
|
-
#
|
384
|
-
# Options ====
|
385
|
-
#
|
386
|
-
# * limit - the maximum number of messages to receive
|
387
|
-
#
|
388
|
-
def receive(limit = -1)
|
389
|
-
Cproton.pn_messenger_recv(@impl, limit)
|
390
|
-
end
|
391
|
-
|
392
|
-
# Returns true if the messenger is currently receiving data.
|
393
|
-
def receiving?
|
394
|
-
Cproton.pn_messenger_receiving(@impl)
|
395
|
-
end
|
396
|
-
|
397
|
-
# Attempts interrupting of the messenger thread.
|
398
|
-
#
|
399
|
-
# The Messenger interface is single-threaded, and this is the only
|
400
|
-
# function intended to be called from outside of is thread.
|
401
|
-
#
|
402
|
-
# Call this from a non-Messenger thread to interrupt it while it
|
403
|
-
# is blocking. This will cause a ::InterruptError to be raised.
|
404
|
-
#
|
405
|
-
# If there is no currently blocking call, then the next blocking
|
406
|
-
# call will be affected, even if it is within the same thread that
|
407
|
-
# originated the interrupt.
|
408
|
-
#
|
409
|
-
def interrupt
|
410
|
-
Cproton.pn_messenger_interrupt(@impl)
|
411
|
-
end
|
412
|
-
|
413
|
-
# Sends or receives any outstanding messages queued for a Messenger.
|
414
|
-
#
|
415
|
-
# This will block for the indicated timeout. This method may also do I/O
|
416
|
-
# other than sending and receiving messages. For example, closing
|
417
|
-
# connections after stop() has been called.
|
418
|
-
#
|
419
|
-
def work(timeout=-1)
|
420
|
-
err = Cproton.pn_messenger_work(@impl, timeout)
|
421
|
-
if (err == Cproton::PN_TIMEOUT) then
|
422
|
-
return false
|
423
|
-
else
|
424
|
-
check_for_error(err)
|
425
|
-
return true
|
426
|
-
end
|
427
|
-
end
|
428
|
-
|
429
|
-
# Returns the number messages in the outgoing queue that have not been
|
430
|
-
# transmitted.
|
431
|
-
#
|
432
|
-
def outgoing
|
433
|
-
Cproton.pn_messenger_outgoing(@impl)
|
434
|
-
end
|
435
|
-
|
436
|
-
# Returns the number of messages in the incoming queue that have not
|
437
|
-
# been retrieved.
|
438
|
-
#
|
439
|
-
def incoming
|
440
|
-
Cproton.pn_messenger_incoming(@impl)
|
441
|
-
end
|
442
|
-
|
443
|
-
# Adds a routing rule to the Messenger's internal routing table.
|
444
|
-
#
|
445
|
-
# The route procedure may be used to influence how a Messenger will
|
446
|
-
# internally treat a given address or class of addresses. Every call
|
447
|
-
# to the route procedure will result in Messenger appending a routing
|
448
|
-
# rule to its internal routing table.
|
449
|
-
#
|
450
|
-
# Whenever a Message is presented to a Messenger for delivery, it
|
451
|
-
# will match the address of this message against the set of routing
|
452
|
-
# rules in order. The first rule to match will be triggered, and
|
453
|
-
# instead of routing based on the address presented in the message,
|
454
|
-
# the Messenger will route based on the address supplied in the rule.
|
455
|
-
#
|
456
|
-
# The pattern matching syntax supports two types of matches, a '%'
|
457
|
-
# will match any character except a '/', and a '*' will match any
|
458
|
-
# character including a '/'.
|
459
|
-
#
|
460
|
-
# A routing address is specified as a normal AMQP address, however it
|
461
|
-
# may additionally use substitution variables from the pattern match
|
462
|
-
# that triggered the rule.
|
463
|
-
#
|
464
|
-
# ==== Arguments
|
465
|
-
#
|
466
|
-
# * pattern - the address pattern
|
467
|
-
# * address - the target address
|
468
|
-
#
|
469
|
-
# ==== Examples
|
470
|
-
#
|
471
|
-
# # route messages sent to foo to the destionaty amqp://foo.com
|
472
|
-
# messenger.route("foo", "amqp://foo.com")
|
473
|
-
#
|
474
|
-
# # any message to foobar will be routed to amqp://foo.com/bar
|
475
|
-
# messenger.route("foobar", "amqp://foo.com/bar")
|
476
|
-
#
|
477
|
-
# # any message to bar/<path> will be routed to the same path within
|
478
|
-
# # the amqp://bar.com domain
|
479
|
-
# messenger.route("bar/*", "amqp://bar.com/$1")
|
480
|
-
#
|
481
|
-
# # route all Message objects over TLS
|
482
|
-
# messenger.route("amqp:*", "amqps:$1")
|
483
|
-
#
|
484
|
-
# # supply credentials for foo
|
485
|
-
# messenger.route("amqp://foo.com/*", "amqp://user:password@foo.com/$1")
|
486
|
-
#
|
487
|
-
# # supply credentials for all domains
|
488
|
-
# messenger.route("amqp://*", "amqp://user:password@$1")
|
489
|
-
#
|
490
|
-
# # route all addresses through a single proxy while preserving the
|
491
|
-
# # original destination
|
492
|
-
# messenger.route("amqp://%$/*", "amqp://user:password@proxy/$1/$2")
|
493
|
-
#
|
494
|
-
# # route any address through a single broker
|
495
|
-
# messenger.route("*", "amqp://user:password@broker/$1")
|
496
|
-
#
|
497
|
-
def route(pattern, address)
|
498
|
-
Cproton.pn_messenger_route(@impl, pattern, address)
|
499
|
-
end
|
500
|
-
|
501
|
-
# Similar to #route, except that the destination of
|
502
|
-
# the Message is determined before the message address is rewritten.
|
503
|
-
#
|
504
|
-
# The outgoing address is only rewritten after routing has been
|
505
|
-
# finalized. If a message has an outgoing address of
|
506
|
-
# "amqp://0.0.0.0:5678", and a rewriting rule that changes its
|
507
|
-
# outgoing address to "foo", it will still arrive at the peer that
|
508
|
-
# is listening on "amqp://0.0.0.0:5678", but when it arrives there,
|
509
|
-
# the receiver will see its outgoing address as "foo".
|
510
|
-
#
|
511
|
-
# The default rewrite rule removes username and password from addresses
|
512
|
-
# before they are transmitted.
|
513
|
-
#
|
514
|
-
# ==== Arguments
|
515
|
-
#
|
516
|
-
# * pattern - the outgoing address
|
517
|
-
# * address - the target address
|
518
|
-
#
|
519
|
-
def rewrite(pattern, address)
|
520
|
-
Cproton.pn_messenger_rewrite(@impl, pattern, address)
|
521
|
-
end
|
522
|
-
|
523
|
-
def selectable
|
524
|
-
impl = Cproton.pn_messenger_selectable(@impl)
|
525
|
-
|
526
|
-
# if we don't have any selectables, then return
|
527
|
-
return nil if impl.nil?
|
528
|
-
|
529
|
-
fd = Cproton.pn_selectable_fd(impl)
|
530
|
-
|
531
|
-
selectable = @selectables[fd]
|
532
|
-
if selectable.nil?
|
533
|
-
selectable = Selectable.new(self, impl)
|
534
|
-
@selectables[fd] = selectable
|
535
|
-
end
|
536
|
-
return selectable
|
537
|
-
end
|
538
|
-
|
539
|
-
# Returns a +Tracker+ for the message most recently sent via the put
|
540
|
-
# method.
|
541
|
-
#
|
542
|
-
def outgoing_tracker
|
543
|
-
impl = Cproton.pn_messenger_outgoing_tracker(@impl)
|
544
|
-
return nil if impl == -1
|
545
|
-
Qpid::Proton::Tracker.new(impl)
|
546
|
-
end
|
547
|
-
|
548
|
-
# Returns a +Tracker+ for the most recently received message.
|
549
|
-
#
|
550
|
-
def incoming_tracker
|
551
|
-
impl = Cproton.pn_messenger_incoming_tracker(@impl)
|
552
|
-
return nil if impl == -1
|
553
|
-
Qpid::Proton::Tracker.new(impl)
|
554
|
-
end
|
555
|
-
|
556
|
-
# Signal the sender that you have acted on the Message
|
557
|
-
# pointed to by the tracker. If no tracker is supplied,
|
558
|
-
# then all messages that have been returned by the get
|
559
|
-
# method are accepted, except those that have already been
|
560
|
-
# auto-settled by passing beyond your incoming window size.
|
561
|
-
#
|
562
|
-
# ==== Options
|
563
|
-
#
|
564
|
-
# * tracker - the tracker
|
565
|
-
#
|
566
|
-
def accept(tracker = nil)
|
567
|
-
raise TypeError.new("invalid tracker: #{tracker}") unless tracker.nil? or valid_tracker?(tracker)
|
568
|
-
if tracker.nil? then
|
569
|
-
tracker = self.incoming_tracker
|
570
|
-
flag = Cproton::PN_CUMULATIVE
|
571
|
-
else
|
572
|
-
flag = 0
|
573
|
-
end
|
574
|
-
Cproton.pn_messenger_accept(@impl, tracker.impl, flag)
|
575
|
-
end
|
576
|
-
|
577
|
-
# Rejects the incoming message identified by the tracker.
|
578
|
-
# If no tracker is supplied, all messages that have been returned
|
579
|
-
# by the get method are rejected, except those that have already
|
580
|
-
# been auto-settled by passing beyond your outgoing window size.
|
581
|
-
#
|
582
|
-
# ==== Options
|
583
|
-
#
|
584
|
-
# * tracker - the tracker
|
585
|
-
#
|
586
|
-
def reject(tracker)
|
587
|
-
raise TypeError.new("invalid tracker: #{tracker}") unless tracker.nil? or valid_tracker?(tracker)
|
588
|
-
if tracker.nil? then
|
589
|
-
tracker = self.incoming_tracker
|
590
|
-
flag = Cproton::PN_CUMULATIVE
|
591
|
-
else
|
592
|
-
flag = 0
|
593
|
-
end
|
594
|
-
Cproton.pn_messenger_reject(@impl, tracker.impl, flag)
|
595
|
-
end
|
596
|
-
|
597
|
-
# Gets the last known remote state of the delivery associated with
|
598
|
-
# the given tracker, as long as the Message is still within your
|
599
|
-
# outgoing window. (Also works on incoming messages that are still
|
600
|
-
# within your incoming queue. See TrackerStatus for details on the
|
601
|
-
# values returned.
|
602
|
-
#
|
603
|
-
# ==== Options
|
604
|
-
#
|
605
|
-
# * tracker - the tracker
|
606
|
-
#
|
607
|
-
def status(tracker)
|
608
|
-
raise TypeError.new("invalid tracker: #{tracker}") unless valid_tracker?(tracker)
|
609
|
-
Qpid::Proton::TrackerStatus.by_value(Cproton.pn_messenger_status(@impl, tracker.impl))
|
610
|
-
end
|
611
|
-
|
612
|
-
# Frees a Messenger from tracking the status associated
|
613
|
-
# with a given tracker. If you don't supply a tracker, all
|
614
|
-
# outgoing messages up to the most recent will be settled.
|
615
|
-
#
|
616
|
-
# ==== Options
|
617
|
-
#
|
618
|
-
# * tracker - the tracker
|
619
|
-
#
|
620
|
-
# ==== Examples
|
621
|
-
#
|
622
|
-
def settle(tracker)
|
623
|
-
raise TypeError.new("invalid tracker: #{tracker}") unless valid_tracker?(tracker)
|
624
|
-
if tracker.nil? then
|
625
|
-
tracker = self.incoming_tracker
|
626
|
-
flag = Cproton::PN_CUMULATIVE
|
627
|
-
else
|
628
|
-
flag = 0
|
629
|
-
end
|
630
|
-
Cproton.pn_messenger_settle(@impl, tracker.impl, flag)
|
631
|
-
end
|
632
|
-
|
633
|
-
# Sets the incoming window.
|
634
|
-
#
|
635
|
-
# The Messenger will track the remote status of this many incoming
|
636
|
-
# deliveries after they have been accepted or rejected.
|
637
|
-
#
|
638
|
-
# Messages enter this window only when you take them into your application
|
639
|
-
# using get(). If your incoming window size is n, and you get n+1 messages
|
640
|
-
# without explicitly accepting or rejecting the oldest message, then the
|
641
|
-
# message that passes beyond the edge of the incoming window will be
|
642
|
-
# assigned the default disposition of its link.
|
643
|
-
#
|
644
|
-
# ==== Options
|
645
|
-
#
|
646
|
-
# * window - the window size
|
647
|
-
#
|
648
|
-
def incoming_window=(window)
|
649
|
-
raise TypeError.new("invalid window: #{window}") unless valid_window?(window)
|
650
|
-
Cproton.pn_messenger_set_incoming_window(@impl, window)
|
651
|
-
end
|
652
|
-
|
653
|
-
# Returns the incoming window.
|
654
|
-
#
|
655
|
-
def incoming_window
|
656
|
-
Cproton.pn_messenger_get_incoming_window(@impl)
|
657
|
-
end
|
658
|
-
|
659
|
-
# Sets the outgoing window.
|
660
|
-
#
|
661
|
-
# The Messenger will track the remote status of this many outgoing
|
662
|
-
# deliveries after calling send.
|
663
|
-
# A Message enters this window when you call the put() method with the
|
664
|
-
# message. If your outgoing window size is n, and you call put n+1
|
665
|
-
# times, status information will no longer be available for the
|
666
|
-
# first message.
|
667
|
-
#
|
668
|
-
# ==== Options
|
669
|
-
#
|
670
|
-
# * window - the window size
|
671
|
-
#
|
672
|
-
def outgoing_window=(window)
|
673
|
-
raise TypeError.new("invalid window: #{window}") unless valid_window?(window)
|
674
|
-
Cproton.pn_messenger_set_outgoing_window(@impl, window)
|
675
|
-
end
|
676
|
-
|
677
|
-
# Returns the outgoing window.
|
678
|
-
#
|
679
|
-
def outgoing_window
|
680
|
-
Cproton.pn_messenger_get_outgoing_window(@impl)
|
681
|
-
end
|
682
|
-
|
683
|
-
# Unregisters a selectable object.
|
684
|
-
def unregister_selectable(fileno) # :nodoc:
|
685
|
-
@selectables.delete(fileno)
|
686
|
-
end
|
687
|
-
|
688
|
-
private
|
689
|
-
|
690
|
-
def valid_tracker?(tracker)
|
691
|
-
!tracker.nil? && tracker.is_a?(Qpid::Proton::Tracker)
|
692
|
-
end
|
693
|
-
|
694
|
-
def valid_window?(window)
|
695
|
-
!window.nil? && [Float, Fixnum].include?(window.class)
|
696
|
-
end
|
697
|
-
|
698
|
-
end
|
699
|
-
|
700
|
-
end
|
701
|
-
|
702
|
-
end
|