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    * http://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  import io.netty.channel.ChannelHandlerContext;
19  
20  /**
21   * A {@link Http2FlowController} for controlling the inbound flow of {@code DATA} frames from the remote
22   * endpoint.
23   */
24  public interface Http2LocalFlowController extends Http2FlowController {
25  
26      /**
27       * Receives an inbound {@code DATA} frame from the remote endpoint and applies flow control
28       * policies to it for both the {@code stream} as well as the connection. If any flow control
29       * policies have been violated, an exception is raised immediately, otherwise the frame is
30       * considered to have "passed" flow control.
31       *
32       * @param ctx the context from the handler where the frame was read.
33       * @param stream the subject stream for the received frame. The connection stream object must
34       *            not be used.
35       * @param data payload buffer for the frame.
36       * @param padding the number of padding bytes found at the end of the frame.
37       * @param endOfStream Indicates whether this is the last frame to be sent from the remote
38       *            endpoint for this stream.
39       * @throws Http2Exception if any flow control errors are encountered.
40       */
41      void receiveFlowControlledFrame(ChannelHandlerContext ctx, Http2Stream stream, ByteBuf data, int padding,
42              boolean endOfStream) throws Http2Exception;
43  
44      /**
45       * Indicates that the application has consumed a number of bytes for the given stream and is
46       * therefore ready to receive more data from the remote endpoint. The application must consume
47       * any bytes that it receives or the flow control window will collapse. Consuming bytes enables
48       * the flow controller to send {@code WINDOW_UPDATE} to restore a portion of the flow control
49       * window for the stream.
50       *
51       * @param ctx the channel handler context to use when sending a {@code WINDOW_UPDATE} if
52       *            appropriate
53       * @param stream the stream for which window space should be freed. The connection stream object
54       *            must not be used.
55       * @param numBytes the number of bytes to be returned to the flow control window.
56       * @throws Http2Exception if the number of bytes returned exceeds the {@link #unconsumedBytes}
57       *             for the stream.
58       */
59      void consumeBytes(ChannelHandlerContext ctx, Http2Stream stream, int numBytes) throws Http2Exception;
60  
61      /**
62       * The number of bytes for the given stream that have been received but not yet consumed by the
63       * application.
64       *
65       * @param stream the stream for which window space should be freed.
66       * @return the number of unconsumed bytes for the stream.
67       */
68      int unconsumedBytes(Http2Stream stream);
69  }