Debian Codegraph @

proton-j/src/main/java/org/apache/qpid/proton/engine/Transport.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.nio.ByteBuffer;
24
25 import org.apache.qpid.proton.amqp.transport.ErrorCondition;
26 import org.apache.qpid.proton.engine.impl.TransportImpl;
27
28
29 /**
30 * <p>
31 * Operates on the entities in the associated {@link Connection}
32 * by accepting and producing binary AMQP output, potentially
33 * layered within SASL and/or SSL.
34 * </p>
35 * <p>
36 * After a connection is bound with {@link #bind(Connection)}, the methods for accepting and producing
37 * output are typically repeatedly called. See the specific methods for details of their legal usage.
38 * </p>
39 * <p>
40 * <strong>Processing the input data received from another AMQP container.</strong>
41 * </p>
42 * <ol>
43 * <li>{@link #getInputBuffer()} </li>
44 * <li>Write data into input buffer</li>
45 * <li>{@link #processInput()}</li>
46 * <li>Check the result, e.g. by calling {@link TransportResult#checkIsOk()}</li>
47 * </ol>
48 * <p>
49 * <strong>Getting the output data to send to another AMQP container:</strong>
50 * </p>
51 * <ol>
52 * <li>{@link #getOutputBuffer()} </li>
53 * <li>Read output from output buffer</li>
54 * <li>{@link #outputConsumed()}</li>
55 * </ol>
56 *
57 * <p>The following methods on the byte buffers returned by {@link #getInputBuffer()} and {@link #getOutputBuffer()}
58 * must not be called:
59 * </p>
60 * <ol>
61 * <li> {@link ByteBuffer#clear()} </li>
62 * <li> {@link ByteBuffer#compact()} </li>
63 * <li> {@link ByteBuffer#flip()} </li>
64 * <li> {@link ByteBuffer#mark()} </li>
65 * </ol>
66 */
67 public interface Transport extends Endpoint
68 {
69
70 public static final class Factory
71 {
72 public static Transport create() {
73 return new TransportImpl();
74 }
75 }
76
77 public static final int TRACE_OFF = 0;
78 public static final int TRACE_RAW = 1;
79 public static final int TRACE_FRM = 2;
80 public static final int TRACE_DRV = 4;
81
82 public static final int DEFAULT_MAX_FRAME_SIZE = -1;
83
84 /** the lower bound for the agreed maximum frame size (in bytes). */
85 public int MIN_MAX_FRAME_SIZE = 512;
86 public int SESSION_WINDOW = 16*1024;
87 public int END_OF_STREAM = -1;
88
89 public void trace(int levels);
90
91 public void bind(Connection connection);
92 public void unbind();
93
94 public int capacity();
95 public ByteBuffer tail();
96 public void process() throws TransportException;
97 public void close_tail();
98
99
100 public int pending();
101 public ByteBuffer head();
102 public void pop(int bytes);
103 public void close_head();
104
105 public boolean isClosed();
106
107 /**
108 * Processes the provided input.
109 *
110 * @param bytes input bytes for consumption
111 * @param offset the offset within bytes where input begins
112 * @param size the number of bytes available for input
113 *
114 * @return the number of bytes consumed
115 * @throws TransportException if the input is invalid, if the transport is already in an error state,
116 * or if the input is empty (unless the remote connection is already closed)
117 * @deprecated use {@link #getInputBuffer()} and {@link #processInput()} instead.
118 */
119 @Deprecated
120 public int input(byte[] bytes, int offset, int size);
121
122 /**
123 * Get a buffer that can be used to write input data into the transport.
124 * Once the client has finished putting into the input buffer, {@link #processInput()}
125 * must be called.
126 *
127 * Successive calls to this method are not guaranteed to return the same object.
128 * Once {@link #processInput()} is called the buffer must not be used.
129 *
130 * @throws TransportException if the transport is already in an invalid state
131 */
132 ByteBuffer getInputBuffer();
133
134 /**
135 * Tell the transport to process the data written to the input buffer.
136 *
137 * If the returned result indicates failure, the transport will not accept any more input.
138 * Specifically, any subsequent {@link #processInput()} calls on this object will
139 * throw an exception.
140 *
141 * @return the result of processing the data, which indicates success or failure.
142 * @see #getInputBuffer()
143 */
144 TransportResult processInput();
145
146 /**
147 * Has the transport produce up to size bytes placing the result
148 * into dest beginning at position offset.
149 *
150 * @param dest array for output bytes
151 * @param offset the offset within bytes where output begins
152 * @param size the maximum number of bytes to be output
153 *
154 * @return the number of bytes written
155 * @deprecated use {@link #getOutputBuffer()} and {@link #outputConsumed()} instead
156 */
157 @Deprecated
158 public int output(byte[] dest, int offset, int size);
159
160 /**
161 * Get a read-only byte buffer containing the transport's pending output.
162 * Once the client has finished getting from the output buffer, {@link #outputConsumed()}
163 * must be called.
164 *
165 * Successive calls to this method are not guaranteed to return the same object.
166 * Once {@link #outputConsumed()} is called the buffer must not be used.
167 *
168 * If the transport's state changes AFTER calling this method, this will not be
169 * reflected in the output buffer.
170 */
171 ByteBuffer getOutputBuffer();
172
173 /**
174 * Informs the transport that the output buffer returned by {@link #getOutputBuffer()}
175 * is finished with, allowing implementation-dependent steps to be performed such as
176 * reclaiming buffer space.
177 */
178 void outputConsumed();
179
180 /**
181 * Signal the transport to expect SASL frames used to establish a SASL layer prior to
182 * performing the AMQP protocol version negotiation. This must first be performed before
183 * the transport is used for processing. Subsequent invocations will return the same
184 * {@link Sasl} object.
185 *
186 * @throws IllegalStateException if transport processing has already begun prior to initial invocation
187 */
188 Sasl sasl() throws IllegalStateException;
189
190 /**
191 * Wrap this transport's output and input to apply SSL encryption and decryption respectively.
192 *
193 * This method is expected to be called at most once. A subsequent invocation will return the same
194 * {@link Ssl} object, regardless of the parameters supplied.
195 *
196 * @param sslDomain the SSL settings to use
197 * @param sslPeerDetails peer details, used for SNI, hostname verification, etc when connecting. May be null.
198 * @return an {@link Ssl} object representing the SSL session.
199 * @throws IllegalArgumentException if the sslDomain requests hostname verification but sslPeerDetails are null.
200 * @throws IllegalStateException if the sslDomain has not been initialised.
201 */
202 Ssl ssl(SslDomain sslDomain, SslPeerDetails sslPeerDetails) throws IllegalArgumentException;
203
204 /**
205 * Equivalent to {@link #ssl(SslDomain, SslPeerDetails)} but passing null for SslPeerDetails, meaning no SNI detail
206 * is sent, hostname verification isn't supported etc when connecting.
207 *
208 * @throws IllegalArgumentException if the sslDomain requests hostname verification.
209 * @throws IllegalStateException if the sslDomain has not been initialised.
210 */
211 Ssl ssl(SslDomain sslDomain) throws IllegalArgumentException;
212
213
214 /**
215 * Get the maximum frame size for the transport
216 *
217 * @return the maximum frame size
218 */
219 int getMaxFrameSize();
220
221 void setMaxFrameSize(int size);
222
223 int getRemoteMaxFrameSize();
224
225 /**
226 * Allows overriding the initial remote-max-frame-size to a value greater than the default 512bytes. The value set
227 * will be used until such time as the Open frame arrives from the peer and populates the remote max frame size.
228 *
229 * This method must be called before before {@link #sasl()} in order to influence SASL behaviour.
230 * @param size the remote frame size to use
231 */
232 void setInitialRemoteMaxFrameSize(int size);
233
234 /**
235 * Gets the local channel-max value to be advertised to the remote peer
236 *
237 * @return the local channel-max value
238 * @see #setChannelMax(int)
239 */
240 int getChannelMax();
241
242 /**
243 * Set the local value of channel-max, to be advertised to the peer on the
244 * <a href="http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#type-open">
245 * Open frame</a> emitted by the transport.
246 *
247 * The remote peers advertised channel-max can be observed using {@link #getRemoteChannelMax()}.
248 *
249 * @param channelMax the local channel-max to advertise to the peer, in range [0 - 2^16).
250 * @throws IllegalArgumentException if the value supplied is outside range [0 - 2^16).
251 */
252 void setChannelMax(int channelMax);
253
254 /**
255 * Gets the remote value of channel-max, as advertised by the peer on its
256 * <a href="http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#type-open">
257 * Open frame</a>.
258 *
259 * The local peers advertised channel-max can be observed using {@link #getChannelMax()}.
260 *
261 * @return the remote channel-max value
262 */
263 int getRemoteChannelMax();
264
265 ErrorCondition getCondition();
266
267 /**
268 *
269 * @param timeout local idle timeout in milliseconds
270 */
271 void setIdleTimeout(int timeout);
272 /**
273 *
274 * @return local idle timeout in milliseconds
275 */
276 int getIdleTimeout();
277 /**
278 *
279 * @return remote idle timeout in milliseconds
280 */
281 int getRemoteIdleTimeout();
282
283 /**
284 * Prompt the transport to perform work such as idle-timeout/heartbeat handling, and return an
285 * absolute deadline in milliseconds that tick must again be called by/at, based on the provided
286 * current time in milliseconds, to ensure the periodic work is carried out as necessary.
287 *
288 * A returned deadline of 0 indicates there is no periodic work necessitating tick be called, e.g.
289 * because neither peer has defined an idle-timeout value.
290 *
291 * The provided milliseconds time values can be from {@link System#currentTimeMillis()} or derived
292 * from {@link System#nanoTime()}, noting that for the later in particular that the returned
293 * deadline could be a different sign than the given time, and (if non-zero) the returned
294 * deadline should have the current time originally provided subtracted from it in order to
295 * establish a relative time delay to the next deadline.
296 *
297 * @param nowMillis the current time in milliseconds
298 * @return the absolute deadline in milliseconds to next call tick by/at, or 0 if there is none.
299 */
300 long tick(long nowMillis);
301
302 long getFramesInput();
303
304 long getFramesOutput();
305
306 /**
307 * Configure whether a synthetic Flow event should be emitted when messages are sent,
308 * reflecting a change in the credit level on the link that may prompt other action.
309 *
310 * Defaults to true.
311 *
312 * @param emitFlowEventOnSend true if a flow event should be emitted, false otherwise
313 */
314 void setEmitFlowEventOnSend(boolean emitFlowEventOnSend);
315
316 boolean isEmitFlowEventOnSend();
317
318 /**
319 * Set an upper limit on the size of outgoing frames that will be sent
320 * to the peer. Allows constraining the transport not to emit Transfer
321 * frames over a given size even when the peers max frame size allows it.
322 *
323 * Must be set before receiving the peers Open frame to have effect.
324 *
325 * @param size the size limit to apply
326 */
327 void setOutboundFrameSizeLimit(int size);
328
329 int getOutboundFrameSizeLimit();
330 }