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,45 @@
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::Reactor
21
+
22
+ class SessionPerConnection
23
+
24
+ include Qpid::Proton::Util::Reactor
25
+
26
+ def initialize
27
+ @default_session = nil
28
+ end
29
+
30
+ def session(connection)
31
+ if @default_session.nil?
32
+ @default_session = self.create_session
33
+ @default_session.context = self
34
+ end
35
+ return @default_session
36
+ end
37
+
38
+ def on_session_remote_close(event)
39
+ event.connection.close
40
+ @default_session = nil
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,41 @@
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::Reactor
21
+
22
+ class SSLConfig
23
+
24
+ def initialize
25
+ @client = Qpid::Proton::SSLDomain.new(Qpid::Proton::SSLDomain::MODE_CLIENT)
26
+ @server = Qpid::Proton::SSLDomain.new(Qpid::Proton::SSLDomain::MODE_SERVER)
27
+ end
28
+
29
+ def set_credentials(cert_file, key_file, password)
30
+ @client.set_credentials(cert_file, key_file, password)
31
+ @server.set_credentials(cert_file, key_file, password)
32
+ end
33
+
34
+ def set_trusted_ca_db(certificate_db)
35
+ @client.set_trusted_ca_db(certificate_db)
36
+ @server.set_trusted_ca_db(certificate_db)
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,39 @@
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::Reactor
21
+
22
+ class Task
23
+
24
+ # @private
25
+ include Qpid::Proton::Util::Wrapper
26
+
27
+ def self.wrap(impl)
28
+ return nil if impl.nil?
29
+ self.fetch_instance(impl, :pn_task_attachments) || Task.new(impl)
30
+ end
31
+
32
+ def initialize(impl)
33
+ @impl = impl
34
+ self.class.store_instance(self, :pn_task_attachments)
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -17,23 +17,22 @@
17
17
  # under the License.
18
18
  #++
19
19
 
20
- module Qpid # :nodoc:
20
+ module Qpid::Proton::Reactor
21
21
 
22
- module Proton # :nodoc:
22
+ class URLs
23
23
 
24
- # A +Subscription+ is an opaque object for working with a +Messenger+'s
25
- # subscriptions.
26
- #
27
- class Subscription
28
-
29
- def initialize(impl) # :nodoc:
30
- @impl = impl
31
- end
24
+ def initialize(values)
25
+ @values = [values].flatten
26
+ @iter = @values.each
27
+ end
32
28
 
33
- def impl # :nodoc:
34
- @impl
29
+ def next
30
+ begin
31
+ return @iter.next
32
+ rescue StopIteration
33
+ @iter = @values.each
34
+ return @iter.next
35
35
  end
36
-
37
36
  end
38
37
 
39
38
  end
@@ -22,43 +22,42 @@
22
22
  # to a Qpid::Proton::Data instance.
23
23
  #++
24
24
 
25
- module Qpid # :nodoc:
26
-
27
- module Proton # :nodoc:
28
-
29
- # Holds the information for an AMQP Array compound type.
30
- #
31
- # It holds the type for the array and the descriptor if the
32
- # array is described.
33
- #
34
- class ArrayHeader
35
- attr_reader :type
36
- attr_reader :descriptor
37
-
38
- def initialize(type, descriptor = nil)
39
- @type = type
40
- @descriptor = descriptor
41
- end
25
+ module Qpid::Proton::Types
42
26
 
43
- # Returns true if the array is described.
44
- def described?
45
- !@descriptor.nil?
46
- end
27
+ # Holds the information for an AMQP Array compound type.
28
+ #
29
+ # It holds the type for the array and the descriptor if the
30
+ # array is described.
31
+ #
32
+ # @private
33
+ #
34
+ class ArrayHeader
35
+ attr_reader :type
36
+ attr_reader :descriptor
47
37
 
48
- def ==(that)
49
- ((@type == that.type) && (@descriptor == that.descriptor))
50
- end
38
+ def initialize(type, descriptor = nil)
39
+ @type = type
40
+ @descriptor = descriptor
41
+ end
42
+
43
+ # Returns true if the array is described.
44
+ def described?
45
+ !@descriptor.nil?
51
46
  end
