testChannelReRegisterRead() — netty Function Reference
Architecture documentation for the testChannelReRegisterRead() function in NioSocketChannelTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 5c181905_1c1d_7eff_38c5_4a59d5e9c413["testChannelReRegisterRead()"] 6562d13f_0b72_6889_33f9_c7688a2de3fc["NioSocketChannelTest"] 5c181905_1c1d_7eff_38c5_4a59d5e9c413 -->|defined in| 6562d13f_0b72_6889_33f9_c7688a2de3fc 0a1856aa_de13_a9cc_d43e_9a8f7ec33dbe["testChannelReRegisterReadSameEventLoop()"] 0a1856aa_de13_a9cc_d43e_9a8f7ec33dbe -->|calls| 5c181905_1c1d_7eff_38c5_4a59d5e9c413 07468fee_4564_c65d_7aca_44bcc62707ef["testChannelReRegisterReadDifferentEventLoop()"] 07468fee_4564_c65d_7aca_44bcc62707ef -->|calls| 5c181905_1c1d_7eff_38c5_4a59d5e9c413 style 5c181905_1c1d_7eff_38c5_4a59d5e9c413 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelTest.java lines 177–249
private static void testChannelReRegisterRead(final boolean sameEventLoop) throws Exception {
EventLoopGroup group = new MultiThreadIoEventLoopGroup(2, NioIoHandler.newFactory());
final CountDownLatch latch = new CountDownLatch(1);
// Just some random bytes
byte[] bytes = new byte[1024];
ThreadLocalRandom.current().nextBytes(bytes);
Channel sc = null;
Channel cc = null;
ServerBootstrap b = new ServerBootstrap();
try {
b.group(group)
.channel(NioServerSocketChannel.class)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new SimpleChannelInboundHandler<ByteBuf>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf byteBuf) {
// We was able to read something from the Channel after reregister.
latch.countDown();
}
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
final EventLoop loop = group.next();
if (sameEventLoop) {
deregister(ctx, loop);
} else {
loop.execute(new Runnable() {
@Override
public void run() {
deregister(ctx, loop);
}
});
}
}
private void deregister(ChannelHandlerContext ctx, final EventLoop loop) {
// As soon as the channel becomes active re-register it to another
// EventLoop. After this is done we should still receive the data that
// was written to the channel.
ctx.deregister().addListener((ChannelFutureListener) cf -> {
Channel channel = cf.channel();
assertNotSame(loop, channel.eventLoop());
group.next().register(channel);
});
}
});
}
});
sc = b.bind(0).syncUninterruptibly().channel();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioSocketChannel.class);
bootstrap.handler(new ChannelInboundHandlerAdapter());
cc = bootstrap.connect(sc.localAddress()).syncUninterruptibly().channel();
cc.writeAndFlush(Unpooled.wrappedBuffer(bytes)).syncUninterruptibly();
latch.await();
} finally {
if (cc != null) {
cc.close();
}
if (sc != null) {
sc.close();
}
group.shutdownGracefully();
}
}
Domain
Subdomains
Source
Frequently Asked Questions
What does testChannelReRegisterRead() do?
testChannelReRegisterRead() is a function in the netty codebase, defined in transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelTest.java.
Where is testChannelReRegisterRead() defined?
testChannelReRegisterRead() is defined in transport/src/test/java/io/netty/channel/socket/nio/NioSocketChannelTest.java at line 177.
What calls testChannelReRegisterRead()?
testChannelReRegisterRead() is called by 2 function(s): testChannelReRegisterReadDifferentEventLoop, testChannelReRegisterReadSameEventLoop.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free