Debian Codegraph @

ruby/lib/core/terminus.rb

raw
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 # Represents an endpoint for an AMQP connection..
22 #
23 # An AMQP terminus acts as either a source or a target for messages,
24 # but never as both. Every Link is associated iwth both a source and
25 # a target Terminus that is negotiated during link establishment.
26 #
27 # A terminus is composed of an AMQP address along with a number of
28 # other properties defining the quality of service and behavior of
29 # the Link.
30 #
31 class Terminus
32 include Util::Deprecation
33
34 # Indicates a non-existent source or target terminus.
35 UNSPECIFIED = Cproton::PN_UNSPECIFIED
36 # Indicates a source for messages.
37 SOURCE = Cproton::PN_SOURCE
38 # Indicates a target for messages.
39 TARGET = Cproton::PN_TARGET
40 # A special target identifying a transaction coordinator.
41 COORDINATOR = Cproton::PN_COORDINATOR
42
43 # The terminus is orphaned when the parent link is closed.
44 EXPIRE_WITH_LINK = Cproton::PN_EXPIRE_WITH_LINK
45 # The terminus is orphaned whent he parent sessio is closed.
46 EXPIRE_WITH_SESSION = Cproton::PN_EXPIRE_WITH_SESSION
47 # The terminus is orphaned when the parent connection is closed.
48 EXPIRE_WITH_CONNECTION = Cproton::PN_EXPIRE_WITH_CONNECTION
49 # The terminus is never considered orphaned.
50 EXPIRE_NEVER = Cproton::PN_EXPIRE_NEVER
51
52 # Indicates a non-durable Terminus.
53 NONDURABLE = Cproton::PN_NONDURABLE
54 # Indicates a Terminus with durably held configuration, but
55 # not the delivery state.
56 CONFIGURATION = Cproton::PN_CONFIGURATION
57 # Indicates a Terminus with both durably held configuration and
58 # durably held delivery states.
59 DELIVERIES = Cproton::PN_DELIVERIES
60
61 # The behavior is defined by the nod.e
62 DIST_MODE_UNSPECIFIED = Cproton::PN_DIST_MODE_UNSPECIFIED
63 # The receiver gets all messages.
64 DIST_MODE_COPY = Cproton::PN_DIST_MODE_COPY
65 # The receives compete for messages.
66 DIST_MODE_MOVE = Cproton::PN_DIST_MODE_MOVE
67
68 # @private
69 PROTON_METHOD_PREFIX = "pn_terminus"
70 # @private
71 extend Util::SWIGClassHelper
72
73 # @!attribute type
74 #
75 # @return [Integer] The terminus type.
76 #
77 # @see SOURCE
78 # @see TARGET
79 # @see COORDINATOR
80 #
81 proton_set_get :type
82
83 # @!attribute address
84 #
85 # @return [String] The terminus address.
86 #
87 proton_set_get :address
88
89 # @!attribute durability_mode
90 #
91 # @return [Integer] The durability mode of the terminus.
92 #
93 # @see NONDURABLE
94 # @see CONFIGURATION
95 # @see DELIVERIES
96 #
97 proton_forward :durability_mode, :get_durability
98 proton_forward :durability_mode=, :set_durability
99
100 deprecated_alias :durability, :durability_mode
101 deprecated_alias :durability=, :durability_mode=
102
103 # @!attribute expiry_policy
104 #
105 # @return [Integer] The expiry policy.
106 #
107 # @see EXPIRE_WITH_LINK
108 # @see EXPIRE_WITH_SESSION
109 # @see EXPIRE_WITH_CONNECTION
110 # @see EXPIRE_NEVER
111 #
112 proton_set_get :expiry_policy
113
114 # @!attribute timeout
115 #
116 # @return [Integer] The timeout period.
117 #
118 proton_set_get :timeout
119
120 # @!attribute dynamic?
121 #
122 # @return [Boolean] True if the terminus is dynamic.
123 #
124 proton_set_is :dynamic
125
126 # @!attribute distribution_mode
127 #
128 # @return [Integer] The distribution mode. Only relevant for a message source.
129 #
130 # @see DIST_MODE_UNSPECIFIED
131 # @see DIST_MODE_COPY
132 # @see DIST_MODE_MOVE
133 #
134 proton_set_get :distribution_mode
135
136 # @private
137 include Util::ErrorHandler
138
139 # @private
140 attr_reader :impl
141
142 # @private
143 def initialize(impl)
144 @impl = impl
145 end
146
147 # Access and modify the AMQP properties data for the Terminus.
148 #
149 # This operation will return an instance of Data that is valid until the
150 # Terminus is freed due to its parent being freed. Any data contained in
151 # the object will be sent as the AMQP properties for the parent Terminus
152 # instance.
153 #
154 # NOTE: this MUST take the form of a symbol keyed map to be valid.
155 #
156 # @return [Data] The terminus properties.
157 #
158 def properties
159 Codec::Data.new(Cproton.pn_terminus_properties(@impl))
160 end
161
162 # Access and modify the AMQP capabilities data for the Terminus.
163 #
164 # This operation will return an instance of Data that is valid until the
165 # Terminus is freed due to its parent being freed. Any data contained in
166 # the object will be sent as the AMQP properties for the parent Terminus
167 # instance.
168 #
169 # NOTE: this MUST take the form of a symbol keyed map to be valid.
170 #
171 # @return [Data] The terminus capabilities.
172 #
173 def capabilities
174 Codec::Data.new(Cproton.pn_terminus_capabilities(@impl))
175 end
176
177 # Access and modify the AMQP outcomes for the Terminus.
178 #
179 # This operaiton will return an instance of Data that is valid until the
180 # Terminus is freed due to its parent being freed. Any data contained in
181 # the object will be sent as the AMQP properties for the parent Terminus
182 # instance.
183 #
184 # NOTE: this MUST take the form of a symbol keyed map to be valid.
185 #
186 # @return [Data] The terminus outcomes.
187 #
188 def outcomes
189 Codec::Data.new(Cproton.pn_terminus_outcomes(@impl))
190 end
191
192 # Access and modify the AMQP filter set for a source terminus.
193 # Only relevant for a message source.
194 #
195 # This operation will return an instance of Data that is valid until the
196 # Terminus is freed due to its parent being freed. Any data contained in
197 # the object will be sent as the AMQP properties for the parent Terminus
198 # instance.
199 #
200 # NOTE: this MUST take the form of a symbol keyed map to be valid.
201 #
202 # @return [Data] The terminus filter.
203 #
204 def filter
205 Codec::Data.new(Cproton.pn_terminus_filter(@impl))
206 end
207
208 # Replace the data in this Terminus with the contents of +other+
209 # @param other [Terminus] The other instance.
210 def replace(other)
211 Cproton.pn_terminus_copy(@impl, other.impl)
212 self
213 end
214 deprecated_alias :copy, :replace
215
216 # Apply options to this terminus.
217 # @option opts [String] :address the node address
218 # @option opts [Boolean] :dynamic (false)
219 # if true, request a new node with a unique address to be created. +:address+ is ignored.
220 # @option opts [Integer] :distribution_mode see {#distribution_mode}, only for source nodes
221 # @option opts [Integer] :durability_mode see {#durability_mode}
222 # @option opts [Integer] :timeout see {#timeout}
223 # @option opts [Integer] :expiry_policy see {#expiry_policy}
224 # @option opts [Hash] :filter see {#filter}, only for source nodes
225 # @option opts [Hash] :capabilities see {#capabilities}
226 def apply(opts=nil)
227 return unless opts
228 if opts.is_a? String # Shorthand for address
229 self.address = opts
230 else
231 opts.each_pair do |k,v|
232 case k
233 when :address then self.address = v
234 when :dynamic then self.dynamic = !!v
235 when :distribution_mode then self.distribution_mode = v
236 when :durability_mode then self.durability_mode = v
237 when :timeout then self.timeout = v.round # Should be integer seconds
238 when :expiry_policy then self.expiry_policy = v
239 when :filter then self.filter << v
240 when :capabilities then self.capabilities << v
241 end
242 end
243 end
244 end
245
246 def inspect()
247 "\#<#{self.class}: address=#{address.inspect} dynamic?=#{dynamic?.inspect}>"
248 end
249
250 def to_s() inspect; end
251
252 can_raise_error([:type=, :address=, :durability=, :expiry_policy=,
253 :timeout=, :dynamic=, :distribution_mode=, :copy],
254 :error_class => Qpid::Proton::LinkError)
255 end
256 end