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,91 @@
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::Event
21
+
22
+ # @private
23
+ def self.dispatch(handler, method, *args)
24
+ args = args.last unless args.nil?
25
+ if handler.respond_to? method.to_sym
26
+ return handler.__send__(method, args)
27
+ elsif handler.respond_to? :on_unhandled
28
+ return handler.__send__(:on_unhandled, method, args)
29
+ end
30
+ end
31
+
32
+ # EventBase is the foundation for creating application-specific events.
33
+ #
34
+ # @example
35
+ #
36
+ # # SCENARIO: A continuation of the example in EventType.
37
+ # #
38
+ # # An Event class is defined to handle receiving encrypted
39
+ # # data from a remote endpoint.
40
+ #
41
+ # class EncryptedDataEvent < EventBase
42
+ # def initialize(message)
43
+ # super(EncryptedDataEvent, message,
44
+ # Qpid::Proton::Event::ENCRYPTED_RECV)
45
+ # end
46
+ # end
47
+ #
48
+ # # at another point, when encrypted data is received
49
+ # msg = Qpid::Proton::Message.new
50
+ # msg.decode(link.receive(link.pending))
51
+ # if encrypted?(msg)
52
+ # collector.put(EncryptedDataEvent.new(msg)
53
+ # end
54
+ #
55
+ # @see EventType The EventType class for how ENCRYPTED_RECV was defined.
56
+ #
57
+ class EventBase
58
+
59
+ # Returns the name for the class associated with this event.
60
+ attr_reader :class_name
61
+
62
+ # Returns the associated context object for the event.
63
+ attr_reader :context
64
+
65
+ # Returns the type of the event.
66
+ attr_reader :type
67
+
68
+ # Creates a new event with the specific class_name and context of the
69
+ # specified type.
70
+ #
71
+ # @param class_name [String] The name of the class.
72
+ # @param context [Object] The event context.
73
+ # @param type [EventType] The event type.
74
+ #
75
+ def initialize(class_name, context, type)
76
+ @class_name = class_name
77
+ @context = context
78
+ @type = type
79
+ end
80
+
81
+ # Invokes the type-specific method on the provided handler.
82
+ #
83
+ # @param handler [Object] The handler to be notified of this event.
84
+ #
85
+ def dispatch(handler)
86
+ Qpid::Proton.dispatch(handler, @type.method, self)
87
+ end
88
+
89
+ end
90
+
91
+ end
@@ -0,0 +1,71 @@
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::Event
21
+
22
+ # Manages the association between an Event and the method which should
23
+ # process on the context object associated with an occurance of the event.
24
+ #
25
+ # Each type is identified by a unique #type value.
26
+ #
27
+ # @example
28
+ #
29
+ # # SCENARIO: A part of an application handles extracting and decrypting
30
+ # # data received from a remote endpoint.
31
+ # #
32
+ # # An EventType is created to notify handlers that such a
33
+ # # situation has occurred.
34
+ #
35
+ # ENCRYPTED_RECV = 10000 # the unique constant value for the event
36
+ #
37
+ # # create a new event type which, when it occurs, invokes a method
38
+ # # named :on_encrypted_data when a handler is notified of its occurrance
39
+ # Qpid::Proton::Event::ENCRYPTED_RECV =
40
+ # Qpid::Proton::Event::EventType.new(ENCRYPTED_RECV, :on_encrypted_data)
41
+ #
42
+ # @see EventBase EventBase for the rest of this example.
43
+ # @see Qpid::Proton::Event::Event The Event class for more details on events.
44
+ #
45
+ class EventType
46
+
47
+ # The method to invoke on any potential handler.
48
+ attr_reader :method
49
+ attr_reader :number
50
+
51
+ def initialize(number, method)
52
+ @number = number
53
+ @name = Cproton.pn_event_type_name(@number)
54
+ @method = method
55
+ @@types ||= {}
56
+ @@types[number] = self
57
+ end
58
+
59
+ # @private
60
+ def to_s
61
+ @name
62
+ end
63
+
64
+ # @private
65
+ def self.by_type(type) # :nodoc:
66
+ @@types[type]
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,70 @@
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::Handler
21
+
22
+ # Mixing that provides methods for acknowledging a delivery.
23
+ #
24
+ module Acking
25
+
26
+ # Accept the receivered message.
27
+ #
28
+ # @param delivery [Qpid::Proton::Delivery] The delivery.
29
+ #
30
+ def accept(delivery)
31
+ self.settle(delivery, Qpid::Proton::Delivery::ACCEPTED)
32
+ end
33
+
34
+ # Rejects a received message that is considered invalid or unprocessable.
35
+ #
36
+ # @param delivery [Qpid::Proton::Delivery] The delivery.
37
+ #
38
+ def reject(delivery)
39
+ self.settle(delivery, Qpid::Proton::Delivery::REJECTED)
40
+ end
41
+
42
+ # Releases a received message, making it available at the source for any
43
+ # other interested receiver.
44
+ #
45
+ # @param delivery [Qpid::Proton::Delivery] The delivery
46
+ # @param delivered [Boolean] True if this was considered a delivery
47
+ # attempt.
48
+ #
49
+ def release(delivery, delivered = true)
50
+ if delivered
51
+ self.settle(delivery, Qpid::Proton::Delivery::MODIFIED)
52
+ else
53
+ self.settle(delivery, Qpid::Proton::Delivery::RELEASED)
54
+ end
55
+ end
56
+
57
+ # Settles the specified delivery. Updates the delivery state if a state
58
+ # is specified.
59
+ #
60
+ # @param delivery [Qpid::Proton::Delivery] The delivery.
61
+ # @param state [Fixnum] The delivery state.
62
+ #
63
+ def settle(delivery, state = nil)
64
+ delivery.update(state) unless state.nil?
65
+ delivery.settle
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,47 @@
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::Handler
21
+
22
+ # @private
23
+ class CAdaptor
24
+
25
+ def initialize(handler, on_error = nil)
26
+ @handler = handler
27
+ @on_error = on_error
28
+ end
29
+
30
+ def dispatch(cevent, ctype)
31
+ event = Qpid::Proton::Event::Event.wrap(cevent, ctype)
32
+ # TODO add a variable to enable this programmatically
33
+ # print "EVENT: #{event} going to #{@handler}\n"
34
+ event.dispatch(@handler)
35
+ end
36
+
37
+ def exception(error)
38
+ if @on_error.nil?
39
+ raise error
40
+ else
41
+ @on_error.call(error)
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,33 @@
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::Handler
21
+
22
+ # @private
23
+ class CFlowController < Qpid::Proton::Handler::WrappedHandler
24
+
25
+ include Qpid::Proton::Util::Wrapper
26
+
27
+ def initialize(window = 1024)
28
+ super(Cproton.pn_flowcontroller(window))
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,217 @@
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::Handler
21
+
22
+ # A utility that exposes endpoint events; i.e., the open/close of a link,
23
+ # session or connection, in a more intuitive manner.
24
+ #
25
+ # A XXX_opened method will be called when both local and remote peers have
26
+ # opened the link, session or connection. This can be used to confirm a
27
+ # locally initiated action for example.
28
+ #
29
+ # A XXX_opening method will be called when the remote peer has requested
30
+ # an open that was not initiated locally. By default this will simply open
31
+ # locally, which then trigtgers the XXX_opened called.
32
+ #
33
+ # The same applies to close.
34
+ #
35
+ class EndpointStateHandler < Qpid::Proton::BaseHandler
36
+
37
+ def initialize(peer_close_is_error = false, delegate = nil)
38
+ @delegate = delegate
39
+ @peer_close_is_error = peer_close_is_error
40
+ end
41
+
42
+ def self.print_error(endpoint, endpoint_type)
43
+ if !endpoint.remote_condition.nil?
44
+ elsif self.local_endpoint?(endpoint) && endpoint.remote_closed?
45
+ logging.error("#{endpoint_type} closed by peer")
46
+ end
47
+ end
48
+
49
+ def on_link_remote_close(event)
50
+ if !event.link.remote_condition.nil?
51
+ self.on_link_error(event)
52
+ elsif event.link.local_closed?
53
+ self.on_link_closed(event)
54
+ else
55
+ self.on_link_closing(event)
56
+ end
57
+ event.link.close
58
+ end
59
+
60
+ def on_session_remote_close(event)
61
+ if !event.session.remote_condition.nil?
62
+ self.on_session_error(event)
63
+ elsif event.session.local_closed?
64
+ self.on_session_closed(event)
65
+ else
66
+ self.on_session_closing(event)
67
+ end
68
+ event.session.close
69
+ end
70
+
71
+ def on_connection_remote_close(event)
72
+ if !event.connection.remote_condition.nil?
73
+ self.on_connection_error(event)
74
+ elsif event.connection.local_closed?
75
+ self.on_connection_closed(event)
76
+ else
77
+ self.on_connection_closing(event)
78
+ end
79
+ event.connection.close
80
+ end
81
+
82
+ def on_connection_local_open(event)
83
+ self.on_connection_opened(event) if event.connection.remote_active?
84
+ end
85
+
86
+ def on_connection_remote_open(event)
87
+ if !(event.connection.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
88
+ self.on_connection_opened(event)
89
+ elsif event.connection.local_uninit?
90
+ self.on_connection_opening(event)
91
+ event.connection.open
92
+ end
93
+ end
94
+
95
+ def on_session_local_open(event)
96
+ self.on_session_opened(event) if event.session.remote_active?
97
+ end
98
+
99
+ def on_session_remote_open(event)
100
+ if !(event.session.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
101
+ self.on_session_opened(event)
102
+ elsif event.session.local_uninit?
103
+ self.on_session_opening(event)
104
+ event.session.open
105
+ end
106
+ end
107
+
108
+ def on_link_local_open(event)
109
+ self.on_link_opened(event) if event.link.remote_active?
110
+ end
111
+
112
+ def on_link_remote_open(event)
113
+ if !(event.link.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
114
+ self.on_link_opened(event)
115
+ elsif event.link.local_uninit?
116
+ self.on_link_opening(event)
117
+ event.link.open
118
+ end
119
+ end
120
+
121
+ def on_connection_opened(event)
122
+ Qpid::Proton::Event.dispatch(@delegate, :on_session_opened, event) if !@delegate.nil?
123
+ end
124
+
125
+ def on_session_opened(event)
126
+ Qpid::Proton::Event.dispatch(@delegate, :on_session_opened, event) if !@delegate.nil?
127
+ end
128
+
129
+ def on_link_opened(event)
130
+ Qpid::Proton::Event.dispatch(@delegate, :on_link_opened, event) if !@delegate.nil?
131
+ end
132
+
133
+ def on_connection_opening(event)
134
+ Qpid::Proton::Event.dispatch(@delegate, :on_connection_opening, event) if !@delegate.nil?
135
+ end
136
+
137
+ def on_session_opening(event)
138
+ Qpid::Proton::Event.dispatch(@delegate, :on_session_opening, event) if !@delegate.nil?
139
+ end
140
+
141
+ def on_link_opening(event)
142
+ Qpid::Proton::Event.dispatch(@delegate, :on_link_opening, event) if !@delegate.nil?
143
+ end
144
+
145
+ def on_connection_error(event)
146
+ if !@delegate.nil?
147
+ Qpid::Proton::Event.dispatch(@delegate, :on_connection_error, event)
148
+ else
149
+ self.log_error(event.connection, "connection")
150
+ end
151
+ end
152
+
153
+ def on_session_error(event)
154
+ if !@delegate.nil?
155
+ Qpid::Proton::Event.dispatch(@delegate, :on_session_error, event)
156
+ else
157
+ self.log_error(event.session, "session")
158
+ event.connection.close
159
+ end
160
+ end
161
+
162
+ def on_link_error(event)
163
+ if !@delegate.nil?
164
+ Qpid::Proton::Event.dispatch(@delegate, :on_link_error, event)
165
+ else
166
+ self.log_error(event.link, "link")
167
+ event.conneciton.close
168
+ end
169
+ end
170
+
171
+ def on_connection_closed(event)
172
+ Qpid::Proton::Event.dispatch(@delegate, :on_connection_closed, event) if !@delegate.nil?
173
+ end
174
+
175
+ def on_session_closed(event)
176
+ Qpid::Proton::Event.dispatch(@delegate, :on_session_closed, event) if !@delegate.nil?
177
+ end
178
+
179
+ def on_link_closed(event)
180
+ Qpid::Proton::Event.dispatch(@delegate, :on_link_closed, event) if !@delegate.nil?
181
+ end
182
+
183
+ def on_connection_closing(event)
184
+ if !@delegate.nil?
185
+ Qpid::Proton::Event.dispatch(@delegate, :on_connection_closing, event)
186
+ elsif @peer_close_is_error
187
+ self.on_connection_error(event)
188
+ end
189
+ end
190
+
191
+ def on_session_closing(event)
192
+ if !@delegate.nil?
193
+ Qpid::Proton::Event.dispatch(@delegate, :on_session_closing, event)
194
+ elsif @peer_close_is_error
195
+ self.on_session_error(event)
196
+ end
197
+ end
198
+
199
+ def on_link_closing(event)
200
+ if !@delegate.nil?
201
+ Qpid::Proton::Event.dispatch(@delegate, :on_link_closing, event)
202
+ elsif @peer_close_is_error
203
+ self.on_link_error(event)
204
+ end
205
+ end
206
+
207
+ def on_transport_tail_closed(event)
208
+ self.on_transport_closed(event)
209
+ end
210
+
211
+ def on_transport_closed(event)
212
+ Qpid::Proton::Event.dispatch(@delegate, :on_disconnected, event) if !@delegate.nil?
213
+ end
214
+
215
+ end
216
+
217
+ end