View Javadoc
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License, version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at:
7    *
8    * https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package io.netty.handler.codec.http2;
16  
17  import io.netty.buffer.ByteBuf;
18  
19  /**
20   * A {@link Http2FlowController} for controlling the inbound flow of {@code DATA} frames from the remote endpoint.
21   */
22  public interface Http2LocalFlowController extends Http2FlowController {
23      /**
24       * Sets the writer to be use for sending {@code WINDOW_UPDATE} frames. This must be called before any flow
25       * controlled data is received.
26       *
27       * @param frameWriter the HTTP/2 frame writer.
28       */
29      Http2LocalFlowController frameWriter(Http2FrameWriter frameWriter);
30  
31      /**
32       * Receives an inbound {@code DATA} frame from the remote endpoint and applies flow control policies to it for both
33       * the {@code stream} as well as the connection. If any flow control policies have been violated, an exception is
34       * raised immediately, otherwise the frame is considered to have "passed" flow control.
35       * <p/>
36       * If {@code stream} is {@code null} or closed, flow control should only be applied to the connection window and the
37       * bytes are immediately consumed.
38       *
39       * @param stream the subject stream for the received frame. The connection stream object must not be used. If {@code
40       * stream} is {@code null} or closed, flow control should only be applied to the connection window and the bytes are
41       * immediately consumed.
42       * @param data payload buffer for the frame.
43       * @param padding additional bytes that should be added to obscure the true content size. Must be between 0 and
44       *                256 (inclusive).
45       * @param endOfStream Indicates whether this is the last frame to be sent from the remote endpoint for this stream.
46       * @throws Http2Exception if any flow control errors are encountered.
47       */
48      void receiveFlowControlledFrame(Http2Stream stream, ByteBuf data, int padding,
49                                      boolean endOfStream) throws Http2Exception;
50  
51      /**
52       * Indicates that the application has consumed a number of bytes for the given stream and is therefore ready to
53       * receive more data from the remote endpoint. The application must consume any bytes that it receives or the flow
54       * control window will collapse. Consuming bytes enables the flow controller to send {@code WINDOW_UPDATE} to
55       * restore a portion of the flow control window for the stream.
56       * <p/>
57       * If {@code stream} is {@code null} or closed (i.e. {@link Http2Stream#state()} method returns {@link
58       * Http2Stream.State#CLOSED}), calling this method has no effect.
59       *
60       * @param stream the stream for which window space should be freed. The connection stream object must not be used.
61       * If {@code stream} is {@code null} or closed (i.e. {@link Http2Stream#state()} method returns {@link
62       * Http2Stream.State#CLOSED}), calling this method has no effect.
63       * @param numBytes the number of bytes to be returned to the flow control window.
64       * @return true if a {@code WINDOW_UPDATE} was sent, false otherwise.
65       * @throws Http2Exception if the number of bytes returned exceeds the {@link #unconsumedBytes(Http2Stream)} for the
66       * stream.
67       */
68      boolean consumeBytes(Http2Stream stream, int numBytes) throws Http2Exception;
69  
70      /**
71       * The number of bytes for the given stream that have been received but not yet consumed by the
72       * application.
73       *
74       * @param stream the stream for which window space should be freed.
75       * @return the number of unconsumed bytes for the stream.
76       */
77      int unconsumedBytes(Http2Stream stream);
78  
79      /**
80       * Get the initial flow control window size for the given stream. This quantity is measured in number of bytes. Note
81       * the unavailable window portion can be calculated by {@link #initialWindowSize()} - {@link
82       * #windowSize(Http2Stream)}.
83       */
84      int initialWindowSize(Http2Stream stream);
85  }