Home / Class/ ChannelReadHandler Class — netty Architecture

ChannelReadHandler Class — netty Architecture

Architecture documentation for the ChannelReadHandler class in LocalChannelTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  03969917_60dc_0ba6_a8df_e1a08c81b0f8["ChannelReadHandler"]
  08ebe769_61fc_27b6_2445_25670081be74["LocalChannelTest.java"]
  03969917_60dc_0ba6_a8df_e1a08c81b0f8 -->|defined in| 08ebe769_61fc_27b6_2445_25670081be74
  5b2d9136_7a5a_b6bb_cfbc_ebeb20c2e2ec["ChannelReadHandler()"]
  03969917_60dc_0ba6_a8df_e1a08c81b0f8 -->|method| 5b2d9136_7a5a_b6bb_cfbc_ebeb20c2e2ec
  8088efe8_c29f_fb7e_c0b6_5eeb1a6637f1["channelActive()"]
  03969917_60dc_0ba6_a8df_e1a08c81b0f8 -->|method| 8088efe8_c29f_fb7e_c0b6_5eeb1a6637f1
  2fe4250e_1e7d_5c4f_5951_b92475ad40e0["channelRead()"]
  03969917_60dc_0ba6_a8df_e1a08c81b0f8 -->|method| 2fe4250e_1e7d_5c4f_5951_b92475ad40e0
  75f6b91d_1b44_ecad_973f_85b5a2d36fe5["channelReadComplete()"]
  03969917_60dc_0ba6_a8df_e1a08c81b0f8 -->|method| 75f6b91d_1b44_ecad_973f_85b5a2d36fe5
  682f5263_0b7f_955e_78f4_bc584d494eaa["exceptionCaught()"]
  03969917_60dc_0ba6_a8df_e1a08c81b0f8 -->|method| 682f5263_0b7f_955e_78f4_bc584d494eaa

Relationship Graph

Source Code

transport/src/test/java/io/netty/channel/local/LocalChannelTest.java lines 1198–1253

    private static final class ChannelReadHandler extends ChannelInboundHandlerAdapter {

        private final CountDownLatch latch;
        private final boolean autoRead;
        private int read;

        ChannelReadHandler(CountDownLatch latch, boolean autoRead) {
            this.latch = latch;
            this.autoRead = autoRead;
        }

        @Override
        public void channelActive(ChannelHandlerContext ctx) {
            if (!autoRead) {
                ctx.read();
            }
            ctx.fireChannelActive();
        }

        @Override
        public void channelRead(final ChannelHandlerContext ctx, Object msg) {
            assertEquals(0, read);
            read++;
            ctx.fireChannelRead(msg);
        }

        @Override
        public void channelReadComplete(final ChannelHandlerContext ctx) {
            assertEquals(1, read);
            latch.countDown();
            if (latch.getCount() > 0) {
                if (!autoRead) {
                    // The read will be scheduled 100ms in the future to ensure we not receive any
                    // channelRead calls in the meantime.
                    ctx.executor().schedule(new Runnable() {
                        @Override
                        public void run() {
                            read = 0;
                            ctx.read();
                        }
                    }, 100, TimeUnit.MILLISECONDS);
                } else {
                    read = 0;
                }
            } else {
                read = 0;
            }
            ctx.fireChannelReadComplete();
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
            ctx.fireExceptionCaught(cause);
            ctx.close();
        }
    }

Frequently Asked Questions

What is the ChannelReadHandler class?
ChannelReadHandler is a class in the netty codebase, defined in transport/src/test/java/io/netty/channel/local/LocalChannelTest.java.
Where is ChannelReadHandler defined?
ChannelReadHandler is defined in transport/src/test/java/io/netty/channel/local/LocalChannelTest.java at line 1198.

Analyze Your Own Codebase

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

Try Supermodel Free