52
47
 
48
+ def ==(that)
49
+ ((@type == that.type) && (@descriptor == that.descriptor))
50
+ end
53
51
  end
54
52
 
55
53
  end
56
54
 
55
+ # @private
57
56
  class Array # :nodoc:
58
57
 
59
58
  # Used to declare an array as an AMQP array.
60
59
  #
61
- # The value, if defined, is an instance of Qpid::Proton::ArrayHeader
60
+ # The value, if defined, is an instance of Qpid::Proton::Types::ArrayHeader
62
61
  attr_accessor :proton_array_header
63
62
 
64
63
  # Returns true if the array is the a Proton described type.
@@ -85,7 +84,7 @@ class Array # :nodoc:
85
84
  data.enter
86
85
  each do |element|
87
86
  # get the proton type for the element
88
- mapping = Qpid::Proton::Mapping.for_class(element.class)
87
+ mapping = Qpid::Proton::Codec::Mapping.for_class(element.class)
89
88
  # add the element
90
89
  mapping.put(data, element)
91
90
  end
@@ -116,9 +115,9 @@ class Array # :nodoc:
116
115
 
117
116
  type = data.type
118
117
 
119
- if type == Qpid::Proton::LIST
118
+ if type == Qpid::Proton::Codec::LIST
120
119
  result = proton_get_list(data)
121
- elsif type == Qpid::Proton::ARRAY
120
+ elsif type == Qpid::Proton::Codec::ARRAY
122
121
  result = proton_get_array(data)
123
122
  else
124
123
  raise TypeError, "element is not a list and not an array"
@@ -154,7 +153,7 @@ class Array # :nodoc:
154
153
  descriptor = data.symbol
155
154
  end
156
155
 
157
- elements.proton_array_header = Qpid::Proton::ArrayHeader.new(type, descriptor)
156
+ elements.proton_array_header = Qpid::Proton::Types::ArrayHeader.new(type, descriptor)
158
157
  (0...count).each do |which|
159
158
  if data.next
160
159
  etype = data.type
@@ -0,0 +1,63 @@
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::Types
21
+
22
+ # @private
23
+ class Described
24
+
25
+ attr_reader :descriptor
26
+ attr_reader :value
27
+
28
+ def initialize(descriptor, value)
29
+ @descriptor = descriptor
30
+ @value = value
31
+ end
32
+
33
+ # Puts the description into the Data object.
34
+ #
35
+ # ==== Arguments
36
+ #
37
+ # * data - the Qpid::Proton::Data instance
38
+ #
39
+ # ==== Examples
40
+ #
41
+ # described = Qpid::Proton::Described.new("my-descriptor", "the value")
42
+ # data = Qpid::Proton::Data.new
43
+ # ...
44
+ # described.put(data)
45
+ #
46
+ def put(data)
47
+ data.symbol = @descriptor
48
+ data.string = @value
49
+ end
50
+
51
+ def ==(that) # :nodoc:
52
+ (that.is_a?(Qpid::Proton::Types::Described) &&
53
+ (self.descriptor == that.descriptor) &&
54
+ (self.value == that.value))
55
+ end
56
+
57
+ def to_s # :nodoc:
58
+ "descriptor=#{descriptor} value=#{value}"
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -22,6 +22,7 @@
22
22
  # to a Qpid::Proton::Data instance.
23
23
  #++
24
24
 
25
+ # @private
25
26
  class Hash # :nodoc:
26
27
 
27
28
  # Places the contents of the hash into the specified data object.
@@ -43,9 +44,9 @@ class Hash # :nodoc:
43
44
  data.enter
44
45
 
45
46
  each_pair do |key, value|
46
- type = Qpid::Proton::Mapping.for_class(key.class)
47
+ type = Qpid::Proton::Codec::Mapping.for_class(key.class)
47
48
  type.put(data, key)
