qpid_proton 0.18.1 → 0.19.0

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 (81) hide show
  1. checksums.yaml +4 -4
  2. data/ext/cproton/cproton.c +863 -75
  3. data/lib/codec/data.rb +589 -815
  4. data/lib/codec/mapping.rb +142 -126
  5. data/lib/core/condition.rb +89 -0
  6. data/lib/core/connection.rb +188 -228
  7. data/lib/core/connection_driver.rb +202 -0
  8. data/lib/core/container.rb +366 -0
  9. data/lib/core/delivery.rb +76 -251
  10. data/lib/core/disposition.rb +21 -35
  11. data/lib/core/endpoint.rb +21 -53
  12. data/lib/core/event.rb +156 -0
  13. data/lib/core/exceptions.rb +109 -106
  14. data/lib/core/link.rb +24 -49
  15. data/lib/core/listener.rb +82 -0
  16. data/lib/core/message.rb +59 -155
  17. data/lib/core/messaging_handler.rb +190 -0
  18. data/lib/core/receiver.rb +38 -7
  19. data/lib/core/sasl.rb +43 -46
  20. data/lib/core/sender.rb +55 -32
  21. data/lib/core/session.rb +58 -58
  22. data/lib/core/ssl.rb +5 -13
  23. data/lib/core/ssl_details.rb +1 -2
  24. data/lib/core/ssl_domain.rb +5 -8
  25. data/lib/core/terminus.rb +62 -30
  26. data/lib/core/tracker.rb +45 -0
  27. data/lib/core/transfer.rb +121 -0
  28. data/lib/core/transport.rb +62 -97
  29. data/lib/core/uri.rb +73 -0
  30. data/lib/core/url.rb +11 -7
  31. data/lib/handler/adapter.rb +78 -0
  32. data/lib/handler/messaging_adapter.rb +127 -0
  33. data/lib/handler/messaging_handler.rb +128 -178
  34. data/lib/handler/reactor_messaging_adapter.rb +158 -0
  35. data/lib/messenger/messenger.rb +9 -8
  36. data/lib/messenger/subscription.rb +1 -2
  37. data/lib/messenger/tracker.rb +1 -2
  38. data/lib/messenger/tracker_status.rb +1 -2
  39. data/lib/qpid_proton.rb +36 -66
  40. data/lib/reactor/container.rb +40 -234
  41. data/lib/types/array.rb +73 -130
  42. data/lib/types/described.rb +2 -44
  43. data/lib/types/hash.rb +19 -56
  44. data/lib/types/strings.rb +1 -2
  45. data/lib/types/type.rb +68 -0
  46. data/lib/util/{handler.rb → deprecation.rb} +22 -15
  47. data/lib/util/error_handler.rb +4 -25
  48. data/lib/util/timeout.rb +1 -2
  49. data/lib/util/version.rb +1 -2
  50. data/lib/util/wrapper.rb +58 -38
  51. metadata +16 -33
  52. data/lib/core/base_handler.rb +0 -31
  53. data/lib/core/selectable.rb +0 -130
  54. data/lib/event/collector.rb +0 -148
  55. data/lib/event/event.rb +0 -318
  56. data/lib/event/event_base.rb +0 -91
  57. data/lib/event/event_type.rb +0 -71
  58. data/lib/handler/acking.rb +0 -70
  59. data/lib/handler/c_adaptor.rb +0 -47
  60. data/lib/handler/c_flow_controller.rb +0 -33
  61. data/lib/handler/endpoint_state_handler.rb +0 -217
  62. data/lib/handler/incoming_message_handler.rb +0 -74
  63. data/lib/handler/outgoing_message_handler.rb +0 -100
  64. data/lib/handler/wrapped_handler.rb +0 -76
  65. data/lib/reactor/acceptor.rb +0 -41
  66. data/lib/reactor/backoff.rb +0 -41
  67. data/lib/reactor/connector.rb +0 -115
  68. data/lib/reactor/global_overrides.rb +0 -44
  69. data/lib/reactor/link_option.rb +0 -90
  70. data/lib/reactor/reactor.rb +0 -196
  71. data/lib/reactor/session_per_connection.rb +0 -45
  72. data/lib/reactor/ssl_config.rb +0 -41
  73. data/lib/reactor/task.rb +0 -39
  74. data/lib/reactor/urls.rb +0 -45
  75. data/lib/util/class_wrapper.rb +0 -54
  76. data/lib/util/condition.rb +0 -47
  77. data/lib/util/constants.rb +0 -85
  78. data/lib/util/engine.rb +0 -82
  79. data/lib/util/reactor.rb +0 -32
  80. data/lib/util/swig_helper.rb +0 -114
  81. data/lib/util/uuid.rb +0 -32
