Package org.jboss.netty.channel
Class AdaptiveReceiveBufferSizePredictor
- java.lang.Object
-
- org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor
-
- All Implemented Interfaces:
ReceiveBufferSizePredictor
public class AdaptiveReceiveBufferSizePredictor extends java.lang.Object implements ReceiveBufferSizePredictor
TheReceiveBufferSizePredictorthat 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.
-
-
Field Summary
Fields Modifier and Type Field Description private booleandecreaseNow(package private) static intDEFAULT_INITIAL(package private) static intDEFAULT_MAXIMUM(package private) static intDEFAULT_MINIMUMprivate intindexprivate static intINDEX_DECREMENTprivate static intINDEX_INCREMENTprivate intmaxIndexprivate intminIndexprivate intnextReceiveBufferSizeprivate static int[]SIZE_TABLE
-
Constructor Summary
Constructors Constructor Description AdaptiveReceiveBufferSizePredictor()Creates a new predictor with the default parameters.AdaptiveReceiveBufferSizePredictor(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)intnextReceiveBufferSize()Predicts the capacity of theChannelBufferfor the next read operation depending on the actual number of read bytes in the previous read operation.voidpreviousReceiveBufferSize(int previousReceiveBufferSize)Updates this predictor by specifying the actual number of read bytes in the previous read operation.
-
-
-
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
-
minIndex
private final int minIndex
-
maxIndex
private final int maxIndex
-
index
private int index
-
nextReceiveBufferSize
private int nextReceiveBufferSize
-
decreaseNow
private boolean decreaseNow
-
-
Constructor Detail
-
AdaptiveReceiveBufferSizePredictor
public AdaptiveReceiveBufferSizePredictor()
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.
-
AdaptiveReceiveBufferSizePredictor
public AdaptiveReceiveBufferSizePredictor(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)
-
nextReceiveBufferSize
public int nextReceiveBufferSize()
Description copied from interface:ReceiveBufferSizePredictorPredicts the capacity of theChannelBufferfor the next read operation depending on the actual number of read bytes in the previous read operation.- Specified by:
nextReceiveBufferSizein interfaceReceiveBufferSizePredictor- Returns:
- the expected number of readable bytes this time
-
previousReceiveBufferSize
public void previousReceiveBufferSize(int previousReceiveBufferSize)
Description copied from interface:ReceiveBufferSizePredictorUpdates this predictor by specifying the actual number of read bytes in the previous read operation.- Specified by:
previousReceiveBufferSizein interfaceReceiveBufferSizePredictor- Parameters:
previousReceiveBufferSize- the actual number of read bytes in the previous read operation
-
-