48
- type = Qpid::Proton::Mapping.for_class(value.class)
49
+ type = Qpid::Proton::Codec::Mapping.for_class(value.class)
49
50
  type.put(data, value)
50
51
  end
51
52
 
@@ -59,7 +60,7 @@ class Hash # :nodoc:
59
60
 
60
61
  type = data.type
61
62
 
62
- raise TypeError, "element is not a map" unless type == Qpid::Proton::MAP
63
+ raise TypeError, "element is not a map" unless type == Qpid::Proton::Codec::MAP
63
64
 
64
65
  count = data.map
65
66
  result = {}
@@ -0,0 +1,62 @@
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::Types
21
+
22
+ # @private
23
+ def self.is_valid_utf?(value)
24
+ # In Ruby 1.9+ we have encoding methods that can check the content of
25
+ # the string, so use them to see if what we have is unicode. If so,
26
+ # good! If not, then just treat is as binary.
27
+ #
28
+ # No such thing in Ruby 1.8. So there we need to use Iconv to try and
29
+ # convert it to unicode. If it works, good! But if it raises an
30
+ # exception then we'll treat it as binary.
31
+ if RUBY_VERSION < "1.9"
32
+ return true if value.isutf8
33
+ return false
34
+ else
35
+ return true if (value.encoding == "UTF-8" ||
36
+ value.encode("UTF-8").valid_encoding?)
37
+
38
+ return false
39
+ end
40
+ end
41
+
42
+ # UTFString lets an application explicitly state that a
43
+ # string of characters is to be UTF-8 encoded.
44
+ #
45
+ class UTFString < ::String
46
+
47
+ def initialize(value)
48
+ if !Qpid::Proton::Types.is_valid_utf?(value)
49
+ raise RuntimeError.new("invalid UTF string")
50
+ end
51
+
52
+ super(value)
53
+ end
54
+
55
+ end
56
+
57
+ # BinaryString lets an application explicitly declare that
58
+ # a string value represents arbitrary data.
59
+ #
60
+ class BinaryString < ::String; end
61
+
62
+ end
@@ -0,0 +1,54 @@
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::Util
21
+
22
+ # This mixin provides a method for mapping from an underlying Proton
23
+ # C library class to a Ruby class.
24
+ #
25
+ # @private
26
+ #
27
+ module ClassWrapper
28
+
29
+ WRAPPERS =
30
+ {
31
+ "pn_void" => proc {|x| Cproton.pn_void2rb(x)},
32
+ "pn_rbref" => proc {|x| Cproton.pn_void2rb(x)},
33
+ "pn_connection" => proc {|x| Qpid::Proton::Connection.wrap(Cproton.pn_cast_pn_connection(x))},
34
+ "pn_session" => proc {|x| Qpid::Proton::Session.wrap(Cproton.pn_cast_pn_session(x))},
35
+ "pn_link" => proc {|x| Qpid::Proton::Link.wrap(Cproton.pn_cast_pn_link(x))},
36
+ "pn_delivery" => proc {|x| Qpid::Proton::Delivery.wrap(Cproton.pn_cast_pn_delivery(x))},
37
+ "pn_transport" => proc {|x| Qpid::Proton::Transport.wrap(Cproton.pn_cast_pn_transport(x))},
38
+ "pn_selectable" => proc {|x| Qpid::Proton::Selectable.wrap(Cproton.pn_cast_pn_selectable(x))},
39
+ "pn_reactor" => proc {|x| Qpid::Proton::Reactor::Reactor.wrap(Cproton.pn_cast_pn_reactor(x))},
40
+ "pn_task" => proc {|x| Qpid::Proton::Reactor::Task.wrap(Cproton.pn_cast_pn_task(x))},
41
+ }
42
+
43
+ def class_wrapper(clazz, c_impl, &block)
44
+ proc_func = WRAPPERS[clazz]
45
+ if !proc_func.nil?
46
+ proc_func.yield(c_impl)
47
+ elsif block_given?
48
+ yield(c_impl)
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end