Debian Codegraph @

proton-j/src/main/java/org/apache/qpid/proton/engine/Link.java

raw
1 /*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21 package org.apache.qpid.proton.engine;
22
23 import java.util.EnumSet;
24 import java.util.Map;
25
26 import org.apache.qpid.proton.amqp.Symbol;
27 import org.apache.qpid.proton.amqp.UnsignedLong;
28 import org.apache.qpid.proton.amqp.transport.ReceiverSettleMode;
29 import org.apache.qpid.proton.amqp.transport.SenderSettleMode;
30 import org.apache.qpid.proton.amqp.transport.Source;
31 import org.apache.qpid.proton.amqp.transport.Target;
32
33 /**
34 * Link
35 *
36 * The settlement mode defaults are:
37 *
38 * Sender settle mode - {@link SenderSettleMode#MIXED}.
39 * Receiver settle mode - {@link ReceiverSettleMode#FIRST}
40 *
41 * TODO describe the application's responsibility to honour settlement.
42 */
43 public interface Link extends Endpoint
44 {
45
46 /**
47 * Returns the name of the link
48 *
49 * @return the link name
50 */
51 String getName();
52
53 /**
54 * Create a delivery object based on the specified tag and adds it to the
55 * this link's delivery list and its connection work list.
56 *
57 * TODO to clarify - this adds the delivery to the connection list. It is not yet
58 * clear why this is done or if it is useful for the application to be able to discover
59 * newly created deliveries from the {@link Connection#getWorkHead()}.
60 *
61 * @param tag a tag for the delivery
62 * @return a new Delivery object
63 */
64 public Delivery delivery(byte[] tag);
65
66 /**
67 * Create a delivery object based on the specified tag. This form
68 * of the method is intended to allow the tag to be formed from a
69 * subsequence of the byte array passed in. This might allow more
70 * optimisation options in future but at present is not
71 * implemented.
72 *
73 * @param tag a tag for the delivery
74 * @param offset (currently ignored and must be 0)
75 * @param length (currently ignored and must be the length of the <code>tag</code> array
76 * @return a Delivery object
77 */
78 public Delivery delivery(byte[] tag, int offset, int length);
79
80 /**
81 * Returns the head delivery on the link.
82 */
83 Delivery head();
84
85 /**
86 * Returns the current delivery
87 */
88 Delivery current();
89
90 /**
91 * Attempts to advance the current delivery. Advances it to the next delivery if one exists, else null.
92 *
93 * The behaviour of this method is different for senders and receivers.
94 *
95 * @return true if it can advance, false if it cannot
96 *
97 * TODO document the meaning of the return value more fully. Currently Senderimpl only returns false if there is no current delivery
98 */
99 boolean advance();
100
101
102 Source getSource();
103 Target getTarget();
104
105 /**
106 * Sets the source for this link.
107 *
108 * The initiator of the link must always provide a Source.
109 *
110 * An application responding to the creation of the link should perform an application
111 * specific lookup on the {@link #getRemoteSource()} to determine an actual Source. If it
112 * failed to determine an actual source, it should set null, and then go on to {@link #close()}
113 * the link.
114 *
115 * @see "AMQP Spec 1.0 section 2.6.3"
116 */
117 void setSource(Source address);
118
119 /**
120 * Expected to be used in a similar manner to {@link #setSource(Source)}
121 */
122 void setTarget(Target address);
123
124 /**
125 * @see #setSource(Source)
126 */
127 Source getRemoteSource();
128
129 /**
130 * @see #setTarget(Target)
131 */
132 Target getRemoteTarget();
133
134 public Link next(EnumSet<EndpointState> local, EnumSet<EndpointState> remote);
135
136 /**
137 * Gets the credit balance for a link.
138 *
139 * Note that a sending link may still be used to send deliveries even if
140 * link credit is/reaches zero, however those deliveries will end up being
141 * {@link #getQueued() queued} by the link until enough credit is obtained
142 * from the receiver to send them over the wire. In this case the balance
143 * reported will go negative.
144 *
145 * @return the credit balance for the link
146 */
147 public int getCredit();
148
149 /**
150 * Gets the number of queued messages for a link.
151 *
152 * Links may queue deliveries for a number of reasons, for example there may be insufficient
153 * {@link #getCredit() credit} to send them to the receiver, they may not have yet had a chance
154 * to be written to the wire, or the receiving application has simply not yet processed them.
155 *
156 * @return the queued message count for the link
157 */
158 public int getQueued();
159
160 public int getUnsettled();
161
162 public Session getSession();
163
164 SenderSettleMode getSenderSettleMode();
165
166 /**
167 * Sets the sender settle mode.
168 *
169 * Should only be called during link set-up, i.e. before calling {@link #open()}.
170 *
171 * If this endpoint is the initiator of the link, this method can be used to set a value other than
172 * the default.
173 *
174 * If this endpoint is not the initiator, this method should be used to set a local value. According
175 * to the AMQP spec, the application may choose to accept the sender's suggestion
176 * (accessed by calling {@link #getRemoteSenderSettleMode()}) or choose another value. The value
177 * has no effect on Proton, but may be useful to the application at a later point.
178 *
179 * In order to be AMQP compliant the application is responsible for honouring the settlement mode. See {@link Link}.
180 */
181 void setSenderSettleMode(SenderSettleMode senderSettleMode);
182
183 /**
184 * @see #setSenderSettleMode(SenderSettleMode)
185 */
186 SenderSettleMode getRemoteSenderSettleMode();
187
188 ReceiverSettleMode getReceiverSettleMode();
189
190 /**
191 * Sets the receiver settle mode.
192 *
193 * Used in analogous way to {@link #setSenderSettleMode(SenderSettleMode)}
194 */
195 void setReceiverSettleMode(ReceiverSettleMode receiverSettleMode);
196
197 /**
198 * @see #setReceiverSettleMode(ReceiverSettleMode)
199 */
200 ReceiverSettleMode getRemoteReceiverSettleMode();
201
202 /**
203 * TODO should this be part of the interface?
204 */
205 @Deprecated
206 void setRemoteSenderSettleMode(SenderSettleMode remoteSenderSettleMode);
207
208 /**
209 * Gets the local link properties.
210 *
211 * @see #setProperties(Map)
212 */
213 Map<Symbol, Object> getProperties();
214
215 /**
216 * Sets the local link properties, to be conveyed to the peer via the Attach frame when
217 * attaching the link to the session.
218 *
219 * Must be called during link setup, i.e. before calling the {@link #open()} method.
220 */
221 void setProperties(Map<Symbol, Object> properties);
222
223 /**
224 * Gets the remote link properties, as conveyed from the peer via the Attach frame
225 * when attaching the link to the session.
226 *
227 * @return the properties Map conveyed by the peer, or null if there was none.
228 */
229 Map<Symbol, Object> getRemoteProperties();
230
231 public int drained();
232
233 /**
234 * Returns a [locally generated] view of credit at the remote peer by considering the
235 * current link {@link #getCredit() credit} count as well as the effect of
236 * any locally {@link #getQueued() queued} messages.
237 *
238 * @return view of effective remote credit
239 */
240 public int getRemoteCredit();
241
242 public boolean getDrain();
243
244 public void detach();
245 public boolean detached();
246
247 /**
248 * Sets the local link offered capabilities, to be conveyed to the peer via the Attach frame
249 * when attaching the link to the session.
250 *
251 * Must be called during link setup, i.e. before calling the {@link #open()} method.
252 *
253 * @param offeredCapabilities
254 * the offered capabilities array to send, or null for none.
255 */
256 public void setOfferedCapabilities(Symbol[] offeredCapabilities);
257
258 /**
259 * Gets the local link offered capabilities.
260 *
261 * @return the offered capabilities array, or null if none was set.
262 *
263 * @see #setOfferedCapabilities(Symbol[])
264 */
265 Symbol[] getOfferedCapabilities();
266
267 /**
268 * Gets the remote link offered capabilities, as conveyed from the peer via the Attach frame
269 * when attaching the link to the session.
270 *
271 * @return the offered capabilities array conveyed by the peer, or null if there was none.
272 */
273 Symbol[] getRemoteOfferedCapabilities();
274
275 /**
276 * Sets the local link desired capabilities, to be conveyed to the peer via the Attach frame
277 * when attaching the link to the session.
278 *
279 * Must be called during link setup, i.e. before calling the {@link #open()} method.
280 *
281 * @param desiredCapabilities
282 * the desired capabilities array to send, or null for none.
283 */
284 public void setDesiredCapabilities(Symbol[] desiredCapabilities);
285
286 /**
287 * Gets the local link desired capabilities.
288 *
289 * @return the desired capabilities array, or null if none was set.
290 *
291 * @see #setDesiredCapabilities(Symbol[])
292 */
293 Symbol[] getDesiredCapabilities();
294
295 /**
296 * Gets the remote link desired capabilities, as conveyed from the peer via the Attach frame
297 * when attaching the link to the session.
298 *
299 * @return the desired capabilities array conveyed by the peer, or null if there was none.
300 */
301 Symbol[] getRemoteDesiredCapabilities();
302
303 /**
304 * Sets the local link max message size, to be conveyed to the peer via the Attach frame
305 * when attaching the link to the session. Null or 0 means no limit.
306 *
307 * Must be called during link setup, i.e. before calling the {@link #open()} method.
308 *
309 * @param maxMessageSize
310 * the local max message size value, or null to clear. 0 also means no limit.
311 */
312 void setMaxMessageSize(UnsignedLong maxMessageSize);
313
314 /**
315 * Gets the local link max message size.
316 *
317 * @return the local max message size, or null if none was set. 0 also means no limit.
318 *
319 * @see #setMaxMessageSize(UnsignedLong)
320 */
321 UnsignedLong getMaxMessageSize();
322
323 /**
324 * Gets the remote link max message size, as conveyed from the peer via the Attach frame
325 * when attaching the link to the session.
326 *
327 * @return the remote max message size conveyed by the peer, or null if none was set. 0 also means no limit.
328 */
329 UnsignedLong getRemoteMaxMessageSize();
330 }