data/lib/core/endpoint.rb CHANGED
@@ -1,4 +1,3 @@
1
- #--
2
1
  # Licensed to the Apache Software Foundation (ASF) under one
3
2
  # or more contributor license agreements. See the NOTICE file
4
3
  # distributed with this work for additional information
@@ -15,7 +14,7 @@
15
14
  # KIND, either express or implied. See the License for the
16
15
  # specific language governing permissions and limitations
17
16
  # under the License.
18
- #++
17
+
19
18
 
20
19
  module Qpid::Proton
21
20
 
@@ -31,6 +30,7 @@ module Qpid::Proton
31
30
  # puts "Remote connection flags: #{conn.state || Qpid::Proton::Endpoint::REMOTE_MASK}"
32
31
  #
33
32
  class Endpoint
33
+ include Util::Deprecation
34
34
 
35
35
  # The local connection is uninitialized.
36
36
  LOCAL_UNINIT = Cproton::PN_LOCAL_UNINIT
@@ -47,32 +47,17 @@ module Qpid::Proton
47
47
  REMOTE_CLOSED = Cproton::PN_REMOTE_CLOSED
48
48
 
49
49
  # Bitmask for the local-only flags.
50
- LOCAL_MASK = Cproton::PN_LOCAL_UNINIT |
51
- Cproton::PN_LOCAL_ACTIVE |
52
- Cproton::PN_LOCAL_CLOSED
50
+ LOCAL_MASK = Cproton::PN_LOCAL_UNINIT | Cproton::PN_LOCAL_ACTIVE | Cproton::PN_LOCAL_CLOSED
53
51
 
54
52
  # Bitmask for the remote-only flags.
55
- REMOTE_MASK = Cproton::PN_REMOTE_UNINIT |
56
- Cproton::PN_REMOTE_ACTIVE |
57
- Cproton::PN_REMOTE_CLOSED
53
+ REMOTE_MASK = Cproton::PN_REMOTE_UNINIT | Cproton::PN_REMOTE_ACTIVE | Cproton::PN_REMOTE_CLOSED
58
54
 
59
55
  # @private
60
- include Util::Engine
61
-
56
+ def condition; remote_condition || local_condition; end
62
57
  # @private
63
- def initialize
64
- @condition = nil
65
- end
66
-
58
+ def remote_condition; Condition.convert(_remote_condition); end
67
59
  # @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
60
+ def local_condition; Condition.convert(_local_condition); end
76
61
 
77
62
  # Return the transport associated with this endpoint.
78
63
  #
@@ -82,11 +67,21 @@ module Qpid::Proton
82
67
  self.connection.transport
83
68
  end
84
69
 
70
+ # @private
71
+ # @return [Bool] true if {#state} has all the bits of `mask` set
72
+ def check_state(mask) (self.state & mask) == mask; end
73
+
74
+ # @return [Bool] true if endpoint has sent and received a CLOSE frame
75
+ def closed?() check_state(LOCAL_CLOSED | REMOTE_CLOSED); end
76
+
77
+ # @return [Bool] true if endpoint has sent and received an OPEN frame
78
+ def open?() check_state(LOCAL_ACTIVE | REMOTE_ACTIVE); end
79
+
85
80
  def local_uninit?
86
81
  check_state(LOCAL_UNINIT)
87
82
  end
88
83
 
89
- def local_active?
84
+ def local_open?
90
85
  check_state(LOCAL_ACTIVE)
91
86
  end
92
87
 
@@ -98,7 +93,7 @@ module Qpid::Proton
98
93
  check_state(REMOTE_UNINIT)
99
94
  end
100
95
 
101
- def remote_active?
96
+ def remote_open?
102
97
  check_state(REMOTE_ACTIVE)
103
98
  end
104
99
 
@@ -106,35 +101,8 @@ module Qpid::Proton
106
101
  check_state(REMOTE_CLOSED)
107
102
  end
108
103
 
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
104
+ alias local_active? local_open?
105
+ alias remote_active? remote_open?
137
106
 
