EchoHandler Class — netty Architecture
Architecture documentation for the EchoHandler class in QuicChannelEchoTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 6fffe389_9577_5718_7786_cbe035878b6a["EchoHandler"] 4b2da30c_3898_7e2f_23f4_62545543f3c8["QuicChannelEchoTest.java"] 6fffe389_9577_5718_7786_cbe035878b6a -->|defined in| 4b2da30c_3898_7e2f_23f4_62545543f3c8 dc18ab1e_9653_f54e_3875_3668a65b6f02["EchoHandler()"] 6fffe389_9577_5718_7786_cbe035878b6a -->|method| dc18ab1e_9653_f54e_3875_3668a65b6f02 3bdf8186_a75e_d952_2d7e_c9f164011b42["channelRegistered()"] 6fffe389_9577_5718_7786_cbe035878b6a -->|method| 3bdf8186_a75e_d952_2d7e_c9f164011b42 e1045f62_6ee7_c954_17a5_31211f40f0cd["channelActive()"] 6fffe389_9577_5718_7786_cbe035878b6a -->|method| e1045f62_6ee7_c954_17a5_31211f40f0cd 5638257c_8ad4_bfaa_2733_4901d77c2f45["channelRead0()"] 6fffe389_9577_5718_7786_cbe035878b6a -->|method| 5638257c_8ad4_bfaa_2733_4901d77c2f45 8f952ffb_218c_70bf_ea7f_e5e10f16983e["channelReadComplete()"] 6fffe389_9577_5718_7786_cbe035878b6a -->|method| 8f952ffb_218c_70bf_ea7f_e5e10f16983e 73202fd4_b52f_2617_b00d_9e4461508372["exceptionCaught()"] 6fffe389_9577_5718_7786_cbe035878b6a -->|method| 73202fd4_b52f_2617_b00d_9e4461508372
Relationship Graph
Source Code
codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicChannelEchoTest.java lines 365–439
private class EchoHandler extends SimpleChannelInboundHandler<ByteBuf> {
private final boolean server;
private final boolean autoRead;
private final ByteBufAllocator allocator;
volatile Channel channel;
final AtomicReference<Throwable> exception = new AtomicReference<>();
volatile int counter;
EchoHandler(boolean server, boolean autoRead, ByteBufAllocator allocator) {
this.server = server;
this.autoRead = autoRead;
this.allocator = allocator;
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) {
ctx.channel().config().setAutoRead(autoRead);
setAllocator(ctx.channel(), allocator);
ctx.fireChannelRegistered();
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
channel = ctx.channel();
QuicStreamChannel channel = (QuicStreamChannel) ctx.channel();
assertEquals(QuicStreamType.BIDIRECTIONAL, channel.type());
if (channel.isLocalCreated()) {
// Server starts with 1, client with 0
assertEquals(server ? 1 : 0, channel.streamId());
} else {
// Server starts with 1, client with 0
assertEquals(server ? 0 : 1, channel.streamId());
}
if (!autoRead) {
ctx.read();
}
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf in) {
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]);
}
if (!((QuicStreamChannel) ctx.channel()).isLocalCreated()) {
channel.write(Unpooled.wrappedBuffer(actual));
}
counter += actual.length;
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
try {
ctx.flush();
} finally {
if (!autoRead) {
ctx.read();
}
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx,
Throwable cause) {
if (exception.compareAndSet(null, cause)) {
cause.printStackTrace();
ctx.close();
}
}
}
Source
Frequently Asked Questions
What is the EchoHandler class?
EchoHandler is a class in the netty codebase, defined in codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicChannelEchoTest.java.
Where is EchoHandler defined?
EchoHandler is defined in codec-native-quic/src/test/java/io/netty/handler/codec/quic/QuicChannelEchoTest.java at line 365.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free