TestChannelInitializer Class — netty Architecture
Architecture documentation for the TestChannelInitializer class in TestChannelInitializer.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 2936c10c_225e_b221_5564_4ba7e259cc8c["TestChannelInitializer"] a1d4214d_7c3f_2a95_0423_d9c11fead4b0["TestChannelInitializer.java"] 2936c10c_225e_b221_5564_4ba7e259cc8c -->|defined in| a1d4214d_7c3f_2a95_0423_d9c11fead4b0 83e7cb8c_9d42_4a33_5a10_242e88f2b33a["initChannel()"] 2936c10c_225e_b221_5564_4ba7e259cc8c -->|method| 83e7cb8c_9d42_4a33_5a10_242e88f2b33a
Relationship Graph
Source Code
codec-http2/src/test/java/io/netty/handler/codec/http2/TestChannelInitializer.java lines 34–122
@Sharable
public class TestChannelInitializer extends ChannelInitializer<Channel> {
ChannelHandler handler;
AtomicInteger maxReads;
@Override
public void initChannel(Channel channel) {
if (handler != null) {
channel.pipeline().addLast(handler);
handler = null;
}
if (maxReads != null) {
channel.config().setRecvByteBufAllocator(new TestNumReadsRecvByteBufAllocator(maxReads));
}
}
/**
* Designed to read a single byte at a time to control the number of reads done at a fine granularity.
*/
static final class TestNumReadsRecvByteBufAllocator implements RecvByteBufAllocator {
private final AtomicInteger numReads;
private TestNumReadsRecvByteBufAllocator(AtomicInteger numReads) {
this.numReads = numReads;
}
@Override
public ExtendedHandle newHandle() {
return new ExtendedHandle() {
private int attemptedBytesRead;
private int lastBytesRead;
private int numMessagesRead;
@Override
public ByteBuf allocate(ByteBufAllocator alloc) {
return alloc.ioBuffer(guess(), guess());
}
@Override
public int guess() {
return 1; // only ever allocate buffers of size 1 to ensure the number of reads is controlled.
}
@Override
public void reset(ChannelConfig config) {
numMessagesRead = 0;
}
@Override
public void incMessagesRead(int numMessages) {
numMessagesRead += numMessages;
}
@Override
public void lastBytesRead(int bytes) {
lastBytesRead = bytes;
}
@Override
public int lastBytesRead() {
return lastBytesRead;
}
@Override
public void attemptedBytesRead(int bytes) {
attemptedBytesRead = bytes;
}
@Override
public int attemptedBytesRead() {
return attemptedBytesRead;
}
@Override
public boolean continueReading() {
return numMessagesRead < numReads.get();
}
@Override
public boolean continueReading(UncheckedBooleanSupplier maybeMoreDataSupplier) {
return continueReading();
}
Source
Frequently Asked Questions
What is the TestChannelInitializer class?
TestChannelInitializer is a class in the netty codebase, defined in codec-http2/src/test/java/io/netty/handler/codec/http2/TestChannelInitializer.java.
Where is TestChannelInitializer defined?
TestChannelInitializer is defined in codec-http2/src/test/java/io/netty/handler/codec/http2/TestChannelInitializer.java at line 34.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free