138
107
  end
139
-
140
108
  end
data/lib/core/event.rb ADDED
@@ -0,0 +1,156 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+
19
+ module Qpid::Proton
20
+
21
+ # @deprecated Only used with the deprecated {Handler::MessagingHandler} API.
22
+ class Event
23
+ private
24
+ include Util::Deprecation
25
+
26
+ PROTON_METHOD_PREFIX = "pn_disposition"
27
+ include Util::Wrapper
28
+
29
+ EVENT_TYPE_NAMES = [:PN_EVENT_NONE,
30
+ :PN_CONNECTION_INIT,
31
+ :PN_CONNECTION_BOUND,
32
+ :PN_CONNECTION_UNBOUND,
33
+ :PN_CONNECTION_LOCAL_OPEN,
34
+ :PN_CONNECTION_REMOTE_OPEN,
35
+ :PN_CONNECTION_LOCAL_CLOSE,
36
+ :PN_CONNECTION_REMOTE_CLOSE,
37
+ :PN_CONNECTION_FINAL,
38
+ :PN_SESSION_INIT,
39
+ :PN_SESSION_LOCAL_OPEN,
40
+ :PN_SESSION_REMOTE_OPEN,
41
+ :PN_SESSION_LOCAL_CLOSE,
42
+ :PN_SESSION_REMOTE_CLOSE,
43
+ :PN_SESSION_FINAL,
44
+ :PN_LINK_INIT,
45
+ :PN_LINK_LOCAL_OPEN,
46
+ :PN_LINK_REMOTE_OPEN,
47
+ :PN_LINK_LOCAL_CLOSE,
48
+ :PN_LINK_REMOTE_CLOSE,
49
+ :PN_LINK_LOCAL_DETACH,
50
+ :PN_LINK_REMOTE_DETACH,
51
+ :PN_LINK_FLOW,
52
+ :PN_LINK_FINAL,
53
+ :PN_DELIVERY,
54
+ :PN_TRANSPORT,
55
+ :PN_TRANSPORT_AUTHENTICATED,
56
+ :PN_TRANSPORT_ERROR,
57
+ :PN_TRANSPORT_HEAD_CLOSED,
58
+ :PN_TRANSPORT_TAIL_CLOSED,
59
+ :PN_TRANSPORT_CLOSED]
60
+
61
+ TYPE_METHODS = EVENT_TYPE_NAMES.each_with_object({}) do |n, h|
62
+ type = Cproton.const_get(n)
63
+ h[type] = "on_#{Cproton.pn_event_type_name(type)[3..-1]}".downcase.to_sym
64
+ end
65
+
66
+ # Use Event.new(impl) to wrap a C event, or Event.new(nil, method, context)
67
+ # to create a pure-ruby event.
68
+ def initialize(impl, method=nil, context=nil)
69
+ @impl, @method, @context = impl, method, context
70
+ @method ||= TYPE_METHODS[Cproton.pn_event_type(@impl)] if @impl
71
+ end
72
+
73
+ # Get the context if it is_a?(clazz), else call method on the context
74
+ def get(clazz, method=nil)
75
+ (ctx = context).is_a?(clazz) ? ctx : ctx.__send__(method) rescue nil
76
+ end
77
+
78
+ def _context
79
+ x = Cproton.pn_event_context(@impl)
80
+ case Cproton.pn_class_id(Cproton.pn_event_class(@impl))
81
+ when Cproton::CID_pn_transport then Transport.wrap(Cproton.pn_cast_pn_transport(x))
82
+ when Cproton::CID_pn_connection then Connection.wrap(Cproton.pn_cast_pn_connection(x))
83
+ when Cproton::CID_pn_session then Session.wrap(Cproton.pn_cast_pn_session(x))
84
+ when Cproton::CID_pn_link then Link.wrap(Cproton.pn_cast_pn_link(x))
85
+ when Cproton::CID_pn_delivery then Delivery.wrap(Cproton.pn_cast_pn_delivery(x))
86
+ end
87
+ end
88
+
89
+ public
90
+
91
+ # Call handler.{#method}(self) if handler.respond_to? {#method}
92
+ # @return [Boolean] true if handler responded to the method, nil if not.
93
+ def dispatch(handler)
94
+ (handler.__send__(@method, self); true) if handler.respond_to? @method
95
+ end
96
+
97
+ # @return [Symbol] method name that this event will call in {#dispatch}
98
+ attr_accessor :method
99
+
100
+ alias type method
101
+
102
+ # @return [Object] the event context object
103
+ def context; return @context ||= _context; end
104
+
105
+ # @return [Container, nil] container for this event
106
+ def container() @container ||= get(Container, :container); end
107
+
108
+ # @return [Transport, nil] transport for this event
109
+ def transport() @transport ||= get(Transport, :transport); end
110
+
111
+ # @return [Connection, nil] the connection for this event
112
+ def connection() @connection ||= get(Connection, :connection); end
113
+
114
+ # @return [Session, nil] session for this event
115
+ def session() @session ||= get(Session, :session); end
116
+
117
+ # @return [Link, nil] link for this event
118
+ def link() @link ||= get(Link, :link); end
119
+
120
+ # @return [Sender, nil] sender associated with this event
121
+ def sender() link if link && link.sender?; end
122
+
123
+ # @return [Receiver, nil] receiver associated with this event
124
+ def receiver() link if link && link.receiver?; end
125
+
126
+ # @return [Delivery, nil] delivery for this event
127
+ def delivery()
128
+ @delivery ||= case context
129
+ when Delivery then @delivery = @context
130
+ # deprecated: for backwards compat allow a Tracker to be treated as a Delivery
131
+ when Tracker then @delivery = Delivery.new(context.impl)
132
+ end
133
+ end
134
+
135
+ # @return [Tracker, nil] delivery for this event
136
+ def tracker() @tracker ||= get(Tracker); end
137
+
138
+ # @return [Message, nil] message for this event
139
+ def message() @message ||= delivery.message if delivery; end
140
+
141
+ def to_s() "#{self.class}(#{method}, #{context})"; end
142
+ def inspect() "#{self.class}(#{method.inspect}, #{context.inspect})"; end
143
+
144
+ # @return [Condition] Error condition associated with this event or nil if none.
145
+ def condition
146
+ (context.remote_condition if context.respond_to? :remote_condition) ||
147
+ (context.condition if context.respond_to? :condition)
148
+ end
149
+
150
+ # @deprecated use {#container}
151
+ deprecated_alias :reactor, :container
152
+
153
+ # @private
154
+ Event = self
155
+ end
156
+ end
@@ -1,4 +1,3 @@
1
- #--
2
1
  # Licensed to the Apache Software Foundation (ASF) under one
