Home / Function/ channelRead() — netty Function Reference

channelRead() — netty Function Reference

Architecture documentation for the channelRead() function in ByteToMessageDecoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  a22162a0_4ee0_09dc_f31c_e78971c0c57d["channelRead()"]
  efe4959f_3296_dbb1_4a4b_76b9d7ccec55["ByteToMessageDecoder"]
  a22162a0_4ee0_09dc_f31c_e78971c0c57d -->|defined in| efe4959f_3296_dbb1_4a4b_76b9d7ccec55
  8a34ecfc_930b_5500_f979_83efbe7a340e["callDecode()"]
  a22162a0_4ee0_09dc_f31c_e78971c0c57d -->|calls| 8a34ecfc_930b_5500_f979_83efbe7a340e
  a2b41b20_4228_5c5c_610d_6731a6923ad0["decode()"]
  a22162a0_4ee0_09dc_f31c_e78971c0c57d -->|calls| a2b41b20_4228_5c5c_610d_6731a6923ad0
  2aa120bb_dbc1_13a7_0bbd_6e8fb49ab322["discardSomeReadBytes()"]
  a22162a0_4ee0_09dc_f31c_e78971c0c57d -->|calls| 2aa120bb_dbc1_13a7_0bbd_6e8fb49ab322
  07d205b6_501b_721f_b872_e8e378f3c54d["fireChannelRead()"]
  a22162a0_4ee0_09dc_f31c_e78971c0c57d -->|calls| 07d205b6_501b_721f_b872_e8e378f3c54d
  style a22162a0_4ee0_09dc_f31c_e78971c0c57d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-base/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java lines 285–341

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object input) throws Exception {
        if (decodeState == STATE_INIT) {
            do {
                if (input instanceof ByteBuf) {
                    selfFiredChannelRead = true;
                    CodecOutputList out = CodecOutputList.newInstance();
                    try {
                        first = cumulation == null;
                        cumulation = cumulator.cumulate(ctx.alloc(),
                                first ? EMPTY_BUFFER : cumulation, (ByteBuf) input);
                        callDecode(ctx, cumulation, out);
                    } catch (DecoderException e) {
                        throw e;
                    } catch (Exception e) {
                        throw new DecoderException(e);
                    } finally {
                        try {
                            if (cumulation != null && !cumulation.isReadable()) {
                                numReads = 0;
                                try {
                                    cumulation.release();
                                } catch (IllegalReferenceCountException e) {
                                    //noinspection ThrowFromFinallyBlock
                                    throw new IllegalReferenceCountException(
                                            getClass().getSimpleName() +
                                                    "#decode() might have released its input buffer, " +
                                                    "or passed it down the pipeline without a retain() call, " +
                                                    "which is not allowed.", e);
                                }
                                cumulation = null;
                            } else if (++numReads >= discardAfterReads) {
                                // We did enough reads already try to discard some bytes, so we not risk to see a OOME.
                                // See https://github.com/netty/netty/issues/4275
                                numReads = 0;
                                discardSomeReadBytes();
                            }

                            int size = out.size();
                            firedChannelRead |= out.insertSinceRecycled();
                            fireChannelRead(ctx, out, size);
                        } finally {
                            out.recycle();
                        }
                    }
                } else {
                    ctx.fireChannelRead(input);
                }
            } while (inputMessages != null && (input = inputMessages.poll()) != null);
        } else {
            // Reentrant call. Bail out here and let original call process our message.
            if (inputMessages == null) {
                inputMessages = new ArrayDeque<>(2);
            }
            inputMessages.offer(input);
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does channelRead() do?
channelRead() is a function in the netty codebase, defined in codec-base/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java.
Where is channelRead() defined?
channelRead() is defined in codec-base/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java at line 285.
What does channelRead() call?
channelRead() calls 4 function(s): callDecode, decode, discardSomeReadBytes, fireChannelRead.

Analyze Your Own Codebase

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

Try Supermodel Free