AdaptiveRecvByteBufAllocator Class — netty Architecture
Architecture documentation for the AdaptiveRecvByteBufAllocator class in AdaptiveRecvByteBufAllocator.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 458cfebb_b197_2c19_3660_772e05fde55c["AdaptiveRecvByteBufAllocator"] 1f169dee_b60d_7088_626d_ce9f42c7fb52["AdaptiveRecvByteBufAllocator.java"] 458cfebb_b197_2c19_3660_772e05fde55c -->|defined in| 1f169dee_b60d_7088_626d_ce9f42c7fb52 1189bce1_aa86_7650_91d9_e518274dcb80["AdaptiveRecvByteBufAllocator()"] 458cfebb_b197_2c19_3660_772e05fde55c -->|method| 1189bce1_aa86_7650_91d9_e518274dcb80 672215fa_7ca7_36d8_7772_6dd3270011f2["Handle()"] 458cfebb_b197_2c19_3660_772e05fde55c -->|method| 672215fa_7ca7_36d8_7772_6dd3270011f2
Relationship Graph
Source Code
transport/src/main/java/io/netty/channel/AdaptiveRecvByteBufAllocator.java lines 32–120
public class AdaptiveRecvByteBufAllocator extends DefaultMaxMessagesRecvByteBufAllocator {
public static final int DEFAULT_MINIMUM = 64;
// Use an initial value that is bigger than the common MTU of 1500
public static final int DEFAULT_INITIAL = 2048;
public static final int DEFAULT_MAXIMUM = 65536;
/**
* @deprecated There is state for {@link #maxMessagesPerRead()} which is typically based upon channel type.
*/
@Deprecated
public static final AdaptiveRecvByteBufAllocator DEFAULT = new AdaptiveRecvByteBufAllocator();
private final class HandleImpl extends MaxMessageHandle {
private final AdaptiveCalculator calculator;
HandleImpl(int minimum, int initial, int maximum) {
calculator = new AdaptiveCalculator(minimum, initial, maximum);
}
@Override
public void lastBytesRead(int bytes) {
// If we read as much as we asked for we should check if we need to ramp up the size of our next guess.
// This helps adjust more quickly when large amounts of data is pending and can avoid going back to
// the selector to check for more data. Going back to the selector can add significant latency for large
// data transfers.
if (bytes == attemptedBytesRead()) {
calculator.record(bytes);
}
super.lastBytesRead(bytes);
}
@Override
public int guess() {
return calculator.nextSize();
}
@Override
public void readComplete() {
calculator.record(totalBytesRead());
}
}
private final int minimum;
private final int initial;
private final int maximum;
/**
* Creates a new predictor with the default parameters. With the default
* parameters, the expected buffer size starts from {@code 1024}, does not
* go down below {@code 64}, and does not go up above {@code 65536}.
*/
public AdaptiveRecvByteBufAllocator() {
this(DEFAULT_MINIMUM, DEFAULT_INITIAL, DEFAULT_MAXIMUM);
}
/**
* Creates a new predictor with the specified parameters.
*
* @param minimum the inclusive lower bound of the expected buffer size
* @param initial the initial buffer size when no feed back was received
* @param maximum the inclusive upper bound of the expected buffer size
*/
public AdaptiveRecvByteBufAllocator(int minimum, int initial, int maximum) {
checkPositive(minimum, "minimum");
if (initial < minimum) {
throw new IllegalArgumentException("initial: " + initial);
}
if (maximum < initial) {
throw new IllegalArgumentException("maximum: " + maximum);
}
this.minimum = minimum;
this.initial = initial;
this.maximum = maximum;
}
@SuppressWarnings("deprecation")
@Override
public Handle newHandle() {
return new HandleImpl(minimum, initial, maximum);
Source
Frequently Asked Questions
What is the AdaptiveRecvByteBufAllocator class?
AdaptiveRecvByteBufAllocator is a class in the netty codebase, defined in transport/src/main/java/io/netty/channel/AdaptiveRecvByteBufAllocator.java.
Where is AdaptiveRecvByteBufAllocator defined?
AdaptiveRecvByteBufAllocator is defined in transport/src/main/java/io/netty/channel/AdaptiveRecvByteBufAllocator.java at line 32.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free