AutoCloseFalseFollower Class — netty Architecture
Architecture documentation for the AutoCloseFalseFollower class in SocketHalfClosedTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD a8155a97_c3e1_5a97_3f5c_f598bd3af9fe["AutoCloseFalseFollower"] f83511ba_39cb_73dd_453f_92c6a5fe10ae["SocketHalfClosedTest.java"] a8155a97_c3e1_5a97_3f5c_f598bd3af9fe -->|defined in| f83511ba_39cb_73dd_453f_92c6a5fe10ae 8c376794_59fb_f352_c408_9a1d36d36c69["AutoCloseFalseFollower()"] a8155a97_c3e1_5a97_3f5c_f598bd3af9fe -->|method| 8c376794_59fb_f352_c408_9a1d36d36c69 872a8925_a278_d5d4_1c4a_48dcd735f74e["channelInactive()"] a8155a97_c3e1_5a97_3f5c_f598bd3af9fe -->|method| 872a8925_a278_d5d4_1c4a_48dcd735f74e 9f0d148d_19fe_6f26_b8b9_17ac45fb4050["exceptionCaught()"] a8155a97_c3e1_5a97_3f5c_f598bd3af9fe -->|method| 9f0d148d_19fe_6f26_b8b9_17ac45fb4050 d339b74f_e58e_53e2_a91c_27d2ff1f05d5["channelRead0()"] a8155a97_c3e1_5a97_3f5c_f598bd3af9fe -->|method| d339b74f_e58e_53e2_a91c_27d2ff1f05d5 9158c171_4fc5_0e4a_4e16_c1f816313ca6["checkPrematureClose()"] a8155a97_c3e1_5a97_3f5c_f598bd3af9fe -->|method| 9158c171_4fc5_0e4a_4e16_c1f816313ca6
Relationship Graph
Source Code
testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketHalfClosedTest.java lines 546–602
private static final class AutoCloseFalseFollower extends SimpleChannelInboundHandler<ByteBuf> {
private final int expectedBytes;
private final CountDownLatch followerCloseLatch;
private final CountDownLatch doneLatch;
private final AtomicReference<Throwable> causeRef;
private int bytesRead;
AutoCloseFalseFollower(int expectedBytes, CountDownLatch followerCloseLatch, CountDownLatch doneLatch,
AtomicReference<Throwable> causeRef) {
this.expectedBytes = expectedBytes;
this.followerCloseLatch = followerCloseLatch;
this.doneLatch = doneLatch;
this.causeRef = causeRef;
}
@Override
public void channelInactive(ChannelHandlerContext ctx) {
checkPrematureClose();
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
ctx.close();
checkPrematureClose();
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
bytesRead += msg.readableBytes();
if (bytesRead >= expectedBytes) {
// We write a reply and immediately close our end of the socket.
ByteBuf buf = ctx.alloc().buffer(expectedBytes);
buf.writerIndex(buf.writerIndex() + expectedBytes);
ctx.writeAndFlush(buf).addListener(future ->
ctx.close().addListener(f -> {
// This is a bit racy but there is no better way how to handle this in Java11.
// The problem is that on close() the underlying FD will not actually be closed directly
// but the close will be done after the Selector did process all events. Because of
// this we will need to give it a bit time to ensure the FD is actual closed before we
// count down the latch and try to write.
ctx.executor().schedule(new Runnable() {
@Override
public void run() {
followerCloseLatch.countDown();
}
}, 200, MILLISECONDS);
}));
}
}
private void checkPrematureClose() {
if (bytesRead < expectedBytes) {
causeRef.set(new IllegalStateException("follower premature close"));
doneLatch.countDown();
}
}
}
Source
Frequently Asked Questions
What is the AutoCloseFalseFollower class?
AutoCloseFalseFollower is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketHalfClosedTest.java.
Where is AutoCloseFalseFollower defined?
AutoCloseFalseFollower is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketHalfClosedTest.java at line 546.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free