Home / Class/ EchoHandler Class — netty Architecture

EchoHandler Class — netty Architecture

Architecture documentation for the EchoHandler class in SctpEchoTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  11e0fb23_27b6_3742_38d9_f1300b3170cc["EchoHandler"]
  b6ef1bf0_ab1c_3df6_2c8c_1dd85440f2b6["SctpEchoTest.java"]
  11e0fb23_27b6_3742_38d9_f1300b3170cc -->|defined in| b6ef1bf0_ab1c_3df6_2c8c_1dd85440f2b6
  8f9cab8d_c9a7_c7cc_29b3_c2be0cddea6f["channelActive()"]
  11e0fb23_27b6_3742_38d9_f1300b3170cc -->|method| 8f9cab8d_c9a7_c7cc_29b3_c2be0cddea6f
  4efdecc1_37b1_7a22_5b06_a28327dcd4d2["channelRead0()"]
  11e0fb23_27b6_3742_38d9_f1300b3170cc -->|method| 4efdecc1_37b1_7a22_5b06_a28327dcd4d2
  8066f2ab_0de6_ab83_7098_945e188f1e9e["exceptionCaught()"]
  11e0fb23_27b6_3742_38d9_f1300b3170cc -->|method| 8066f2ab_0de6_ab83_7098_945e188f1e9e

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/sctp/SctpEchoTest.java lines 155–190

    private static class EchoHandler extends SimpleChannelInboundHandler<ByteBuf> {
        volatile Channel channel;
        final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
        volatile int counter;

        @Override
        public void channelActive(ChannelHandlerContext ctx) throws Exception {
            channel = ctx.channel();
        }

        @Override
        public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
            byte[] actual = new byte[in.readableBytes()];
            in.readBytes(actual);

            int lastIdx = counter;
            for (int i = 0; i < actual.length; i++) {
                assertEquals(data[i + lastIdx], actual[i]);
            }

            // Update the counter before calling write(...) as write could in theory trigger another channelRead(...)
            // which then would use the wrong lastIdx.
            counter += actual.length;

            if (channel.parent() != null) {
                channel.writeAndFlush(randomBufferType(channel.alloc(), actual, 0, actual.length));
            }
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            if (exception.compareAndSet(null, cause)) {
                ctx.close();
            }
        }
    }

Frequently Asked Questions

What is the EchoHandler class?
EchoHandler is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/sctp/SctpEchoTest.java.
Where is EchoHandler defined?
EchoHandler is defined in testsuite/src/main/java/io/netty/testsuite/transport/sctp/SctpEchoTest.java at line 155.

Analyze Your Own Codebase

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

Try Supermodel Free