Home / Class/ QuicCodecDispatcher Class — netty Architecture

QuicCodecDispatcher Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  550dceea_3958_0e89_1405_ee683da73397["QuicCodecDispatcher"]
  a14ebc00_41a1_b954_e2ee_6cef1b775b7b["QuicCodecDispatcher.java"]
  550dceea_3958_0e89_1405_ee683da73397 -->|defined in| a14ebc00_41a1_b954_e2ee_6cef1b775b7b
  de751f20_9da3_99d6_71ec_25eace95b434["QuicCodecDispatcher()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| de751f20_9da3_99d6_71ec_25eace95b434
  42e043d2_b07f_3953_95f6_882621319506["isSharable()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| 42e043d2_b07f_3953_95f6_882621319506
  b99c9c30_8611_5f76_7839_3df99f435379["handlerAdded()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| b99c9c30_8611_5f76_7839_3df99f435379
  8d23b345_4050_d240_3ec5_e6f36fd82f5e["handlerRemoved()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| 8d23b345_4050_d240_3ec5_e6f36fd82f5e
  0e711db4_2323_9b60_83ee_b0667227d32f["channelRead()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| 0e711db4_2323_9b60_83ee_b0667227d32f
  95d1ff13_107e_5366_e7f6_d5916dc4618a["channelReadComplete()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| 95d1ff13_107e_5366_e7f6_d5916dc4618a
  94e20dc2_3f57_0092_4278_0fcdf1ba00af["initChannel()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| 94e20dc2_3f57_0092_4278_0fcdf1ba00af
  899a505d_01d9_8f4d_237d_520e0f5fbaef["decodeIndex()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| 899a505d_01d9_8f4d_237d_520e0f5fbaef
  fdaf76e1_fbe7_e167_dea3_5a72683ffae5["ByteBuf()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| fdaf76e1_fbe7_e167_dea3_5a72683ffae5
  dcc7626f_cb03_ca66_d737_48297d2f901e["hasShortHeader()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| dcc7626f_cb03_ca66_d737_48297d2f901e
  b0dd8adc_e321_400e_f574_b7da98b23444["decodeIdx()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| b0dd8adc_e321_400e_f574_b7da98b23444
  595eae1c_8108_2e6b_7b26_c92f0a661df4["ByteBuffer()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| 595eae1c_8108_2e6b_7b26_c92f0a661df4
  c64f638f_d33c_8572_823e_04c094f49e75["QuicConnectionIdGenerator()"]
  550dceea_3958_0e89_1405_ee683da73397 -->|method| c64f638f_d33c_8572_823e_04c094f49e75

Relationship Graph

Source Code

codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicCodecDispatcher.java lines 51–325

public abstract class QuicCodecDispatcher extends ChannelInboundHandlerAdapter {
    // 20 is the max as per RFC.
    // See https://datatracker.ietf.org/doc/html/rfc9000#section-17.2
    private static final int MAX_LOCAL_CONNECTION_ID_LENGTH = 20;

    // Use a CopyOnWriteArrayList as modifications to the List should only happen during bootstrapping and teardown
    // of the channels.
    private final List<ChannelHandlerContextDispatcher> contextList = new CopyOnWriteArrayList<>();
    private final int localConnectionIdLength;

    /**
     * Create a new instance using the default connection id length.
     */
    protected QuicCodecDispatcher() {
        this(MAX_LOCAL_CONNECTION_ID_LENGTH);
    }

    /**
     * Create a new instance
     *
     * @param localConnectionIdLength   the local connection id length. This must be between 10 and 20.
     */
    protected QuicCodecDispatcher(int localConnectionIdLength) {
        // Let's use 10 as a minimum to ensure we still have some bytes left for randomness as we already use
        // 2 of the bytes to encode the index.
        this.localConnectionIdLength = ObjectUtil.checkInRange(localConnectionIdLength,
                10, MAX_LOCAL_CONNECTION_ID_LENGTH, "localConnectionIdLength");
    }

    @Override
    public final boolean isSharable() {
        return true;
    }

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

        ChannelHandlerContextDispatcher ctxDispatcher = new ChannelHandlerContextDispatcher(ctx);
        contextList.add(ctxDispatcher);
        int idx = contextList.indexOf(ctxDispatcher);
        try {
            QuicConnectionIdGenerator idGenerator = newIdGenerator((short) idx);
            initChannel(ctx.channel(), localConnectionIdLength, idGenerator);
        } catch (Exception e) {
            // Null out on exception and rethrow. We not remove the element as the indices need to be
            // stable.
            contextList.set(idx, null);
            throw e;
        }
    }

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

        for (int idx = 0; idx < contextList.size(); idx++) {
            ChannelHandlerContextDispatcher ctxDispatcher = contextList.get(idx);
            if (ctxDispatcher != null && ctxDispatcher.ctx.equals(ctx)) {
                // null out, so we can collect the ChannelHandlerContext that was stored in the List.
                contextList.set(idx, null);
                break;
            }
        }
    }

    @Override
    public final void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        DatagramPacket packet = (DatagramPacket) msg;
        ByteBuf connectionId = getDestinationConnectionId(packet.content(), localConnectionIdLength);
        if (connectionId != null) {
            int idx = decodeIndex(connectionId);
            if (contextList.size() > idx) {
                ChannelHandlerContextDispatcher selectedCtx = contextList.get(idx);
                if (selectedCtx != null) {
                    selectedCtx.fireChannelRead(msg);
                    return;
                }
            }
        }
        // We were not be-able to dispatch to a specific ChannelHandlerContext, just forward and let the

Frequently Asked Questions

What is the QuicCodecDispatcher class?
QuicCodecDispatcher is a class in the netty codebase, defined in codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicCodecDispatcher.java.
Where is QuicCodecDispatcher defined?
QuicCodecDispatcher is defined in codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicCodecDispatcher.java at line 51.

Analyze Your Own Codebase

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

Try Supermodel Free