Home / Class/ DefaultHttp2LocalFlowController Class — netty Architecture

DefaultHttp2LocalFlowController Class — netty Architecture

Architecture documentation for the DefaultHttp2LocalFlowController class in DefaultHttp2LocalFlowController.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  36ddda9f_3efd_b028_26eb_619b997ea963["DefaultHttp2LocalFlowController"]
  40872612_d507_c116_2a45_f6a7304d70c3["DefaultHttp2LocalFlowController.java"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|defined in| 40872612_d507_c116_2a45_f6a7304d70c3
  a440d6d3_b77f_7649_883b_58e5b5d1a03d["DefaultHttp2LocalFlowController()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| a440d6d3_b77f_7649_883b_58e5b5d1a03d
  4067647c_f9c7_bde4_7b8c_40f13338f301["channelHandlerContext()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| 4067647c_f9c7_bde4_7b8c_40f13338f301
  9b6920f9_c0fb_2c1a_29e1_1d03e42fd974["initialWindowSize()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| 9b6920f9_c0fb_2c1a_29e1_1d03e42fd974
  7b1bc4c9_ebdf_8d02_088f_aca3bcbd47d2["windowSize()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| 7b1bc4c9_ebdf_8d02_088f_aca3bcbd47d2
  8f5c83ec_a0ba_8175_a92b_575a502628da["incrementWindowSize()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| 8f5c83ec_a0ba_8175_a92b_575a502628da
  13160351_4f41_3008_7caf_908c2881fdb0["consumeBytes()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| 13160351_4f41_3008_7caf_908c2881fdb0
  dfeec92d_b9a3_9962_60d3_bafdee4a7557["consumeAllBytes()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| dfeec92d_b9a3_9962_60d3_bafdee4a7557
  a89ed0c8_7255_1694_956c_f134ac6f835c["unconsumedBytes()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| a89ed0c8_7255_1694_956c_f134ac6f835c
  849d6605_749f_d5b5_7f3b_6e927d5da205["checkValidRatio()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| 849d6605_749f_d5b5_7f3b_6e927d5da205
  8e7edab7_3878_e374_7f64_d7a626dff93d["windowUpdateRatio()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| 8e7edab7_3878_e374_7f64_d7a626dff93d
  33746bc7_789f_d1be_3449_9bda9fc12cea["receiveFlowControlledFrame()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| 33746bc7_789f_d1be_3449_9bda9fc12cea
  fc95b1a5_8ad4_8144_5ac2_dd6060bed632["FlowState()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| fc95b1a5_8ad4_8144_5ac2_dd6060bed632
  fafdcd3b_e1ac_f571_9e49_4a4678015b65["isClosed()"]
  36ddda9f_3efd_b028_26eb_619b997ea963 -->|method| fafdcd3b_e1ac_f571_9e49_4a4678015b65

Relationship Graph

Source Code

codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2LocalFlowController.java lines 42–646

public class DefaultHttp2LocalFlowController implements Http2LocalFlowController {
    /**
     * The default ratio of window size to initial window size below which a {@code WINDOW_UPDATE}
     * is sent to expand the window.
     */
    public static final float DEFAULT_WINDOW_UPDATE_RATIO = 0.5f;

    private final Http2Connection connection;
    private final Http2Connection.PropertyKey stateKey;
    private Http2FrameWriter frameWriter;
    private ChannelHandlerContext ctx;
    private float windowUpdateRatio;
    private int initialWindowSize = DEFAULT_WINDOW_SIZE;

    public DefaultHttp2LocalFlowController(Http2Connection connection) {
        this(connection, DEFAULT_WINDOW_UPDATE_RATIO, false);
    }

    /**
     * Constructs a controller with the given settings.
     *
     * @param connection the connection state.
     * @param windowUpdateRatio the window percentage below which to send a {@code WINDOW_UPDATE}.
     * @param autoRefillConnectionWindow if {@code true}, effectively disables the connection window
     * in the flow control algorithm as they will always refill automatically without requiring the
     * application to consume the bytes. When enabled, the maximum bytes you must be prepared to
     * queue is proportional to {@code maximum number of concurrent streams * the initial window
     * size per stream}
     * (<a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_MAX_CONCURRENT_STREAMS</a>
     * <a href="https://tools.ietf.org/html/rfc7540#section-6.5.2">SETTINGS_INITIAL_WINDOW_SIZE</a>).
     */
    public DefaultHttp2LocalFlowController(Http2Connection connection,
                                           float windowUpdateRatio,
                                           boolean autoRefillConnectionWindow) {
        this.connection = checkNotNull(connection, "connection");
        windowUpdateRatio(windowUpdateRatio);

        // Add a flow state for the connection.
        stateKey = connection.newKey();
        FlowState connectionState = autoRefillConnectionWindow ?
                new AutoRefillState(connection.connectionStream(), initialWindowSize) :
                new DefaultState(connection.connectionStream(), initialWindowSize);
        connection.connectionStream().setProperty(stateKey, connectionState);

        // Register for notification of new streams.
        connection.addListener(new Http2ConnectionAdapter() {
            @Override
            public void onStreamAdded(Http2Stream stream) {
                // Unconditionally used the reduced flow control state because it requires no object allocation
                // and the DefaultFlowState will be allocated in onStreamActive.
                stream.setProperty(stateKey, REDUCED_FLOW_STATE);
            }

            @Override
            public void onStreamActive(Http2Stream stream) {
                // Need to be sure the stream's initial window is adjusted for SETTINGS
                // frames which may have been exchanged while it was in IDLE
                stream.setProperty(stateKey, new DefaultState(stream, initialWindowSize));
            }

            @Override
            public void onStreamClosed(Http2Stream stream) {
                try {
                    // When a stream is closed, consume any remaining bytes so that they
                    // are restored to the connection window.
                    FlowState state = state(stream);
                    int unconsumedBytes = state.unconsumedBytes();
                    if (ctx != null && unconsumedBytes > 0) {
                        if (consumeAllBytes(state, unconsumedBytes)) {
                            // As the user has no real control on when this callback is used we should better
                            // call flush() if we produced any window update to ensure we not stale.
                            ctx.flush();
                        }
                    }
                } catch (Http2Exception e) {
                    PlatformDependent.throwException(e);
                } finally {
                    // Unconditionally reduce the amount of memory required for flow control because there is no
                    // object allocation costs associated with doing so and the stream will not have any more
                    // local flow control state to keep track of anymore.
                    stream.setProperty(stateKey, REDUCED_FLOW_STATE);

Frequently Asked Questions

What is the DefaultHttp2LocalFlowController class?
DefaultHttp2LocalFlowController is a class in the netty codebase, defined in codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2LocalFlowController.java.
Where is DefaultHttp2LocalFlowController defined?
DefaultHttp2LocalFlowController is defined in codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2LocalFlowController.java at line 42.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free