ReuseFdHandler Class — netty Architecture
Architecture documentation for the ReuseFdHandler class in AbstractSocketReuseFdTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD b1f99365_b9c8_a7b8_4472_f530b239a199["ReuseFdHandler"] 27781ab1_b241_2e7d_8861_817581c95ca8["AbstractSocketReuseFdTest.java"] b1f99365_b9c8_a7b8_4472_f530b239a199 -->|defined in| 27781ab1_b241_2e7d_8861_817581c95ca8 ec82d613_98f5_5ac4_3311_97ad7b3b3931["ReuseFdHandler()"] b1f99365_b9c8_a7b8_4472_f530b239a199 -->|method| ec82d613_98f5_5ac4_3311_97ad7b3b3931 8d342941_d1ef_de20_a31e_f3849f6bfc1b["channelActive()"] b1f99365_b9c8_a7b8_4472_f530b239a199 -->|method| 8d342941_d1ef_de20_a31e_f3849f6bfc1b 5e3644a7_f1fa_7db2_ea8f_3231b223df87["channelRead()"] b1f99365_b9c8_a7b8_4472_f530b239a199 -->|method| 5e3644a7_f1fa_7db2_ea8f_3231b223df87 28c044b1_6430_d6f5_9ab9_96e1d0b14119["exceptionCaught()"] b1f99365_b9c8_a7b8_4472_f530b239a199 -->|method| 28c044b1_6430_d6f5_9ab9_96e1d0b14119 17adb25a_1493_e740_a61b_e18f8b5df7b0["channelInactive()"] b1f99365_b9c8_a7b8_4472_f530b239a199 -->|method| 17adb25a_1493_e740_a61b_e18f8b5df7b0
Relationship Graph
Source Code
testsuite/src/main/java/io/netty/testsuite/transport/socket/AbstractSocketReuseFdTest.java lines 119–185
static class ReuseFdHandler extends ChannelInboundHandlerAdapter {
private static final String EXPECTED_PAYLOAD = "payload";
private final Promise<Void> donePromise;
private final AtomicInteger remaining;
private final boolean client;
volatile Channel channel;
final AtomicReference<Throwable> globalException;
final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
final StringBuilder received = new StringBuilder();
ReuseFdHandler(
boolean client,
AtomicReference<Throwable> globalException,
AtomicInteger remaining,
Promise<Void> donePromise) {
this.client = client;
this.globalException = globalException;
this.remaining = remaining;
this.donePromise = donePromise;
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
channel = ctx.channel();
if (client) {
ctx.writeAndFlush(Unpooled.copiedBuffer(EXPECTED_PAYLOAD, CharsetUtil.US_ASCII));
}
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof ByteBuf) {
ByteBuf buf = (ByteBuf) msg;
received.append(buf.toString(CharsetUtil.US_ASCII));
buf.release();
if (received.toString().equals(EXPECTED_PAYLOAD)) {
if (client) {
ctx.close();
} else {
ctx.writeAndFlush(Unpooled.copiedBuffer(EXPECTED_PAYLOAD, CharsetUtil.US_ASCII));
}
}
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
if (exception.compareAndSet(null, cause)) {
donePromise.tryFailure(new IllegalStateException("exceptionCaught: " + ctx.channel(), cause));
ctx.close();
}
globalException.compareAndSet(null, cause);
}
@Override
public void channelInactive(ChannelHandlerContext ctx) {
if (remaining.decrementAndGet() == 0) {
if (received.toString().equals(EXPECTED_PAYLOAD)) {
donePromise.setSuccess(null);
} else {
donePromise.tryFailure(new Exception("Unexpected payload:" + received));
}
}
}
}
Defined In
Source
Frequently Asked Questions
What is the ReuseFdHandler class?
ReuseFdHandler is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/AbstractSocketReuseFdTest.java.
Where is ReuseFdHandler defined?
ReuseFdHandler is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/AbstractSocketReuseFdTest.java at line 119.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free