EchoHandler Class — netty Architecture
Architecture documentation for the EchoHandler class in SocketEchoTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 3749a47f_5fb1_e195_228f_ad68473b86f5["EchoHandler"] 6407e4ab_9243_85a6_d137_db3483b867e8["SocketEchoTest.java"] 3749a47f_5fb1_e195_228f_ad68473b86f5 -->|defined in| 6407e4ab_9243_85a6_d137_db3483b867e8 f00838f1_bd95_3f2f_039a_8da620627a51["EchoHandler()"] 3749a47f_5fb1_e195_228f_ad68473b86f5 -->|method| f00838f1_bd95_3f2f_039a_8da620627a51 b0180ed4_40c5_513f_3726_2b8032f34766["channelActive()"] 3749a47f_5fb1_e195_228f_ad68473b86f5 -->|method| b0180ed4_40c5_513f_3726_2b8032f34766 25d1201e_2f24_0096_c709_2fe3d9d74eaf["channelRead0()"] 3749a47f_5fb1_e195_228f_ad68473b86f5 -->|method| 25d1201e_2f24_0096_c709_2fe3d9d74eaf dae179f4_bad2_86f8_2d67_5e0714a6d8c1["channelReadComplete()"] 3749a47f_5fb1_e195_228f_ad68473b86f5 -->|method| dae179f4_bad2_86f8_2d67_5e0714a6d8c1 9cef9c21_6ba3_7d89_c1a2_b28bf813f329["exceptionCaught()"] 3749a47f_5fb1_e195_228f_ad68473b86f5 -->|method| 9cef9c21_6ba3_7d89_c1a2_b28bf813f329
Relationship Graph
Source Code
testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketEchoTest.java lines 254–311
private static class EchoHandler extends SimpleChannelInboundHandler<ByteBuf> {
private final boolean autoRead;
volatile Channel channel;
final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
volatile int counter;
EchoHandler(boolean autoRead) {
this.autoRead = autoRead;
}
@Override
public void channelActive(ChannelHandlerContext ctx)
throws Exception {
channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
}
@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.write(randomBufferType(channel.alloc(), actual, 0, actual.length));
}
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
try {
ctx.flush();
} finally {
if (!autoRead) {
ctx.read();
}
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx,
Throwable cause) throws Exception {
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 testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketEchoTest.java.
Where is EchoHandler defined?
EchoHandler is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketEchoTest.java at line 254.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free