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,95 @@
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
+ # The receiving endpoint.
23
+ #
24
+ # @see Sender
25
+ #
26
+ class Receiver < Link
27
+
28
+ # @private
29
+ include Util::SwigHelper
30
+
31
+ # @private
32
+ PROTON_METHOD_PREFIX = "pn_link"
33
+
34
+ # @!attribute drain
35
+ #
36
+ # The drain mode.
37
+ #
38
+ # If a receiver is in drain mode, then the sending endpoint of a link must
39
+ # immediately use up all available credit on the link. If this is not
40
+ # possible, the excess credit must be returned by invoking #drained.
41
+ #
42
+ # Only the receiving endpoint can set the drain mode.
43
+ #
44
+ # @return [Boolean] True if drain mode is set.
45
+ #
46
+ proton_accessor :drain
47
+
48
+ # @!attribute [r] draining?
49
+ #
50
+ # Returns if a link is currently draining.
51
+ #
52
+ # A link is defined to be draining when drain mode is set to true and
53
+ # the sender still has excess credit.
54
+ #
55
+ # @return [Boolean] True if the receiver is currently draining.
56
+ #
57
+ proton_caller :draining?
58
+
59
+ # Grants credit for incoming deliveries.
60
+ #
61
+ # @param n [Fixnum] The amount to increment the link credit.
62
+ #
63
+ def flow(n)
64
+ Cproton.pn_link_flow(@impl, n)
65
+ end
66
+
67
+ # Allows receiving up to the specified limit of data from the remote
68
+ # endpoint.
69
+ #
70
+ # Note that large messages can be streamed across the network, so just
71
+ # because there is no data to read does not imply the message is complete.
72
+ #
73
+ # To ensure the entirety of the message data has been read, either call
74
+ # #receive until nil is returned, or verify that #partial? is false and
75
+ # Delivery#pending is 0.
76
+ #
77
+ # @param limit [Fixnum] The maximum bytes to receive.
78
+ #
79
+ # @return [Fixnum, nil] The number of bytes received, or nil if the end of
80
+ # the stream was reached.t
81
+ #
82
+ # @see Deliver#pending To see how much buffer space is needed.
83
+ #
84
+ # @raise [LinkError] If an error occurs.
85
+ #
86
+ def receive(limit)
87
+ (n, bytes) = Cproton.pn_link_recv(@impl, limit)
88
+ return nil if n == Qpid::Proton::Error::EOS
89
+ raise LinkError.new("[#{n}]: #{Cproton.pn_link_error(@impl)}") if n < 0
90
+ return bytes
91
+ end
92
+
93
+ end
94
+
95
+ end
data/lib/core/sasl.rb ADDED
@@ -0,0 +1,94 @@
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
+ # The SASL layer is responsible for establishing an authenticated and/or
23
+ # encrypted tunnel over which AMQP frames are passed between peers.
24
+ #
25
+ # The peer acting as the SASL client must provide authentication
26
+ # credentials.
27
+ #
28
+ # The peer acting as the SASL server must provide authentication against the
29
+ # received credentials.
30
+ #
31
+ # @example
32
+ # # SCENARIO: the remote endpoint has not initialized their connection
33
+ # # then the local endpoint, acting as a SASL server, decides
34
+ # # to allow an anonymous connection.
35
+ # #
36
+ # # The SASL layer locally assumes the role of server and then
37
+ # # enables anonymous authentication for the remote endpoint.
38
+ # #
39
+ # sasl = @transport.sasl
40
+ # sasl.server
41
+ # sasl.mechanisms("ANONYMOUS")
42
+ # sasl.done(Qpid::Proton::SASL::OK)
43
+ #
44
+ class SASL
45
+
46
+ # Negotation has not completed.
47
+ NONE = Cproton::PN_SASL_NONE
48
+ # Authentication succeeded.
49
+ OK = Cproton::PN_SASL_OK
50
+ # Authentication failed due to bad credentials.
51
+ AUTH = Cproton::PN_SASL_AUTH
52
+
53
+ # Constructs a new instance for the given transport.
54
+ #
55
+ # @param transport [Transport] The transport.
56
+ #
57
+ # @private A SASL should be fetched only from its Transport
58
+ #
59
+ def initialize(transport)
60
+ @impl = Cproton.pn_sasl(transport.impl)
61
+ end
62
+
63
+ # Sets the acceptable SASL mechanisms.
64
+ #
65
+ # @param mechanisms [String] The space-delimited set of mechanisms.
66
+ #
67
+ # @example Use anonymous SASL authentication.
68
+ # @sasl.mechanisms("GSSAPI CRAM-MD5 PLAIN")
69
+ #
70
+ def mechanisms(mechanisms)
71
+ Cproton.pn_sasl_mechanisms(@impl, mechanisms)
72
+ end
73
+
74
+ # Returns the outcome of the SASL negotiation.
75
+ #
76
+ # @return [Fixnum] The outcome.
77
+ #
78
+ def outcome
79
+ outcome = Cprotn.pn_sasl_outcome(@impl)
80
+ return nil if outcome == NONE
81
+ outcome
82
+ end
83
+
84
+ # Set the condition of the SASL negotiation.
85
+ #
86
+ # @param outcome [Fixnum] The outcome.
87
+ #
88
+ def done(outcome)
89
+ Cproton.pn_sasl_done(@impl, outcome)
90
+ end
91
+
92
+ end
93
+
94
+ end
@@ -0,0 +1,130 @@
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
+ # Selectable enables accessing the underlying file descriptors
23
+ # for Messenger.
24
+ #
25
+ # @private
26
+ class Selectable
27
+
28
+ # @private
29
+ include Util::SwigHelper
30
+
31
+ # @private
32
+ PROTON_METHOD_PREFIX = "pn_selectable"
33
+
34
+ # Returns the underlying file descriptor.
35
+ #
36
+ # This can be used in conjunction with the IO class.
37
+ #
38
+ def fileno
39
+ Cproton.pn_selectable_get_fd(@impl)
40
+ end
41
+
42
+ proton_reader :reading, :is_or_get => :is
43
+
44
+ proton_reader :writing, :is_or_get => :is
45
+
46
+ proton_caller :readable
47
+
48
+ proton_caller :writable
49
+
50
+ proton_caller :expired
51
+
52
+ proton_accessor :registered, :is_or_get => :is
53
+
54
+ proton_accessor :terminal, :is_or_get => :is
55
+
56
+ proton_caller :terminate
57
+
58
+ proton_caller :release
59
+
60
+ # @private
61
+ def self.wrap(impl)
62
+ return nil if impl.nil?
63
+
64
+ self.fetch_instance(impl, :pn_selectable_attachments) || Selectable.new(impl)
65
+ end
66
+
67
+ # @private
68
+ include Util::Wrapper
69
+
70
+ # @private
71
+ def initialize(impl)
72
+ @impl = impl
73
+ self.class.store_instance(self, :pn_selectable_attachments)
74
+ end
75
+
76
+ private
77
+
78
+ DEFAULT = Object.new
79
+
80
+ public
81
+
82
+ def fileno(fd = DEFAULT)
83
+ if fd == DEFAULT
84
+ Cproton.pn_selectable_get_fd(@impl)
85
+ elsif fd.nil?
86
+ Cproton.pn_selectable_set_fd(@impl, Cproton::PN_INVALID_SOCKET)
87
+ else
88
+ Cproton.pn_selectable_set_fd(@impl, fd)
89
+ end
90
+ end
91
+
92
+ def reading=(reading)
93
+ if reading.nil?
94
+ reading = false
95
+ elsif reading == "0"
96
+ reading = false
97
+ else
98
+ reading = true
99
+ end
100
+ Cproton.pn_selectable_set_reading(@impl, reading ? true : false)
101
+ end
102
+
103
+ def writing=(writing)
104
+ if writing.nil?
105
+ writing = false
106
+ elsif writing == "0"
107
+ writing = false
108
+ else
109
+ writing = true
110
+ end
111
+ Cproton.pn_selectable_set_writing(@impl, writing ? true : false)
112
+ end
113
+
114
+ def deadline
115
+ tstamp = Cproton.pn_selectable_get_deadline(@impl)
116
+ return nil if tstamp.nil?
117
+ mills_to_sec(tstamp)
118
+ end
119
+
120
+ def deadline=(deadline)
121
+ Cproton.pn_selectable_set_deadline(sec_to_millis(deadline))
122
+ end
123
+
124
+ def to_io
125
+ @io ||= IO.new(fileno)
126
+ end
127
+
128
+ end
129
+
130
+ end
@@ -0,0 +1,76 @@
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
+ # The sending endpoint.
23
+ #
24
+ # @see Receiver
25
+ #
26
+ class Sender < Link
27
+
28
+ # @private
29
+ include Util::ErrorHandler
30
+
31
+ # @private
32
+ can_raise_error :stream, :error_class => Qpid::Proton::LinkError
33
+
34
+ # Signals the availability of deliveries.
35
+ #
36
+ # @param n [Fixnum] The number of deliveries potentially available.
37
+ #
38
+ def offered(n)
39
+ Cproton.pn_link_offered(@impl, n)
40
+ end
41
+
42
+ # Sends the specified data to the remote endpoint.
43
+ #
44
+ # @param object [Object] The content to send.
45
+ # @param tag [Object] The tag
46
+ #
47
+ # @return [Fixnum] The number of bytes sent.
48
+ #
49
+ def send(object, tag = nil)
50
+ if object.respond_to? :proton_send
51
+ object.proton_send(self, tag)
52
+ else
53
+ stream(object)
54
+ end
55
+ end
56
+
57
+ # Send the specified bytes as part of the current delivery.
58
+ #
59
+ # @param bytes [Array] The bytes to send.
60
+ #
61
+ # @return n [Fixnum] The number of bytes sent.
62
+ #
63
+ def stream(bytes)
64
+ Cproton.pn_link_send(@impl, bytes)
65
+ end
66
+
67
+ def delivery_tag
68
+ @tag_count ||= 0
69
+ result = @tag_count.succ
70
+ @tag_count = result
71
+ return "#{result}"
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,163 @@
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 session is the parent for senders and receivers.
23
+ #
24
+ # A Session has a single parent Qpid::Proton::Connection instance.
25
+ #
26
+ class Session < Endpoint
27
+
28
+ # @private
29
+ include Util::Wrapper
30
+
31
+ # @private
32
+ include Util::SwigHelper
33
+
34
+ # @private
35
+ PROTON_METHOD_PREFIX = "pn_session"
36
+
37
+ # @!attribute incoming_capacity
38
+ #
39
+ # The incoming capacity of a session determines how much incoming message
40
+ # data the session will buffer. Note that if this value is less than the
41
+ # negotatied frame size of the transport, it will be rounded up to one full
42
+ # frame.
43
+ #
44
+ # @return [Fixnum] The incoing capacity of the session, measured in bytes.
45
+ #
46
+ proton_accessor :incoming_capacity
47
+
48
+ # @private
49
+ proton_reader :attachments
50
+
51
+ # @!attribute [r] outgoing_bytes
52
+ #
53
+ # @return [Fixnum] The number of outgoing bytes currently being buffered.
54
+ #
55
+ proton_caller :outgoing_bytes
56
+
57
+ # @!attribute [r] incoming_bytes
58
+ #
59
+ # @return [Fixnum] The number of incomign bytes currently being buffered.
60
+ #
61
+ proton_caller :incoming_bytes
62
+
63
+ # @!method open
64
+ # Opens the session.
65
+ #
66
+ # Once this operaton has completed, the state flag is updated.
67
+ #
68
+ # @see LOCAL_ACTIVE
69
+ #
70
+ proton_caller :open
71
+
72
+ # @!attribute [r] state
73
+ #
74
+ # @return [Fixnum] The endpoint state.
75
+ #
76
+ proton_caller :state
77
+
78
+ # @private
79
+ def self.wrap(impl)
80
+ return nil if impl.nil?
81
+ self.fetch_instance(impl, :pn_session_attachments) || Session.new(impl)
82
+ end
83
+
84
+ # @private
85
+ def initialize(impl)
86
+ @impl = impl
87
+ self.class.store_instance(self, :pn_session_attachments)
88
+ end
89
+
90
+ # Closed the session.
91
+ #
92
+ # Once this operation has completed, the state flag will be set. This may be
93
+ # called without calling #open, in which case it is the equivalence of
94
+ # calling #open and then close immediately.
95
+ #
96
+ def close
97
+ self._update_condition
98
+ Cproton.pn_session_close(@impl)
99
+ end
100
+
101
+ # Retrieves the next session from a given connection that matches the
102
+ # specified state mask.
103
+ #
104
+ # When uses with Connection#session_head an application can access all of
105
+ # the session son the connection that match the given state.
106
+ #
107
+ # @param state_mask [Fixnum] The state mask to match.
108
+ #
109
+ # @return [Session, nil] The next session if one matches, or nil.
110
+ #
111
+ def next(state_mask)
112
+ Session.wrap(Cproton.pn_session_next(@impl, state_mask))
113
+ end
114
+
115
+ # Returns the parent connection.
116
+ #
117
+ # @return [Connection] The connection.
118
+ #
119
+ def connection
120
+ Connection.wrap(Cproton.pn_session_connection(@impl))
121
+ end
122
+
123
+ # Constructs a new sender.
124
+ #
125
+ # Each sender between two AMQP containers must be uniquely named. Note that
126
+ # this uniqueness cannot be enforced at the library level, so some
127
+ # consideration should be taken in choosing link names.
128
+ #
129
+ # @param name [String] The link name.
130
+ #
131
+ # @return [Sender, nil] The sender, or nil if an error occurred.
132
+ #
133
+ def sender(name)
134
+ Sender.new(Cproton.pn_sender(@impl, name))
135
+ end
136
+
137
+ # Constructs a new receiver.
138
+ #
139
+ # Each receiver between two AMQP containers must be uniquely named. Note
140
+ # that this uniqueness cannot be enforced at the library level, so some
141
+ # consideration should be taken in choosing link names.
142
+ #
143
+ # @param name [String] The link name.
144
+ #
145
+ # @return [Receiver, nil] The receiver, or nil if an error occurred.
146
+ #
147
+ def receiver(name)
148
+ Receiver.new(Cproton.pn_receiver(@impl, name))
149
+ end
150
+
151
+ # @private
152
+ def _local_condition
153
+ Cproton.pn_session_condition(@impl)
154
+ end
155
+
156
+ # @private
157
+ def _remote_condition # :nodoc:
158
+ Cproton.pn_session_remote_condition(@impl)
159
+ end
160
+
161
+ end
162
+
163
+ end