AutoCloseFalseLeader Class — netty Architecture
Architecture documentation for the AutoCloseFalseLeader class in SocketHalfClosedTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 75d25e1f_d173_eba1_2e00_bdb589050562["AutoCloseFalseLeader"] f83511ba_39cb_73dd_453f_92c6a5fe10ae["SocketHalfClosedTest.java"] 75d25e1f_d173_eba1_2e00_bdb589050562 -->|defined in| f83511ba_39cb_73dd_453f_92c6a5fe10ae 7b9ca86a_3a2b_7af1_f60e_b6c7ea429e62["AutoCloseFalseLeader()"] 75d25e1f_d173_eba1_2e00_bdb589050562 -->|method| 7b9ca86a_3a2b_7af1_f60e_b6c7ea429e62 e10e4eef_7517_beb9_006a_70828f05ea78["channelActive()"] 75d25e1f_d173_eba1_2e00_bdb589050562 -->|method| e10e4eef_7517_beb9_006a_70828f05ea78 048f4f70_aab1_9685_54cc_9d10fe8b0e4c["channelRead0()"] 75d25e1f_d173_eba1_2e00_bdb589050562 -->|method| 048f4f70_aab1_9685_54cc_9d10fe8b0e4c ed63ea02_ba7b_766c_f519_7df130ca8449["userEventTriggered()"] 75d25e1f_d173_eba1_2e00_bdb589050562 -->|method| ed63ea02_ba7b_766c_f519_7df130ca8449 e02ca8f5_bf2c_16d2_4875_90f8bfa4871e["channelInactive()"] 75d25e1f_d173_eba1_2e00_bdb589050562 -->|method| e02ca8f5_bf2c_16d2_4875_90f8bfa4871e 1b353293_269e_5350_bac6_ca825553573d["exceptionCaught()"] 75d25e1f_d173_eba1_2e00_bdb589050562 -->|method| 1b353293_269e_5350_bac6_ca825553573d 52f023a0_c81e_bc99_523a_b23033bffdf0["checkPrematureClose()"] 75d25e1f_d173_eba1_2e00_bdb589050562 -->|method| 52f023a0_c81e_bc99_523a_b23033bffdf0
Relationship Graph
Source Code
testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketHalfClosedTest.java lines 604–672
private static final class AutoCloseFalseLeader extends SimpleChannelInboundHandler<ByteBuf> {
private final int expectedBytes;
private final CountDownLatch followerCloseLatch;
private final CountDownLatch doneLatch;
private final AtomicReference<Throwable> causeRef;
private int bytesRead;
boolean seenOutputShutdown;
AutoCloseFalseLeader(int expectedBytes, CountDownLatch followerCloseLatch, CountDownLatch doneLatch,
AtomicReference<Throwable> causeRef) {
this.expectedBytes = expectedBytes;
this.followerCloseLatch = followerCloseLatch;
this.doneLatch = doneLatch;
this.causeRef = causeRef;
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
ByteBuf buf = ctx.alloc().buffer(expectedBytes);
buf.writerIndex(buf.writerIndex() + expectedBytes);
ctx.writeAndFlush(buf.retainedDuplicate());
// We wait here to ensure that we write before we have a chance to process the outbound
// shutdown event.
followerCloseLatch.await();
// This write should fail, but we should still be allowed to read the peer's data
ctx.writeAndFlush(buf).addListener(future -> {
if (future.cause() == null) {
causeRef.set(new IllegalStateException("second write should have failed!"));
doneLatch.countDown();
}
});
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
bytesRead += msg.readableBytes();
if (bytesRead >= expectedBytes) {
doneLatch.countDown();
}
}
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt instanceof ChannelOutputShutdownEvent) {
seenOutputShutdown = true;
doneLatch.countDown();
}
}
@Override
public void channelInactive(ChannelHandlerContext ctx) {
checkPrematureClose();
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
ctx.close();
checkPrematureClose();
}
private void checkPrematureClose() {
if (bytesRead < expectedBytes || !seenOutputShutdown) {
causeRef.set(new IllegalStateException("leader premature close"));
doneLatch.countDown();
}
}
}
Source
Frequently Asked Questions
What is the AutoCloseFalseLeader class?
AutoCloseFalseLeader is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketHalfClosedTest.java.
Where is AutoCloseFalseLeader defined?
AutoCloseFalseLeader is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketHalfClosedTest.java at line 604.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free