qpid_proton 0.8 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/cproton/cproton.c +5004 -4239
- data/ext/cproton/extconf.rb +4 -1
- data/lib/qpid_proton.rb +7 -3
- data/lib/qpid_proton/array.rb +5 -5
- data/lib/qpid_proton/data.rb +6 -8
- data/lib/qpid_proton/described.rb +2 -2
- data/lib/qpid_proton/exception_handling.rb +51 -5
- data/lib/qpid_proton/exceptions.rb +10 -4
- data/lib/qpid_proton/filters.rb +4 -4
- data/lib/qpid_proton/hash.rb +3 -3
- data/lib/qpid_proton/mapping.rb +36 -8
- data/lib/qpid_proton/message.rb +30 -22
- data/lib/qpid_proton/messenger.rb +72 -34
- data/lib/qpid_proton/selectable.rb +4 -4
- data/lib/qpid_proton/strings.rb +65 -0
- data/lib/qpid_proton/subscription.rb +4 -4
- data/lib/qpid_proton/tracker.rb +4 -4
- data/lib/qpid_proton/tracker_status.rb +4 -4
- data/lib/qpid_proton/version.rb +7 -4
- metadata +19 -4
- data/lib/qpid_proton/message_format.rb +0 -75
data/ext/cproton/extconf.rb
CHANGED
@@ -19,6 +19,10 @@
|
|
19
19
|
|
20
20
|
require 'mkmf'
|
21
21
|
|
22
|
+
# set the ruby version compiler flag
|
23
|
+
runtime_version = RUBY_VERSION.gsub(/\./,'')[0,2]
|
24
|
+
$CFLAGS << " -DRUBY#{runtime_version}"
|
25
|
+
|
22
26
|
dir_config("qpid-proton")
|
23
27
|
|
24
28
|
REQUIRED_LIBRARIES = [
|
@@ -33,7 +37,6 @@ REQUIRED_HEADERS = [
|
|
33
37
|
"proton/engine.h",
|
34
38
|
"proton/message.h",
|
35
39
|
"proton/sasl.h",
|
36
|
-
"proton/driver.h",
|
37
40
|
"proton/messenger.h"
|
38
41
|
]
|
39
42
|
|
data/lib/qpid_proton.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
3
|
# or more contributor license agreements. See the NOTICE file
|
4
4
|
# distributed with this work for additional information
|
@@ -15,20 +15,24 @@
|
|
15
15
|
# KIND, either express or implied. See the License for the
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
|
-
|
18
|
+
#++
|
19
19
|
|
20
20
|
require "cproton"
|
21
21
|
require "date"
|
22
22
|
|
23
|
+
if RUBY_VERSION < "1.9"
|
24
|
+
require "kconv"
|
25
|
+
end
|
26
|
+
|
23
27
|
require "qpid_proton/version"
|
24
28
|
require "qpid_proton/described"
|
29
|
+
require "qpid_proton/strings"
|
25
30
|
require "qpid_proton/mapping"
|
26
31
|
require "qpid_proton/array"
|
27
32
|
require "qpid_proton/hash"
|
28
33
|
require "qpid_proton/exceptions"
|
29
34
|
require "qpid_proton/exception_handling"
|
30
35
|
require "qpid_proton/filters"
|
31
|
-
require "qpid_proton/message_format"
|
32
36
|
require "qpid_proton/data"
|
33
37
|
require "qpid_proton/message"
|
34
38
|
require "qpid_proton/subscription"
|
data/lib/qpid_proton/array.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
3
|
# or more contributor license agreements. See the NOTICE file
|
4
4
|
# distributed with this work for additional information
|
@@ -15,16 +15,16 @@
|
|
15
15
|
# KIND, either express or implied. See the License for the
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
|
-
|
18
|
+
#++
|
19
19
|
|
20
20
|
#--
|
21
21
|
# Patch the Array class to provide methods for adding its contents
|
22
22
|
# to a Qpid::Proton::Data instance.
|
23
23
|
#++
|
24
24
|
|
25
|
-
module Qpid
|
25
|
+
module Qpid # :nodoc:
|
26
26
|
|
27
|
-
module Proton
|
27
|
+
module Proton # :nodoc:
|
28
28
|
|
29
29
|
# Holds the information for an AMQP Array compound type.
|
30
30
|
#
|
@@ -54,7 +54,7 @@ module Qpid
|
|
54
54
|
|
55
55
|
end
|
56
56
|
|
57
|
-
class Array
|
57
|
+
class Array # :nodoc:
|
58
58
|
|
59
59
|
# Used to declare an array as an AMQP array.
|
60
60
|
#
|
data/lib/qpid_proton/data.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
3
|
# or more contributor license agreements. See the NOTICE file
|
4
4
|
# distributed with this work for additional information
|
@@ -15,13 +15,11 @@
|
|
15
15
|
# KIND, either express or implied. See the License for the
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
|
-
|
19
|
-
|
20
|
-
require 'cproton'
|
18
|
+
#++
|
21
19
|
|
22
|
-
module Qpid
|
20
|
+
module Qpid # :nodoc:
|
23
21
|
|
24
|
-
module Proton
|
22
|
+
module Proton # :nodoc:
|
25
23
|
|
26
24
|
# +DataError+ is raised when an error occurs while encoding
|
27
25
|
# or decoding data.
|
@@ -725,7 +723,7 @@ module Qpid
|
|
725
723
|
# If the current node is binary, returns its value. Otherwise, it returns
|
726
724
|
# an empty string ("").
|
727
725
|
def binary
|
728
|
-
Cproton.pn_data_get_binary(@data)
|
726
|
+
Qpid::Proton::BinaryString.new(Cproton.pn_data_get_binary(@data))
|
729
727
|
end
|
730
728
|
|
731
729
|
# Puts a unicode string value.
|
@@ -742,7 +740,7 @@ module Qpid
|
|
742
740
|
# If the current node is a string, returns its value. Otherwise, it
|
743
741
|
# returns an empty string ("").
|
744
742
|
def string
|
745
|
-
Cproton.pn_data_get_string(@data)
|
743
|
+
Qpid::Proton::UTFString.new(Cproton.pn_data_get_string(@data))
|
746
744
|
end
|
747
745
|
|
748
746
|
# Puts a symbolic value.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
3
|
# or more contributor license agreements. See the NOTICE file
|
4
4
|
# distributed with this work for additional information
|
@@ -15,7 +15,7 @@
|
|
15
15
|
# KIND, either express or implied. See the License for the
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
|
-
|
18
|
+
#++
|
19
19
|
|
20
20
|
module Qpid # :nodoc:
|
21
21
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
3
|
# or more contributor license agreements. See the NOTICE file
|
4
4
|
# distributed with this work for additional information
|
@@ -15,16 +15,59 @@
|
|
15
15
|
# KIND, either express or implied. See the License for the
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
|
-
|
18
|
+
#++
|
19
19
|
|
20
|
-
module Qpid
|
20
|
+
module Qpid # :nodoc:
|
21
21
|
|
22
|
-
module Proton
|
22
|
+
module Proton # :nodoc:
|
23
23
|
|
24
24
|
# Provides mixin functionality for dealing with exception conditions.
|
25
25
|
#
|
26
26
|
module ExceptionHandling
|
27
27
|
|
28
|
+
def self.included(base)
|
29
|
+
base.extend(self)
|
30
|
+
|
31
|
+
unless defined? base.to_be_wrapped
|
32
|
+
class << base
|
33
|
+
@@to_be_wrapped = []
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
define_method :method_added do |name|
|
38
|
+
if (!@@to_be_wrapped.nil?) && (@@to_be_wrapped.include? name)
|
39
|
+
@@to_be_wrapped.delete name
|
40
|
+
create_exception_handler_wrapper(name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def can_raise_exception(method_names)
|
46
|
+
# coerce the names to be an array
|
47
|
+
Array(method_names).each do |method_name|
|
48
|
+
# if the method doesn't already exist then queue this aliasing
|
49
|
+
unless self.method_defined? method_name
|
50
|
+
@@to_be_wrapped ||= []
|
51
|
+
@@to_be_wrapped << method_name
|
52
|
+
else
|
53
|
+
create_exception_handler_wrapper(method_name)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_exception_handler_wrapper(method_name)
|
59
|
+
original_method_name = method_name.to_s
|
60
|
+
wrapped_method_name = "_excwrap_#{original_method_name}"
|
61
|
+
alias_method wrapped_method_name, original_method_name
|
62
|
+
define_method original_method_name do |*args, &block|
|
63
|
+
# need to get a reference to the method object itself since
|
64
|
+
# calls to Class.send interfere with Messenger.send
|
65
|
+
method = self.method(wrapped_method_name.to_sym)
|
66
|
+
rc = method.call(*args, &block)
|
67
|
+
check_for_error(rc)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
28
71
|
# Raises an Proton-specific error if a return code is non-zero.
|
29
72
|
#
|
30
73
|
# Expects the class to provide an +error+ method.
|
@@ -32,7 +75,7 @@ module Qpid
|
|
32
75
|
|
33
76
|
raise ::ArgumentError.new("Invalid error code: #{code}") if code.nil?
|
34
77
|
|
35
|
-
|
78
|
+
return code if code > 0
|
36
79
|
|
37
80
|
case(code)
|
38
81
|
|
@@ -54,6 +97,9 @@ module Qpid
|
|
54
97
|
when Qpid::Proton::Error::ARGUMENT
|
55
98
|
raise Qpid::Proton::ArgumentError.new(self.error)
|
56
99
|
|
100
|
+
when Qpid::Proton::Error::STATE
|
101
|
+
raise Qpid::Proton::StateError.new(self.error)
|
102
|
+
|
57
103
|
when Qpid::Proton::Error::TIMEOUT
|
58
104
|
raise Qpid::Proton::TimeoutError.new(self.error)
|
59
105
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
3
|
# or more contributor license agreements. See the NOTICE file
|
4
4
|
# distributed with this work for additional information
|
@@ -15,11 +15,11 @@
|
|
15
15
|
# KIND, either express or implied. See the License for the
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
|
-
|
18
|
+
#++
|
19
19
|
|
20
|
-
module Qpid
|
20
|
+
module Qpid # :nodoc:
|
21
21
|
|
22
|
-
module Proton
|
22
|
+
module Proton # :nodoc:
|
23
23
|
|
24
24
|
module Error
|
25
25
|
|
@@ -61,6 +61,12 @@ module Qpid
|
|
61
61
|
class ArgumentError < ProtonError
|
62
62
|
end
|
63
63
|
|
64
|
+
# Represents that the client has got into an unexpected state during
|
65
|
+
# messaging.
|
66
|
+
#
|
67
|
+
class StateError < ProtonError
|
68
|
+
end
|
69
|
+
|
64
70
|
# Represents a timeout during messaging.
|
65
71
|
#
|
66
72
|
class TimeoutError < ProtonError
|
data/lib/qpid_proton/filters.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
3
|
# or more contributor license agreements. See the NOTICE file
|
4
4
|
# distributed with this work for additional information
|
@@ -15,11 +15,11 @@
|
|
15
15
|
# KIND, either express or implied. See the License for the
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
|
-
|
18
|
+
#++
|
19
19
|
|
20
|
-
module Qpid
|
20
|
+
module Qpid # :nodoc:
|
21
21
|
|
22
|
-
module Proton
|
22
|
+
module Proton # :nodoc:
|
23
23
|
|
24
24
|
module Filters
|
25
25
|
|
data/lib/qpid_proton/hash.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
3
|
# or more contributor license agreements. See the NOTICE file
|
4
4
|
# distributed with this work for additional information
|
@@ -15,14 +15,14 @@
|
|
15
15
|
# KIND, either express or implied. See the License for the
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
|
-
|
18
|
+
#++
|
19
19
|
|
20
20
|
#--
|
21
21
|
# Patch the Hash class to provide methods for adding its contents
|
22
22
|
# to a Qpid::Proton::Data instance.
|
23
23
|
#++
|
24
24
|
|
25
|
-
class Hash
|
25
|
+
class Hash # :nodoc:
|
26
26
|
|
27
27
|
# Places the contents of the hash into the specified data object.
|
28
28
|
#
|
data/lib/qpid_proton/mapping.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
3
|
# or more contributor license agreements. See the NOTICE file
|
4
4
|
# distributed with this work for additional information
|
@@ -15,7 +15,7 @@
|
|
15
15
|
# KIND, either express or implied. See the License for the
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
|
-
|
18
|
+
#++
|
19
19
|
|
20
20
|
module Qpid # :nodoc:
|
21
21
|
|
@@ -106,11 +106,35 @@ module Qpid # :nodoc:
|
|
106
106
|
DECIMAL128 = Mapping.new(Cproton::PN_DECIMAL128, "decimal128")
|
107
107
|
UUID = Mapping.new(Cproton::PN_UUID, "uuid")
|
108
108
|
BINARY = Mapping.new(Cproton::PN_BINARY, "binary")
|
109
|
-
STRING = Mapping.new(Cproton::PN_STRING, "string", [String, Symbol
|
109
|
+
STRING = Mapping.new(Cproton::PN_STRING, "string", [String, Symbol,
|
110
|
+
UTFString,
|
111
|
+
BinaryString])
|
110
112
|
|
111
|
-
class << STRING
|
113
|
+
class << STRING # :nodoc:
|
112
114
|
def put(data, value)
|
113
|
-
|
115
|
+
# if we have a symbol then convert it to a string
|
116
|
+
value = value.to_s if value.is_a?(Symbol)
|
117
|
+
|
118
|
+
isutf = false
|
119
|
+
|
120
|
+
if value.is_a?(Qpid::Proton::UTFString)
|
121
|
+
isutf = true
|
122
|
+
else
|
123
|
+
# For Ruby 1.8 we will just treat all strings as binary.
|
124
|
+
# For Ruby 1.9+ we can check the encoding first to see what it is
|
125
|
+
if RUBY_VERSION >= "1.9"
|
126
|
+
# If the string is ASCII-8BIT then treat is as binary. Otherwise,
|
127
|
+
# try to convert it to UTF-8 and, if successful, send as that.
|
128
|
+
if value.encoding != Encoding::ASCII_8BIT &&
|
129
|
+
value.encode(Encoding::UTF_8).valid_encoding?
|
130
|
+
isutf = true
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
data.string = value if isutf
|
136
|
+
data.binary = value if !isutf
|
137
|
+
|
114
138
|
end
|
115
139
|
end
|
116
140
|
|
@@ -120,12 +144,16 @@ module Qpid # :nodoc:
|
|
120
144
|
LIST = Mapping.new(Cproton::PN_LIST, "list", [::Array], "get_array")
|
121
145
|
MAP = Mapping.new(Cproton::PN_MAP, "map", [::Hash], "get_map")
|
122
146
|
|
123
|
-
class << MAP
|
124
|
-
def put(data, map)
|
147
|
+
class << MAP # :nodoc:
|
148
|
+
def put(data, map, options = {})
|
125
149
|
data.put_map
|
126
150
|
data.enter
|
127
151
|
map.each_pair do |key, value|
|
128
|
-
|
152
|
+
if options[:keys] == :SYMBOL
|
153
|
+
SYMBOL.put(data, key)
|
154
|
+
else
|
155
|
+
Mapping.for_class(key.class).put(data, key)
|
156
|
+
end
|
129
157
|
|
130
158
|
if value.nil?
|
131
159
|
data.null
|
data/lib/qpid_proton/message.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#--
|
2
2
|
# Licensed to the Apache Software Foundation (ASF) under one
|
3
3
|
# or more contributor license agreements. See the NOTICE file
|
4
4
|
# distributed with this work for additional information
|
@@ -15,16 +15,32 @@
|
|
15
15
|
# KIND, either express or implied. See the License for the
|
16
16
|
# specific language governing permissions and limitations
|
17
17
|
# under the License.
|
18
|
-
|
18
|
+
#++
|
19
19
|
|
20
|
-
module Qpid
|
20
|
+
module Qpid # :nodoc:
|
21
21
|
|
22
|
-
module Proton
|
22
|
+
module Proton # :nodoc:
|
23
23
|
|
24
24
|
# A Message represents an addressable quantity of data.
|
25
25
|
#
|
26
|
+
# ==== Message Body
|
27
|
+
#
|
28
|
+
# The message body can be set using the #body= method. The message will
|
29
|
+
# then attempt to determine how exactly to encode the content.
|
30
|
+
#
|
26
31
|
# ==== Examples
|
27
32
|
#
|
33
|
+
# To create a message for sending:
|
34
|
+
#
|
35
|
+
# # send a simple text message
|
36
|
+
# msg = Qpid::Proton::Message.new
|
37
|
+
# msg.body = "STATE: update"
|
38
|
+
#
|
39
|
+
# # send a binary chunk of data
|
40
|
+
# data = File.binread("/home/qpid/binfile.tar.gz")
|
41
|
+
# msg = Qpid::Proton::Message.new
|
42
|
+
# msg.body = Qpid::Proton::BinaryString.new(data)
|
43
|
+
#
|
28
44
|
class Message
|
29
45
|
|
30
46
|
# Decodes a message from supplied AMQP data and returns the number
|
@@ -94,7 +110,7 @@ module Qpid
|
|
94
110
|
annts.clear
|
95
111
|
if !@annotations.nil?
|
96
112
|
mapping = Qpid::Proton::Mapping.for_class(@annotations.class)
|
97
|
-
mapping.put(annts, @annotations)
|
113
|
+
mapping.put(annts, @annotations, :keys => :SYMBOL)
|
98
114
|
end
|
99
115
|
body = Qpid::Proton::Data.new(Cproton::pn_message_body(@impl))
|
100
116
|
body.clear
|
@@ -372,6 +388,8 @@ module Qpid
|
|
372
388
|
#
|
373
389
|
# See MessageFormat for more details on formats.
|
374
390
|
#
|
391
|
+
# *Warning:* This method has been deprecated.
|
392
|
+
#
|
375
393
|
# ==== Options
|
376
394
|
#
|
377
395
|
# * format - the format
|
@@ -383,6 +401,12 @@ module Qpid
|
|
383
401
|
|
384
402
|
# Returns the message format
|
385
403
|
#
|
404
|
+
# *Warning:* This method has been deprecated.
|
405
|
+
#
|
406
|
+
# ==== Note
|
407
|
+
#
|
408
|
+
# This method is now deprecated.
|
409
|
+
#
|
386
410
|
def format
|
387
411
|
Qpid::Proton::MessageFormat.by_value(Cproton.pn_message_get_format(@impl))
|
388
412
|
end
|
@@ -403,22 +427,6 @@ module Qpid
|
|
403
427
|
Cproton.pn_message_get_content_type(@impl)
|
404
428
|
end
|
405
429
|
|
406
|
-
# Sets the message content.
|
407
|
-
#
|
408
|
-
# ==== Options
|
409
|
-
#
|
410
|
-
# * content - the content
|
411
|
-
#
|
412
|
-
def content=(content)
|
413
|
-
Cproton.pn_message_load(@impl, content)
|
414
|
-
end
|
415
|
-
|
416
|
-
# Returns the message content.
|
417
|
-
#
|
418
|
-
def content
|
419
|
-
Cproton.pn_message_save(@impl, 1024)[1]
|
420
|
-
end
|
421
|
-
|
422
430
|
# Sets the content encoding type.
|
423
431
|
#
|
424
432
|
# ==== Options
|
@@ -601,7 +609,7 @@ module Qpid
|
|
601
609
|
|
602
610
|
def check(err) # :nodoc:
|
603
611
|
if err < 0
|
604
|
-
raise DataError, "[#{err}]: #{Cproton.pn_message_error(@
|
612
|
+
raise DataError, "[#{err}]: #{Cproton.pn_message_error(@impl)}"
|
605
613
|
else
|
606
614
|
return err
|
607
615
|
end
|