Package io.netty.channel
Class AdaptiveRecvByteBufAllocator
- java.lang.Object
-
- io.netty.channel.DefaultMaxMessagesRecvByteBufAllocator
-
- io.netty.channel.AdaptiveRecvByteBufAllocator
-
- All Implemented Interfaces:
MaxMessagesRecvByteBufAllocator,RecvByteBufAllocator
public class AdaptiveRecvByteBufAllocator extends DefaultMaxMessagesRecvByteBufAllocator
TheRecvByteBufAllocatorthat automatically increases and decreases the predicted buffer size on feed back.It gradually increases the expected number of readable bytes if the previous read fully filled the allocated buffer. It gradually decreases the expected number of readable bytes if the read operation was not able to fill a certain amount of the allocated buffer two times consecutively. Otherwise, it keeps returning the same prediction.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classAdaptiveRecvByteBufAllocator.HandleImpl-
Nested classes/interfaces inherited from class io.netty.channel.DefaultMaxMessagesRecvByteBufAllocator
DefaultMaxMessagesRecvByteBufAllocator.MaxMessageHandle
-
Nested classes/interfaces inherited from interface io.netty.channel.RecvByteBufAllocator
RecvByteBufAllocator.DelegatingHandle, RecvByteBufAllocator.ExtendedHandle, RecvByteBufAllocator.Handle
-
-
Field Summary
Fields Modifier and Type Field Description static AdaptiveRecvByteBufAllocatorDEFAULTDeprecated.There is state forDefaultMaxMessagesRecvByteBufAllocator.maxMessagesPerRead()which is typically based upon channel type.(package private) static intDEFAULT_INITIAL(package private) static intDEFAULT_MAXIMUM(package private) static intDEFAULT_MINIMUMprivate static intINDEX_DECREMENTprivate static intINDEX_INCREMENTprivate intinitialprivate intmaxIndexprivate intminIndexprivate static int[]SIZE_TABLE
-
Constructor Summary
Constructors Constructor Description AdaptiveRecvByteBufAllocator()Creates a new predictor with the default parameters.AdaptiveRecvByteBufAllocator(int minimum, int initial, int maximum)Creates a new predictor with the specified parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static intgetSizeTableIndex(int size)RecvByteBufAllocator.HandlenewHandle()Creates a new handle.AdaptiveRecvByteBufAllocatorrespectMaybeMoreData(boolean respectMaybeMoreData)Determine if future instances ofRecvByteBufAllocator.newHandle()will stop reading if we think there is no more data.-
Methods inherited from class io.netty.channel.DefaultMaxMessagesRecvByteBufAllocator
maxMessagesPerRead, maxMessagesPerRead, respectMaybeMoreData
-
-
-
-
Field Detail
-
DEFAULT_MINIMUM
static final int DEFAULT_MINIMUM
- See Also:
- Constant Field Values
-
DEFAULT_INITIAL
static final int DEFAULT_INITIAL
- See Also:
- Constant Field Values
-
DEFAULT_MAXIMUM
static final int DEFAULT_MAXIMUM
- See Also:
- Constant Field Values
-
INDEX_INCREMENT
private static final int INDEX_INCREMENT
- See Also:
- Constant Field Values
-
INDEX_DECREMENT
private static final int INDEX_DECREMENT
- See Also:
- Constant Field Values
-
SIZE_TABLE
private static final int[] SIZE_TABLE
-
DEFAULT
@Deprecated public static final AdaptiveRecvByteBufAllocator DEFAULT
Deprecated.There is state forDefaultMaxMessagesRecvByteBufAllocator.maxMessagesPerRead()which is typically based upon channel type.
-
minIndex
private final int minIndex
-
maxIndex
private final int maxIndex
-
initial
private final int initial
-
-
Constructor Detail
-
AdaptiveRecvByteBufAllocator
public AdaptiveRecvByteBufAllocator()
Creates a new predictor with the default parameters. With the default parameters, the expected buffer size starts from1024, does not go down below64, and does not go up above65536.
-
AdaptiveRecvByteBufAllocator
public AdaptiveRecvByteBufAllocator(int minimum, int initial, int maximum)Creates a new predictor with the specified parameters.- Parameters:
minimum- the inclusive lower bound of the expected buffer sizeinitial- the initial buffer size when no feed back was receivedmaximum- the inclusive upper bound of the expected buffer size
-
-
Method Detail
-
getSizeTableIndex
private static int getSizeTableIndex(int size)
-
newHandle
public RecvByteBufAllocator.Handle newHandle()
Description copied from interface:RecvByteBufAllocatorCreates a new handle. The handle provides the actual operations and keeps the internal information which is required for predicting an optimal buffer capacity.
-
respectMaybeMoreData
public AdaptiveRecvByteBufAllocator respectMaybeMoreData(boolean respectMaybeMoreData)
Description copied from class:DefaultMaxMessagesRecvByteBufAllocatorDetermine if future instances ofRecvByteBufAllocator.newHandle()will stop reading if we think there is no more data.- Overrides:
respectMaybeMoreDatain classDefaultMaxMessagesRecvByteBufAllocator- Parameters:
respectMaybeMoreData-trueto stop reading if we think there is no more data. This may save a system call to read from the socket, but if data has arrived in a racy fashion we may give up ourDefaultMaxMessagesRecvByteBufAllocator.maxMessagesPerRead()quantum and have to wait for the selector to notify us of more data.falseto keep reading (up toDefaultMaxMessagesRecvByteBufAllocator.maxMessagesPerRead()) or until there is no data when we attempt to read.
- Returns:
this.
-
-