qpid_proton 0.9.0 → 0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,271 @@
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
21
+
22
+ # A Delivery maintains detail on the delivery of data to an endpoint.
23
+ #
24
+ # A Delivery has a single parent Qpid::Proton::Link
25
+ #
26
+ # @example
27
+ #
28
+ # # SCENARIO: An event comes in notifying that data has been delivered to
29
+ # # the local endpoint. A Delivery object can be used to check
30
+ # # the details of the delivery.
31
+ #
32
+ # delivery = @event.delivery
33
+ # if delivery.readable? && !delivery.partial?
34
+ # # decode the incoming message
35
+ # msg = Qpid::Proton::Message.new
36
+ # msg.decode(link.receive(delivery.pending))
37
+ # end
38
+ #
39
+ class Delivery
40
+
41
+ # @private
42
+ include Util::Wrapper
43
+
44
+ # @private
45
+ def self.wrap(impl) # :nodoc:
46
+ return nil if impl.nil?
47
+ self.fetch_instance(impl, :pn_delivery_attachments) || Delivery.new(impl)
48
+ end
49
+
50
+ # @private
51
+ def initialize(impl)
52
+ @impl = impl
53
+ @local = Disposition.new(Cproton.pn_delivery_local(impl), true)
54
+ @remote = Disposition.new(Cproton.pn_delivery_remote(impl), false)
55
+ self.class.store_instance(self, :pn_delivery_attachments)
56
+ end
57
+
58
+ # @private
59
+ include Util::SwigHelper
60
+
61
+ # @private
62
+ PROTON_METHOD_PREFIX = "pn_delivery"
63
+
64
+ # @!attribute [r] tag
65
+ #
66
+ # @return [String] The tag for the delivery.
67
+ #
68
+ proton_caller :tag
69
+
70
+ # @!attribute [r] writable?
71
+ #
72
+ # A delivery is considered writable if it is the current delivery on an
73
+ # outgoing link, and the link has positive credit.
74
+ #
75
+ # @return [Boolean] Returns if a delivery is writable.
76
+ #
77
+ proton_caller :writable?
78
+
79
+ # @!attribute [r] readable?
80
+ #
81
+ # A delivery is considered readable if it is the current delivery on an
82
+ # incoming link.
83
+ #
84
+ # @return [Boolean] Returns if a delivery is readable.
85
+ #
86
+ proton_caller :readable?
87
+ # @!attribute [r] updated?
88
+ #
89
+ # A delivery is considered updated whenever the peer communicates a new
90
+ # disposition for the dlievery. Once a delivery becomes updated, it will
91
+ # remain so until cleared.
92
+ #
93
+ # @return [Boolean] Returns if a delivery is updated.
94
+ #
95
+ # @see #clear
96
+ #
97
+ proton_caller :updated?
98
+
99
+ # @!method clear
100
+ #
101
+ # Clear the updated flag for a delivery.
102
+ #
103
+ proton_caller :clear
104
+
105
+ # @!attribute [r] pending
106
+ #
107
+ # @return [Fixnum] Return the amount of pending message data for the
108
+ # delivery.
109
+ #
110
+ proton_caller :pending
111
+
112
+ # @!attribute [r] partial?
113
+ #
114
+ # @return [Boolean] Returns if the delivery has only partial message data.
115
+ #
116
+ proton_caller :partial?
117
+
118
+ # @!attribute [r] settled?
119
+ #
120
+ # @return [Boolean] Returns if the delivery is remotely settled.
121
+ #
122
+ proton_caller :settled?
123
+
124
+
125
+ # @!method settle
126
+ #
127
+ # Settles a delivery.
128
+ #
129
+ # A settled delivery can never be used again.
130
+ #
131
+ proton_caller :settle
132
+
133
+ # @!method dump
134
+ #
135
+ # Utility function for printing details of a delivery.
136
+ #
137
+ proton_caller :dump
138
+
139
+ # @!attribute [r] buffered?
140
+ #
141
+ # A delivery that is buffered has not yet been written to the wire.
142
+ #
143
+ # Note that returning false does not imply that a delivery was definitely
144
+ # written to the wire. If false is returned, it is not known whether the
145
+ # delivery was actually written to the wire or not.
146
+ #
147
+ # @return [Boolean] Returns if the delivery is buffered.
148
+ #
149
+ proton_caller :buffered?
150
+
151
+ include Util::Engine
152
+
153
+ def update(state)
154
+ impl = @local.impl
155
+ object_to_data(@local.data, Cproton.pn_disposition_data(impl))
156
+ object_to_data(@local.annotations, Cproton.pn_disposition_annotations(impl))
157
+ object_to_data(@local.condition, Cproton.pn_disposition_condition(impl))
158
+ Cproton.pn_delivery_update(@impl, state)
159
+ end
160
+
161
+ # Returns the local disposition state for the delivery.
162
+ #
163
+ # @return [Disposition] The local disposition state.
164
+ #
165
+ def local_state
166
+ Cproton.pn_delivery_local_state(@impl)
167
+ end
168
+
169
+ # Returns the remote disposition state for the delivery.
170
+ #
171
+ # @return [Disposition] The remote disposition state.
172
+ #
173
+ def remote_state
174
+ Cproton.pn_delivery_remote_state(@impl)
175
+ end
176
+
177
+ # Returns the next delivery on the connection that has pending operations.
178
+ #
179
+ # @return [Delivery, nil] The next delivery, or nil if there are none.
180
+ #
181
+ # @see Connection#work_head
182
+ #
183
+ def work_next
184
+ Delivery.wrap(Cproton.pn_work_next(@impl))
185
+ end
186
+
187
+ # Returns the parent link.
188
+ #
189
+ # @return [Link] The parent link.
190
+ #
191
+ def link
192
+ Link.wrap(Cproton.pn_delivery_link(@impl))
193
+ end
194
+
195
+ # Returns the parent session.
196
+ #
197
+ # @return [Session] The session.
198
+ #
199
+ def session
200
+ self.link.session
201
+ end
202
+
203
+ # Returns the parent connection.
204
+ #
205
+ # @return [Connection] The connection.
206
+ #
207
+ def connection
208
+ self.session.connection
209
+ end
210
+
211
+ # Returns the parent transport.
212
+ #
213
+ # @return [Transport] The transport.
214
+ #
215
+ def transport
216
+ self.connection.transport
217
+ end
218
+
219
+ # @private
220
+ def local_received?
221
+ self.local_state == Disposition::RECEIVED
222
+ end
223
+
224
+ # @private
225
+ def remote_received?
226
+ self.remote_state == Disposition::RECEIVED
227
+ end
228
+
229
+ # @private
230
+ def local_accepted?
231
+ self.local_state == Disposition::ACCEPTED
232
+ end
233
+
234
+ # @private
235
+ def remote_accepted?
236
+ self.remote_state == Disposition::ACCEPTED
237
+ end
238
+
239
+ # @private
240
+ def local_rejected?
241
+ self.local_state == Disposition::REJECTED
242
+ end
243
+
244
+ # @private
245
+ def remote_rejected?
246
+ self.remote_state == Disposition::REJECTED
247
+ end
248
+
249
+ # @private
250
+ def local_released?
251
+ self.local_state == Disposition::RELEASED
252
+ end
253
+
254
+ # @private
255
+ def remote_released?
256
+ self.remote_state == Disposition::RELEASED
257
+ end
258
+
259
+ # @private
260
+ def local_modified?
261
+ self.local_state == Disposition::MODIFIED
262
+ end
263
+
264
+ # @private
265
+ def remote_modified?
266
+ self.remote_state == Disposition::MODIFIED
267
+ end
268
+
269
+ end
270
+
271
+ end
@@ -0,0 +1,158 @@
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
21
+
22
+ # Disposition records the current state and/or final outcome of a transfer.
23
+ #
24
+ # Every delivery contains both a local and a remote disposition. The local
25
+ # disposition holds the local state of the delivery, and the remote
26
+ # disposition holds the *last known* remote state of the delivery.
27
+ #
28
+ class Disposition
29
+
30
+ include Util::Constants
31
+
32
+ # Indicates the delivery was received.
33
+ self.add_constant(:RECEIVED, Cproton::PN_RECEIVED)
34
+ # Indicates the delivery was accepted.
35
+ self.add_constant(:ACCEPTED, Cproton::PN_ACCEPTED)
36
+ # Indicates the delivery was rejected.
37
+ self.add_constant(:REJECTED, Cproton::PN_REJECTED)
38
+ # Indicates the delivery was released.
39
+ self.add_constant(:RELEASED, Cproton::PN_RELEASED)
40
+ # Indicates the delivery was modified.
41
+ self.add_constant(:MODIFIED, Cproton::PN_MODIFIED)
42
+
43
+ # @private
44
+ include Util::Engine
45
+
46
+ attr_reader :impl
47
+
48
+ # @private
49
+ def initialize(impl, local)
50
+ @impl = impl
51
+ @local = local
52
+ @data = nil
53
+ @condition = nil
54
+ @annotations = nil
55
+ end
56
+
57
+ # @private
58
+ include Util::SwigHelper
59
+
60
+ # @private
61
+ PROTON_METHOD_PREFIX = "pn_disposition"
62
+
63
+ # @!attribute section_number
64
+ #
65
+ # @return [Fixnum] The section number of the disposition.
66
+ #
67
+ proton_accessor :section_number
68
+
69
+ # @!attribute section_offset
70
+ #
71
+ # @return [Fixnum] The section offset of the disposition.
72
+ #
73
+ proton_accessor :section_offset
74
+
75
+ # @!attribute failed?
76
+ #
77
+ # @return [Boolean] The failed flag.
78
+ #
79
+ proton_accessor :failed, :is_or_get => :is
80
+
81
+ # @!attribute undeliverable?
82
+ #
83
+ # @return [Boolean] The undeliverable flag.
84
+ #
85
+ proton_accessor :undeliverable, :is_or_get => :is
86
+
87
+ # Sets the data for the disposition.
88
+ #
89
+ # @param data [Codec::Data] The data.
90
+ #
91
+ # @raise [AttributeError] If the disposition is remote.
92
+ #
93
+ def data=(data)
94
+ raise AttributeError.new("data attribute is read-only") unless @local
95
+ @data = data
96
+ end
97
+
98
+ # Returns the data for the disposition.
99
+ #
100
+ # @return [Codec::Data] The data.
101
+ #
102
+ def data
103
+ if @local
104
+ @data
105
+ else
106
+ data_to_object(Cproton.pn_disposition_data(@impl))
107
+ end
108
+ end
109
+
110
+ # Sets the annotations for the disposition.
111
+ #
112
+ # @param annotations [Codec::Data] The annotations.
113
+ #
114
+ # @raise [AttributeError] If the disposition is remote.
115
+ #
116
+ def annotations=(annotations)
117
+ raise AttributeError.new("annotations attribute is read-only") unless @local
118
+ @annotations = annotations
119
+ end
120
+
121
+ # Returns the annotations for the disposition.
122
+ #
123
+ # @return [Codec::Data] The annotations.
124
+ #
125
+ def annotations
126
+ if @local
127
+ @annotations
128
+ else
129
+ data_to_object(Cproton.pn_disposition_annotations(@impl))
130
+ end
131
+ end
132
+
133
+ # Sets the condition for the disposition.
134
+ #
135
+ # @param condition [Codec::Data] The condition.
136
+ #
137
+ # @raise [AttributeError] If the disposition is remote.
138
+ #
139
+ def condition=(condition)
140
+ raise AttributeError.new("condition attribute is read-only") unless @local
141
+ @condition = condition
142
+ end
143
+
144
+ # Returns the condition of the disposition.
145
+ #
146
+ # @return [Codec::Data] The condition of the disposition.
147
+ #
148
+ def condition
149
+ if @local
150
+ @condition
151
+ else
152
+ condition_to_object(Cproton.pn_disposition_condition(@impl))
153
+ end
154
+ end
155
+
156
+ end
157
+
158
+ end
@@ -0,0 +1,140 @@
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
21
+
22
+ # Endpoint is the parent classes for Link and Session.
23
+ #
24
+ # It provides a namespace for constant values that relate to the current
25
+ # state of both links and sessions.
26
+ #
27
+ # @example
28
+ #
29
+ # conn = Qpid::Proton::Connection.new
30
+ # puts "Local connection flags : #{conn.state || Qpid::Proton::Endpoint::LOCAL_MASK}"
31
+ # puts "Remote connection flags: #{conn.state || Qpid::Proton::Endpoint::REMOTE_MASK}"
32
+ #
33
+ class Endpoint
34
+
35
+ # The local connection is uninitialized.
36
+ LOCAL_UNINIT = Cproton::PN_LOCAL_UNINIT
37
+ # The local connection is active.
38
+ LOCAL_ACTIVE = Cproton::PN_LOCAL_ACTIVE
39
+ # The local connection is closed.
40
+ LOCAL_CLOSED = Cproton::PN_LOCAL_CLOSED
41
+
42
+ # The remote connection is unitialized.
43
+ REMOTE_UNINIT = Cproton::PN_REMOTE_UNINIT
44
+ # The remote connection is active.
45
+ REMOTE_ACTIVE = Cproton::PN_REMOTE_ACTIVE
46
+ # The remote connection is closed.
47
+ REMOTE_CLOSED = Cproton::PN_REMOTE_CLOSED
48
+
49
+ # Bitmask for the local-only flags.
50
+ LOCAL_MASK = Cproton::PN_LOCAL_UNINIT |
51
+ Cproton::PN_LOCAL_ACTIVE |
52
+ Cproton::PN_LOCAL_CLOSED
53
+
54
+ # Bitmask for the remote-only flags.
55
+ REMOTE_MASK = Cproton::PN_REMOTE_UNINIT |
56
+ Cproton::PN_REMOTE_ACTIVE |
57
+ Cproton::PN_REMOTE_CLOSED
58
+
59
+ # @private
60
+ include Util::Engine
61
+
62
+ # @private
63
+ def initialize
64
+ @condition = nil
65
+ end
66
+
67
+ # @private
68
+ def _update_condition
69
+ object_to_condition(@condition, self._local_condition)
70
+ end
71
+
72
+ # @private
73
+ def remote_condition
74
+ condition_to_object(self._remote_condition)
75
+ end
76
+
77
+ # Return the transport associated with this endpoint.
78
+ #
79
+ # @return [Transport] The transport.
80
+ #
81
+ def transport
82
+ self.connection.transport
83
+ end
84
+
85
+ def local_uninit?
86
+ check_state(LOCAL_UNINIT)
87
+ end
88
+
89
+ def local_active?
90
+ check_state(LOCAL_ACTIVE)
91
+ end
92
+
93
+ def local_closed?
94
+ check_state(LOCAL_CLOSED)
95
+ end
96
+
97
+ def remote_uninit?
98
+ check_state(REMOTE_UNINIT)
99
+ end
100
+
101
+ def remote_active?
102
+ check_state(REMOTE_ACTIVE)
103
+ end
104
+
105
+ def remote_closed?
106
+ check_state(REMOTE_CLOSED)
107
+ end
108
+
109
+ def check_state(state_mask)
110
+ !(self.state & state_mask).zero?
111
+ end
112
+
113
+ def handler
114
+ reactor = Qpid::Proton::Reactor::Reactor.wrap(Cproton.pn_object_reactor(@impl))
115
+ if reactor.nil?
116
+ on_error = nil
117
+ else
118
+ on_error = reactor.method(:on_error)
119
+ end
120
+ record = self.attachments
121
+ puts "record=#{record}"
122
+ WrappedHandler.wrap(Cproton.pn_record_get_handler(record), on_error)
123
+ end
124
+
125
+ def handler=(handler)
126
+ reactor = Qpid::Proton::Reactor::Reactor.wrap(Cproton.pn_object_reactor(@impl))
127
+ if reactor.nil?
128
+ on_error = nil
129
+ else
130
+ on_error = reactor.method(:on_error)
131
+ end
132
+ impl = chandler(handler, on_error)
133
+ record = self.attachments
134
+ Cproton.pn_record_set_handler(record, impl)
135
+ Cproton.pn_decref(impl)
136
+ end
137
+
138
+ end
139
+
140
+ end