3
2
  # or more contributor license agreements. See the NOTICE file
4
3
  # distributed with this work for additional information
@@ -15,112 +14,116 @@
15
14
  # KIND, either express or implied. See the License for the
16
15
  # specific language governing permissions and limitations
17
16
  # under the License.
18
- #++
19
-
20
- module Qpid
21
-
22
- module Proton
23
-
24
- module Error
25
-
26
- NONE = 0
27
- EOS = Cproton::PN_EOS
28
- ERROR = Cproton::PN_ERR
29
- OVERFLOW = Cproton::PN_OVERFLOW
30
- UNDERFLOW = Cproton::PN_UNDERFLOW
31
- STATE = Cproton::PN_STATE_ERR
32
- ARGUMENT = Cproton::PN_ARG_ERR
33
- TIMEOUT = Cproton::PN_TIMEOUT
34
- INTERRUPTED = Cproton::PN_INTR
35
- INPROGRESS = Cproton::PN_INPROGRESS
36
-
37
- end
38
-
39
- # Represents a generic error at the messaging level.
40
- #
41
- class ProtonError < RuntimeError
42
- end
43
-
44
- # Represents an end-of-stream error while messaging.
45
- #
46
- class EOSError < ProtonError
47
- end
48
-
49
- # Represents a data overflow exception while messaging.
50
- #
51
- class OverflowError < ProtonError
52
- end
53
-
54
- # Represents a data underflow exception while messaging.
55
- #
56
- class UnderflowError < ProtonError
57
- end
58
-
59
- # Represents an invalid, missing or illegal argument while messaging.
60
- #
61
- class ArgumentError < ProtonError
62
- end
63
-
64
- # Represents that the client has got into an unexpected state during
65
- # messaging.
66
- #
67
- class StateError < ProtonError
68
- end
69
-
70
- # Represents a timeout during messaging.
71
- #
72
- class TimeoutError < ProtonError
73
- end
74
-
75
- # Represents an interrupting during a blocking I/O operation.
76
- #
77
- class InterruptedError < ProtonError
78
- end
79
-
80
- class InProgressError < ProtonError
81
- end
82
-
83
- # Raised by instances of Transport.
84
- #
85
- class TransportError < ProtonError
86
- end
87
-
88
- # Raised by instances of SASL
89
- #
90
- class SASLError < TransportError
91
- end
92
-
93
- # Raised by Session.
94
- #
95
- class SessionError < ProtonError
96
- end
97
-
98
- # Raised when an attempt is made to change an attribute that is read-only.
99
- #
100
- class AttributeError < ProtonError
101
- end
102
-
103
- # Raised by link components.
104
- #
105
- class LinkError < ProtonError
106
- end
107
-
108
- class SSLError < TransportError
109
- end
110
-
111
- class SSLUnavailableError < SSLError
112
- end
113
-
114
- # Raised when a message is rejected.
115
- #
116
- class Reject < ProtonError
117
- end
118
-
119
- # Raised when a message is released.
120
- #
121
- class Release < ProtonError
122
- end
123
17
 
