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.channel.ChannelHandlerContext;
18  
19  /**
20   * Base interface for all HTTP/2 flow controllers.
21   */
22  public interface Http2FlowController {
23      /**
24       * Set the {@link ChannelHandlerContext} for which to apply flow control on.
25       * <p>
26       * This <strong>must</strong> be called to properly initialize the {@link Http2FlowController}.
27       * Not calling this is considered a programming error.
28       * @param ctx The {@link ChannelHandlerContext} for which to apply flow control on.
29       * @throws Http2Exception if any protocol-related error occurred.
30       */
31      void channelHandlerContext(ChannelHandlerContext ctx) throws Http2Exception;
32  
33      /**
34       * Sets the connection-wide initial flow control window and updates all stream windows (but not the connection
35       * stream window) by the delta.
36       * <p>
37       * Represents the value for
38       * <a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_INITIAL_WINDOW_SIZE</a>. This method should
39       * only be called by Netty (not users) as a result of a receiving a {@code SETTINGS} frame.
40       *
41       * @param newWindowSize the new initial window size.
42       * @throws Http2Exception thrown if any protocol-related error occurred.
43       */
44      void initialWindowSize(int newWindowSize) throws Http2Exception;
45  
46      /**
47       * Gets the connection-wide initial flow control window size that is used as the basis for new stream flow
48       * control windows.
49       * <p>
50       * Represents the value for
51       * <a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_INITIAL_WINDOW_SIZE</a>. The initial value
52       * returned by this method must be {@link Http2CodecUtil#DEFAULT_WINDOW_SIZE}.
53       */
54      int initialWindowSize();
55  
56      /**
57       * Get the portion of the flow control window for the given stream that is currently available for sending/receiving
58       * frames which are subject to flow control. This quantity is measured in number of bytes.
59       */
60      int windowSize(Http2Stream stream);
61  
62      /**
63       * Increments the size of the stream's flow control window by the given delta.
64       * <p>
65       * In the case of a {@link Http2RemoteFlowController} this is called upon receipt of a
66       * {@code WINDOW_UPDATE} frame from the remote endpoint to mirror the changes to the window
67       * size.
68       * <p>
69       * For a {@link Http2LocalFlowController} this can be called to request the expansion of the
70       * window size published by this endpoint. It is up to the implementation, however, as to when a
71       * {@code WINDOW_UPDATE} is actually sent.
72       *
73       * @param stream The subject stream. Use {@link Http2Connection#connectionStream()} for
74       *            requesting the size of the connection window.
75       * @param delta the change in size of the flow control window.
76       * @throws Http2Exception thrown if a protocol-related error occurred.
77       */
78      void incrementWindowSize(Http2Stream stream, int delta) throws Http2Exception;
79  }