Home / Class/ Http2ControlFrameLimitEncoder Class — netty Architecture

Http2ControlFrameLimitEncoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  f941964b_67fa_416a_683a_69abc95d93e2["Http2ControlFrameLimitEncoder"]
  4b56ae10_da3f_5aff_1851_a3afc4e02549["Http2ControlFrameLimitEncoder.java"]
  f941964b_67fa_416a_683a_69abc95d93e2 -->|defined in| 4b56ae10_da3f_5aff_1851_a3afc4e02549
  094a3f01_8758_b09e_9c6e_ab653b36c0fe["Http2ControlFrameLimitEncoder()"]
  f941964b_67fa_416a_683a_69abc95d93e2 -->|method| 094a3f01_8758_b09e_9c6e_ab653b36c0fe
  3e617422_2360_595a_5a12_2c9e40cf3cb8["lifecycleManager()"]
  f941964b_67fa_416a_683a_69abc95d93e2 -->|method| 3e617422_2360_595a_5a12_2c9e40cf3cb8
  d5702f7b_cc2a_77cc_9118_4ce84233b4e9["ChannelFuture()"]
  f941964b_67fa_416a_683a_69abc95d93e2 -->|method| d5702f7b_cc2a_77cc_9118_4ce84233b4e9
  43c80ac4_4cee_af50_5027_266b1d11e09a["ChannelPromise()"]
  f941964b_67fa_416a_683a_69abc95d93e2 -->|method| 43c80ac4_4cee_af50_5027_266b1d11e09a

Relationship Graph

Source Code

codec-http2/src/main/java/io/netty/handler/codec/http2/Http2ControlFrameLimitEncoder.java lines 30–108

final class Http2ControlFrameLimitEncoder extends DecoratingHttp2ConnectionEncoder {
    private static final InternalLogger logger = InternalLoggerFactory.getInstance(Http2ControlFrameLimitEncoder.class);
    private int outstandingControlFrames;

    private final int maxOutstandingControlFrames;
    private final ChannelFutureListener outstandingControlFramesListener = f-> outstandingControlFrames--;
    private Http2LifecycleManager lifecycleManager;
    private boolean limitReached;

    Http2ControlFrameLimitEncoder(Http2ConnectionEncoder delegate, int maxOutstandingControlFrames) {
        super(delegate);
        this.maxOutstandingControlFrames = ObjectUtil.checkPositive(maxOutstandingControlFrames,
                "maxOutstandingControlFrames");
    }

    @Override
    public void lifecycleManager(Http2LifecycleManager lifecycleManager) {
        this.lifecycleManager = lifecycleManager;
        super.lifecycleManager(lifecycleManager);
    }

    @Override
    public ChannelFuture writeSettingsAck(ChannelHandlerContext ctx, ChannelPromise promise) {
        ChannelPromise newPromise = handleOutstandingControlFrames(ctx, promise);
        if (newPromise == null) {
            return promise;
        }
        return super.writeSettingsAck(ctx, newPromise);
    }

    @Override
    public ChannelFuture writePing(ChannelHandlerContext ctx, boolean ack, long data, ChannelPromise promise) {
        // Only apply the limit to ping acks.
        if (ack) {
            ChannelPromise newPromise = handleOutstandingControlFrames(ctx, promise);
            if (newPromise == null) {
                return promise;
            }
            return super.writePing(ctx, ack, data, newPromise);
        }
        return super.writePing(ctx, ack, data, promise);
    }

    @Override
    public ChannelFuture writeRstStream(
            ChannelHandlerContext ctx, int streamId, long errorCode, ChannelPromise promise) {
        ChannelPromise newPromise = handleOutstandingControlFrames(ctx, promise);
        if (newPromise == null) {
            return promise;
        }
        return super.writeRstStream(ctx, streamId, errorCode, newPromise);
    }

    private ChannelPromise handleOutstandingControlFrames(ChannelHandlerContext ctx, ChannelPromise promise) {
        if (!limitReached) {
            if (outstandingControlFrames == maxOutstandingControlFrames) {
                // Let's try to flush once as we may be able to flush some of the control frames.
                ctx.flush();
            }
            if (outstandingControlFrames == maxOutstandingControlFrames) {
                limitReached = true;
                Http2Exception exception = Http2Exception.connectionError(Http2Error.ENHANCE_YOUR_CALM,
                        "Maximum number %d of outstanding control frames reached", maxOutstandingControlFrames);
                logger.info("{} Maximum number {} of outstanding control frames reached, closing channel.",
                        ctx.channel(), maxOutstandingControlFrames, exception);

                // First notify the Http2LifecycleManager and then close the connection.
                lifecycleManager.onError(ctx, true, exception);
                ctx.close();
            }
            outstandingControlFrames++;

            // We did not reach the limit yet, add the listener to decrement the number of outstanding control frames
            // once the promise was completed
            return promise.unvoid().addListener(outstandingControlFramesListener);
        }
        return promise;
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free