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.channel.ChannelHandlerContext;
18  
19  /**
20   * Base interface for all HTTP/2 flow controllers.
21   */
22  public interface Http2FlowController {
23  
24      /**
25       * Sets the initial flow control window and updates all stream windows (but not the connection
26       * window) by the delta.
27       * <p>
28       * This method is used to apply the {@code SETTINGS_INITIAL_WINDOW_SIZE} value for an
29       * {@code SETTINGS} frame.
30       *
31       * @param newWindowSize the new initial window size.
32       * @throws Http2Exception thrown if any protocol-related error occurred.
33       */
34      void initialWindowSize(int newWindowSize) throws Http2Exception;
35  
36      /**
37       * Gets the initial flow control window size that is used as the basis for new stream flow
38       * control windows.
39       */
40      int initialWindowSize();
41  
42      /**
43       * Gets the number of bytes remaining in the flow control window size for the given stream.
44       *
45       * @param stream The subject stream. Use {@link Http2Connection#connectionStream()} for
46       *            requesting the size of the connection window.
47       * @return the current size of the flow control window.
48       * @throws IllegalArgumentException if the given stream does not exist.
49       */
50      int windowSize(Http2Stream stream);
51  
52      /**
53       * Increments the size of the stream's flow control window by the given delta.
54       * <p>
55       * In the case of a {@link Http2RemoteFlowController} this is called upon receipt of a
56       * {@code WINDOW_UPDATE} frame from the remote endpoint to mirror the changes to the window
57       * size.
58       * <p>
59       * For a {@link Http2LocalFlowController} this can be called to request the expansion of the
60       * window size published by this endpoint. It is up to the implementation, however, as to when a
61       * {@code WINDOW_UPDATE} is actually sent.
62       *
63       * @param ctx The context for the calling handler
64       * @param stream The subject stream. Use {@link Http2Connection#connectionStream()} for
65       *            requesting the size of the connection window.
66       * @param delta the change in size of the flow control window.
67       * @throws Http2Exception thrown if a protocol-related error occurred.
68       */
69      void incrementWindowSize(ChannelHandlerContext ctx, Http2Stream stream, int delta) throws Http2Exception;
70  }