public class AdaptiveBufferSizePredictor extends java.lang.Object implements BufferSizePredictor
BufferSizePredictor
that automatically increases and
decreases the predicted buffer size on feed back.
It gradually increases the expected number of bytes if the previous buffer fully filled the allocated buffer. It gradually decreases the expected number of 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. TODO: Object type hints could be useful at giving more type-specific predictions
Modifier and Type | Field and Description |
---|---|
private boolean |
decreaseNow |
(package private) static int |
DEFAULT_INITIAL |
(package private) static int |
DEFAULT_MAXIMUM |
(package private) static int |
DEFAULT_MINIMUM |
private int |
index |
private static int |
INDEX_DECREMENT |
private static int |
INDEX_INCREMENT |
private static boolean |
isTrace |
private static Log |
log |
private int |
maxIndex |
private int |
minIndex |
private int |
nextBufferSize |
private static int[] |
SIZE_TABLE |
Constructor and Description |
---|
AdaptiveBufferSizePredictor()
Creates a new predictor with the default parameters.
|
AdaptiveBufferSizePredictor(int minimum,
int initial,
int maximum)
Creates a new predictor with the specified parameters.
|
Modifier and Type | Method and Description |
---|---|
private static int |
getSizeTableIndex(int size) |
int |
nextSize(java.lang.Object obj)
Provide the next buffer size taking in account
the object to store in the buffer.
|
void |
recordSize(int previousSize)
Record the size of the of data in the last buffer used.
|
private static final Log log
private static final boolean isTrace
static final int DEFAULT_MINIMUM
static final int DEFAULT_INITIAL
static final int DEFAULT_MAXIMUM
private static final int INDEX_INCREMENT
private static final int INDEX_DECREMENT
private static final int[] SIZE_TABLE
private final int minIndex
private final int maxIndex
private int index
private int nextBufferSize
private boolean decreaseNow
public AdaptiveBufferSizePredictor()
512
, does not
go down below 16
, and does not go up above 65536
.public AdaptiveBufferSizePredictor(int minimum, int initial, int maximum)
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 sizeprivate static int getSizeTableIndex(int size)
public int nextSize(java.lang.Object obj)
BufferSizePredictor
nextSize
in interface BufferSizePredictor
obj
- instance that will be stored in the bufferpublic void recordSize(int previousSize)
BufferSizePredictor
recordSize
in interface BufferSizePredictor
previousSize
- int representing the size of the last
object buffered.