Home / Class/ Http2MultiplexCodec Class — netty Architecture

Http2MultiplexCodec Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  a7ac469b_ce05_746a_3b73_34450541872b["Http2MultiplexCodec"]
  f174a7ac_d482_a233_ce3f_afc5fecf5872["Http2MultiplexCodec.java"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|defined in| f174a7ac_d482_a233_ce3f_afc5fecf5872
  2dfbe6bf_f325_77b9_8c5c_864304507997["Http2MultiplexCodec()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| 2dfbe6bf_f325_77b9_8c5c_864304507997
  86274434_994f_89d5_0c83_8984b1f64446["onHttpClientUpgrade()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| 86274434_994f_89d5_0c83_8984b1f64446
  a5c9170b_2d23_93a0_6b86_4eadc5705360["handlerAdded0()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| a5c9170b_2d23_93a0_6b86_4eadc5705360
  17c57755_c573_691d_bdf8_018b5cff6aa8["handlerRemoved0()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| 17c57755_c573_691d_bdf8_018b5cff6aa8
  32b10e6c_b784_372e_860b_7e037423e94b["onHttp2Frame()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| 32b10e6c_b784_372e_860b_7e037423e94b
  7c2b2a8f_41e8_7ac2_1687_1d9ce90d5bea["onHttp2StreamStateChanged()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| 7c2b2a8f_41e8_7ac2_1687_1d9ce90d5bea
  7a9c6c63_ddeb_5b41_e9f6_51cf62398f32["Http2StreamChannel()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| 7a9c6c63_ddeb_5b41_e9f6_51cf62398f32
  e5d576e9_696e_d77d_46ca_3e748084d1e4["onHttp2FrameStreamException()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| e5d576e9_696e_d77d_46ca_3e748084d1e4
  7a9be5dc_4230_32da_7f05_59f39e1e3d2c["onHttp2GoAwayFrame()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| 7a9be5dc_4230_32da_7f05_59f39e1e3d2c
  78cb2a42_5bff_2a57_7359_230af6443313["channelReadComplete()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| 78cb2a42_5bff_2a57_7359_230af6443313
  a4b14126_9c21_7172_e4e0_4c793e70994c["processPendingReadCompleteQueue()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| a4b14126_9c21_7172_e4e0_4c793e70994c
  15844237_ed54_ad21_fa95_5b3c70083dd9["channelRead()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| 15844237_ed54_ad21_fa95_5b3c70083dd9
  4d17d6b7_da65_3de6_fcc7_ddb712a714fd["channelWritabilityChanged()"]
  a7ac469b_ce05_746a_3b73_34450541872b -->|method| 4d17d6b7_da65_3de6_fcc7_ddb712a714fd

Relationship Graph

Source Code

codec-http2/src/main/java/io/netty/handler/codec/http2/Http2MultiplexCodec.java lines 88–344

@Deprecated
public class Http2MultiplexCodec extends Http2FrameCodec {

    private final ChannelHandler inboundStreamHandler;
    private final ChannelHandler upgradeStreamHandler;
    private final Queue<AbstractHttp2StreamChannel> readCompletePendingQueue =
            new MaxCapacityQueue<AbstractHttp2StreamChannel>(new ArrayDeque<AbstractHttp2StreamChannel>(8),
                    // Choose 100 which is what is used most of the times as default.
                    Http2CodecUtil.SMALLEST_MAX_CONCURRENT_STREAMS);

    private boolean parentReadInProgress;
    private int idCount;

    // Need to be volatile as accessed from within the Http2MultiplexCodecStreamChannel in a multi-threaded fashion.
    volatile ChannelHandlerContext ctx;

    Http2MultiplexCodec(Http2ConnectionEncoder encoder,
                        Http2ConnectionDecoder decoder,
                        Http2Settings initialSettings,
                        ChannelHandler inboundStreamHandler,
                        ChannelHandler upgradeStreamHandler, boolean decoupleCloseAndGoAway, boolean flushPreface) {
        super(encoder, decoder, initialSettings, decoupleCloseAndGoAway, flushPreface);
        this.inboundStreamHandler = inboundStreamHandler;
        this.upgradeStreamHandler = upgradeStreamHandler;
    }

    @Override
    public void onHttpClientUpgrade() throws Http2Exception {
        // We must have an upgrade handler or else we can't handle the stream
        if (upgradeStreamHandler == null) {
            throw connectionError(INTERNAL_ERROR, "Client is misconfigured for upgrade requests");
        }
        // Creates the Http2Stream in the Connection.
        super.onHttpClientUpgrade();
    }

    @Override
    public final void handlerAdded0(ChannelHandlerContext ctx) throws Exception {
        if (ctx.executor() != ctx.channel().eventLoop()) {
            throw new IllegalStateException("EventExecutor must be EventLoop of Channel");
        }
        this.ctx = ctx;
    }

    @Override
    public final void handlerRemoved0(ChannelHandlerContext ctx) throws Exception {
        super.handlerRemoved0(ctx);

        readCompletePendingQueue.clear();
    }

    @Override
    final void onHttp2Frame(ChannelHandlerContext ctx, Http2Frame frame) {
        if (frame instanceof Http2StreamFrame) {
            Http2StreamFrame msg = (Http2StreamFrame) frame;
            AbstractHttp2StreamChannel channel  = (AbstractHttp2StreamChannel)
                    ((DefaultHttp2FrameStream) msg.stream()).attachment;
            channel.fireChildRead(msg);
            return;
        }
        if (frame instanceof Http2GoAwayFrame) {
            onHttp2GoAwayFrame(ctx, (Http2GoAwayFrame) frame);
        }
        // Send frames down the pipeline
        ctx.fireChannelRead(frame);
    }

    @Override
    final void onHttp2StreamStateChanged(ChannelHandlerContext ctx, DefaultHttp2FrameStream stream) {
        switch (stream.state()) {
            case HALF_CLOSED_LOCAL:
                if (stream.id() != HTTP_UPGRADE_STREAM_ID) {
                    // Ignore everything which was not caused by an upgrade
                    break;
                }
                // fall-through
            case HALF_CLOSED_REMOTE:
                // fall-through
            case OPEN:
                if (stream.attachment != null) {
                    // ignore if child channel was already created.

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free