18
+
19
+ module Qpid::Proton
20
+
21
+ # @private
22
+ module Error
23
+ NONE = 0
24
+ EOS = Cproton::PN_EOS
25
+ ERROR = Cproton::PN_ERR
26
+ OVERFLOW = Cproton::PN_OVERFLOW
27
+ UNDERFLOW = Cproton::PN_UNDERFLOW
28
+ STATE = Cproton::PN_STATE_ERR
29
+ ARGUMENT = Cproton::PN_ARG_ERR
30
+ TIMEOUT = Cproton::PN_TIMEOUT
31
+ INTERRUPTED = Cproton::PN_INTR
32
+ INPROGRESS = Cproton::PN_INPROGRESS
33
+ end
34
+
35
+ # Represents a generic error at the messaging level.
36
+ #
37
+ class ProtonError < RuntimeError
38
+ end
39
+
40
+ # Represents an end-of-stream error while messaging.
41
+ #
42
+ class EOSError < ProtonError
43
+ end
44
+
45
+ # Represents a data overflow exception while messaging.
46
+ #
47
+ class OverflowError < ProtonError
48
+ end
49
+
50
+ # Represents a data underflow exception while messaging.
51
+ #
52
+ class UnderflowError < ProtonError
53
+ end
54
+
55
+ # Represents an invalid, missing or illegal argument while messaging.
56
+ #
57
+ class ArgumentError < ProtonError
58
+ end
59
+
60
+ # Represents that the client has got into an unexpected state during
61
+ # messaging.
62
+ #
63
+ class StateError < ProtonError
64
+ end
65
+
66
+ # Represents a timeout during messaging.
67
+ #
68
+ class TimeoutError < ProtonError
69
+ end
70
+
71
+ # Represents an interrupting during a blocking I/O operation.
72
+ #
73
+ class InterruptedError < ProtonError
74
+ end
75
+
76
+ class InProgressError < ProtonError
77
+ end
78
+
79
+ # Raised by instances of Transport.
80
+ #
81
+ class TransportError < ProtonError
82
+ end
83
+
84
+ # Raised by instances of SASL
85
+ #
86
+ class SASLError < TransportError
87
+ end
88
+
89
+ # Raised by Session.
90
+ #
91
+ class SessionError < ProtonError
92
+ end
93
+
94
+ # Raised when an attempt is made to change an attribute that is read-only.
95
+ #
96
+ class AttributeError < ProtonError
97
+ end
98
+
99
+ # Raised by link components.
100
+ #
101
+ class LinkError < ProtonError
102
+ end
103
+
104
+ class SSLError < TransportError
105
+ end
106
+
107
+ class SSLUnavailableError < SSLError
108
+ end
109
+
110
+ # Raised when a message is rejected.
111
+ #
112
+ class Reject < ProtonError
124
113
  end
125
114
 
115
+ # Raised when a message is released.
116
+ #
117
+ class Release < ProtonError
118
+ end
119
+
120
+ # Raised when a message is aborted by the sender.
121
+ #
122
+ class AbortedError < ProtonError
123
+ end
124
+
125
+ # Raised to stop an automatic response to an endpoint open/close,
126
+ # so that the application can delay completing the open/close to a later time.
127
+ class StopAutoResponse < ProtonError
128
+ end
126
129
  end