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::Util
21
+
22
+ class Condition
23
+
24
+ def initialize(name, description = nil, info = nil)
25
+ @name = name
26
+ @description = description
27
+ @info = info
28
+ end
29
+
30
+ # @private
31
+ def to_s
32
+ "Condition(#{@name}, #{@description}, #{@info})"
33
+ end
34
+
35
+ # @private
36
+ def ==(other)
37
+ ((other.class = self.class) &&
38
+ (other.name == self.name) &&
39
+ (other.description == self.description) &&
40
+ (other.info == self.info))
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,85 @@
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
+ # Provides a means for defining constant values within the namespace
23
+ # of a class.
24
+ #
25
+ # If the class has defined the class method, :post_add_constant, then that
26
+ # method will be invoked after each new item is added. It must be defined
27
+ # *before* any constants are defined.
28
+ #
29
+ # ==== Example
30
+ #
31
+ # class GrammarComponent
32
+ #
33
+ # include Qpid::Proton::Constants
34
+ #
35
+ # def self.post_add_constant(key, value)
36
+ # @terminal << value if value.terminal?
37
+ # @nonterminal << value if !value.terminal? && !value.rule
38
+ # @rule << value if value.rule
39
+ # end
40
+ #
41
+ # self.add_constant :LEFT_PARENTHESIS, new GrammarComponent("(", :terminal)
42
+ # self.add_constant :RIGHT_PARENTHESIS, new GrammarComponent(")", :terminal)
43
+ # self.add_constant :ELEMENT, new GrammarComponent("E", :rule)
44
+ #
45
+ # def initialize(component, type)
46
+ # @component = component
47
+ # @type = type
48
+ # end
49
+ #
50
+ # def terminal?; @type == :terminal; end
51
+ #
52
+ # def rule?; @type == :rule; end
53
+ #
54
+ # end
55
+ #
56
+ # @private
57
+ #
58
+ module Constants
59
+
60
+ def self.included(base)
61
+ base.extend ClassMethods
62
+ end
63
+
64
+ module ClassMethods
65
+
66
+ def add_constant(key, value)
67
+ self.const_set(key, value)
68
+
69
+ @pn_by_value ||= {}
70
+ @pn_by_value[value] = key
71
+
72
+ if self.respond_to? :post_add_constant
73
+ self.post_add_constant(key, value)
74
+ end
75
+ end
76
+
77
+ def by_value(value)
78
+ (@pn_by_value || {})[value]
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,82 @@
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
+ # @private
23
+ module Engine
24
+
25
+ # Convenience method to receive messages from a delivery.
26
+ #
27
+ # @param delivery [Qpid::Proton::Delivery] The delivery.
28
+ # @param message [Qpid::Proton::Message] The message to use.
29
+ #
30
+ # @return [Qpid::Proton::Message] the message
31
+ #
32
+ def self.receive_message(delivery, msg = nil)
33
+ msg = Qpid::Proton::Message.new if msg.nil?
34
+ msg.decode(delivery.link.receive(delivery.pending))
35
+ delivery.link.advance
36
+ return msg
37
+ end
38
+
39
+ def data_to_object(data_impl) # :nodoc:
40
+ object = nil
41
+ unless data_impl.nil?
42
+ data = Qpid::Proton::Codec::Data.new(data_impl)
43
+ data.rewind
44
+ data.next
45
+ object = data.object
46
+ data.rewind
47
+ end
48
+ return object
49
+ end
50
+
51
+ def object_to_data(object, data_impl) # :nodoc:
52
+ unless object.nil?
53
+ data = Data.new(data_impl)
54
+ data.object = object
55
+ end
56
+ end
57
+
58
+ def condition_to_object(condition) # :nodoc:
59
+ result = nil
60
+ if Cproton.pn_condition_is_set(condition)
61
+ result = Condition.new(Cproton.pn_condition_get_name(condition),
62
+ Cproton.pn_condition_get_description(condition),
63
+ data_to_object(Cproton.pn_condition_info(condition)))
64
+ end
65
+ return result
66
+ end
67
+
68
+ def object_to_condition(object, condition) # :nodoc:
69
+ Cproton.pn_condition_clear(condition)
70
+ unless object.nil?
71
+ Cproton.pn_condition_set_name(condition, object.name)
72
+ Cproton.pn_condition_set_description(condition, object.description)
73
+ info = Data.new(Cproton.pn_condition_info(condition))
74
+ if object.info?
75
+ info.object = object.info
76
+ end
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ end
@@ -0,0 +1,127 @@
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
+ # Provides mixin functionality for dealing with exception conditions.
23
+ #
24
+ # @private
25
+ module ErrorHandler
26
+
27
+ def self.included(base)
28
+ base.extend(self)
29
+
30
+ unless defined? base.to_be_wrapped
31
+ class << base
32
+ @@to_be_wrapped = []
33
+ end
34
+ end
35
+
36
+ define_method :method_added do |name|
37
+ if (!@@to_be_wrapped.nil?) && (@@to_be_wrapped.include? name)
38
+ @@to_be_wrapped.delete name
39
+ create_exception_handler_wrapper(name)
40
+ end
41
+ end
42
+ end
43
+
44
+ def can_raise_error(method_names, options = {})
45
+ error_class = options[:error_class]
46
+ below = options[:below] || 0
47
+ # coerce the names to be an array
48
+ Array(method_names).each do |method_name|
49
+ # if the method doesn't already exist then queue this aliasing
50
+ unless self.method_defined? method_name
51
+ @@to_be_wrapped ||= []
52
+ @@to_be_wrapped << method_name
53
+ else
54
+ create_exception_handler_wrapper(method_name, error_class, below)
55
+ end
56
+ end
57
+ end
58
+
59
+ def create_exception_handler_wrapper(method_name, error_class = nil, below = 0)
60
+ original_method_name = method_name.to_s
61
+ wrapped_method_name = "_excwrap_#{original_method_name}"
62
+ alias_method wrapped_method_name, original_method_name
63
+ define_method original_method_name do |*args, &block|
64
+ # need to get a reference to the method object itself since
65
+ # calls to Class.send interfere with Messenger.send
66
+ method = self.method(wrapped_method_name.to_sym)
67
+ rc = method.call(*args, &block)
68
+ check_for_error(rc, error_class) if rc < below
69
+ return rc
70
+ end
71
+ end
72
+
73
+ # Raises an Proton-specific error if a return code is non-zero.
74
+ #
75
+ # Expects the class to provide an +error+ method.
76
+ def check_for_error(code, error_class = nil)
77
+
78
+ raise ::ArgumentError.new("Invalid error code: #{code}") if code.nil?
79
+
80
+ return code if code > 0
81
+
82
+ case(code)
83
+
84
+ when Qpid::Proton::Error::NONE
85
+ return
86
+
87
+ when Qpid::Proton::Error::EOS
88
+ raise Qpid::Proton::EOSError.new(self.error)
89
+
90
+ when Qpid::Proton::Error::ERROR
91
+ raise Qpid::Proton::ProtonError.new(self.error)
92
+
93
+ when Qpid::Proton::Error::OVERFLOW
94
+ raise Qpid::Proton::OverflowError.new(self.error)
95
+
96
+ when Qpid::Proton::Error::UNDERFLOW
97
+ raise Qpid::Proton::UnderflowError.new(self.error)
98
+
99
+ when Qpid::Proton::Error::ARGUMENT
100
+ raise Qpid::Proton::ArgumentError.new(self.error)
101
+
102
+ when Qpid::Proton::Error::STATE
103
+ raise Qpid::Proton::StateError.new(self.error)
104
+
105
+ when Qpid::Proton::Error::TIMEOUT
106
+ raise Qpid::Proton::TimeoutError.new(self.error)
107
+
108
+ when Qpid::Proton::Error::INPROGRESS
109
+ return
110
+
111
+ when Qpid::Proton::Error::INTERRUPTED
112
+ raise Qpid::Proton::InterruptedError.new(self.error)
113
+
114
+ when Qpid::Proton::Error::INPROGRESS
115
+ raise Qpid::Proton::InProgressError.new(self.error)
116
+
117
+ else
118
+
119
+ raise ::ArgumentError.new("Unknown error code: #{code}")
120
+
121
+ end
122
+
123
+ end
124
+
125
+ end
126
+
127
+ 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::Util
21
+
22
+ # @private
23
+ module Handler
24
+
25
+ def chandler(handler, on_error)
26
+ return nil if handler.nil?
27
+
28
+ if handler.instance_of?(Qpid::Proton::Handler::WrappedHandler)
29
+ impl = handler.impl
30
+ Cproton.pn_incref(impl)
31
+ return impl
32
+ else
33
+ cadaptor = Qpid::Proton::Handler::CAdaptor.new(handler, on_error)
34
+ rbhandler = Cproton.pn_rbhandler(cadaptor)
35
+ return rbhandler
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,32 @@
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
+ module Reactor
23
+
24
+ def create_session(connection, handler = nil)
25
+ session = connection.session
26
+ session.open
27
+ return session
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,114 @@
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
+ # Provides helper functions for writing wrapper functions for the
23
+ # underlying C APIs.
24
+ #
25
+ # Before defining any mutators the class must define the name of the
26
+ # prefix for methods with the constant PROTON_METOD_PREFIX.
27
+ #
28
+ # == Mutators, Setters And Getters
29
+ #
30
+ # There are three types of wrappers that are supported:
31
+ #
32
+ # [proton_writer] Defines a set-only method for the named attribute.
33
+ # [proton_reader] Defines a get-only method for the named attribute.
34
+ # [proton_accessor] Defines both a set- and a get-method for the named
35
+ # attribute.
36
+ # [proton_caller] A simple wrapper for calling an underlying method,
37
+ # avoids repetitive boiler plate coding.
38
+ #
39
+ # == Arguments
40
+ #
41
+ # [:is_or_get => {:is, :get}] For both the getter and the mutator types
42
+ # you can also declare that the method uses "is" instead of "get" in the
43
+ # underlying API. Such methods are then defined with "?"
44
+ #
45
+ # @example
46
+ # class Terminus
47
+ #
48
+ # include WrapperHelper
49
+ #
50
+ # PROTON_METHOD_PREFIX = "pn_terminus"
51
+ #
52
+ # # add methods "type" and "type=" that call "pn_terminus_{get,set}_type"
53
+ # proton_accessor :type
54
+ #
55
+ # # adds the method "dynamic?" that calls "pn_terminus_is_dynamic"
56
+ # proton_accessor :dynamic, :is_or_get => :is
57
+ #
58
+ # # adds a method named "foo" that calls "pn_terminus_foo"
59
+ # proton_caller :foo
60
+ #
61
+ # end
62
+ #
63
+ # @private
64
+ module SwigHelper
65
+
66
+ def self.included(base)
67
+ base.extend ClassMethods
68
+ end
69
+
70
+ module ClassMethods # :nodoc:
71
+
72
+ def create_wrapper_method(name, proton_method, with_arg = false)
73
+ if with_arg
74
+ define_method "#{name}" do |arg|
75
+ Cproton.__send__(proton_method.to_sym, @impl, arg)
76
+ end
77
+ else
78
+ define_method "#{name}" do
79
+ Cproton.__send__(proton_method.to_sym, @impl)
80
+ end
81
+ end
82
+ end
83
+
84
+ # Defines a method that calls an underlying C library function.
85
+ def proton_caller(name, options = {})
86
+ proton_method = "#{self::PROTON_METHOD_PREFIX}_#{name}"
87
+ # drop the trailing '?' if this is a property method
88
+ proton_method = proton_method[0..-2] if proton_method.end_with? "?"
89
+ create_wrapper_method(name, proton_method)
90
+ end
91
+
92
+ def proton_writer(name, options = {})
93
+ proton_method = "#{self::PROTON_METHOD_PREFIX}_set_#{name}"
94
+ create_wrapper_method("#{name}=", proton_method, true)
95
+ end
96
+
97
+ def proton_reader(name, options = {})
98
+ an_is_method = options[:is_or_get] == :is
99
+ prefix = (an_is_method) ? "is" : "get"
100
+ proton_method = "#{self::PROTON_METHOD_PREFIX}_#{prefix}_#{name}"
101
+ name = "#{name}?" if an_is_method
102
+ create_wrapper_method(name, proton_method)
103
+ end
104
+
105
+ def proton_accessor(name, options = {})
106
+ proton_writer(name, options)
107
+ proton_reader(name, options)
108
+ end
109
+
110
+ end
111
+
112
+ end
113
+
114
+ end