Top Description Inners Fields Constructors Methods
io.netty5.channel

public Class AdaptiveReadHandleFactory

extends MaxMessagesReadHandleFactory
Class Inheritance
Imports
java.util.ArrayList, .List

The ReadHandleFactory that 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 unable to fill a certain amount of the allocated buffer two times consecutively. Otherwise, it keeps returning the same prediction.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv static final int
pack-priv static final int
private static final int
private static final int
private final int
private final int
private final int
private static final int[]

Constructor Summary

AccessConstructor and Description
public
AdaptiveReadHandleFactory()

Creates a new predictor with the default parameters.

public
AdaptiveReadHandleFactory(int
the maximum number of messages to read per read loop invocation.
maxMessagesPerRead
)

Creates a new predictor with the default parameters.

public
AdaptiveReadHandleFactory(int
the maximum number of messages to read per read loop invocation.
maxMessagesPerRead
,
int
the inclusive lower bound of the expected buffer size
minimum
,
int
the initial buffer size when no feedback was received
initial
,
int
the inclusive upper bound of the expected buffer size
maximum
)

Creates a new predictor with the specified parameters.

Method Summary

Modifier and TypeMethod and Description
private static int
getSizeTableIndex(final int size)

public MaxMessagesReadHandleFactory.MaxMessageReadHandle
newMaxMessageHandle(int
the maximum number of messages to read per read loop.
maxMessagesPerRead
)

Implements abstract io.netty5.channel.MaxMessagesReadHandleFactory.newMaxMessageHandle.

Creates a new MaxMessageReadHandle to use.
Inherited from io.netty5.channel.MaxMessagesReadHandleFactory:
newHandle

Field Detail

DEFAULT_INITIALback to summary
pack-priv static final int DEFAULT_INITIAL
DEFAULT_MAXIMUMback to summary
pack-priv static final int DEFAULT_MAXIMUM
DEFAULT_MINIMUMback to summary
pack-priv static final int DEFAULT_MINIMUM
INDEX_DECREMENTback to summary
private static final int INDEX_DECREMENT
INDEX_INCREMENTback to summary
private static final int INDEX_INCREMENT
initialback to summary
private final int initial
maxIndexback to summary
private final int maxIndex
minIndexback to summary
private final int minIndex
SIZE_TABLEback to summary
private static final int[] SIZE_TABLE

Constructor Detail

AdaptiveReadHandleFactoryback to summary
public AdaptiveReadHandleFactory()

Creates a new predictor with the default parameters. With the default parameters, the expected buffer size starts from 1024, does not go down below 64, and does not go up above 65536.

AdaptiveReadHandleFactoryback to summary
public AdaptiveReadHandleFactory(int maxMessagesPerRead)

Creates a new predictor with the default parameters. With the default parameters, the expected buffer size starts from 1024, does not go down below 64, and does not go up above 65536.

Parameters
maxMessagesPerRead:int

the maximum number of messages to read per read loop invocation.

AdaptiveReadHandleFactoryback to summary
public AdaptiveReadHandleFactory(int maxMessagesPerRead, int minimum, int initial, int maximum)

Creates a new predictor with the specified parameters.

Parameters
maxMessagesPerRead:int

the maximum number of messages to read per read loop invocation.

minimum:int

the inclusive lower bound of the expected buffer size

initial:int

the initial buffer size when no feedback was received

maximum:int

the inclusive upper bound of the expected buffer size

Method Detail

getSizeTableIndexback to summary
private static int getSizeTableIndex(final int size)
newMaxMessageHandleback to summary
public MaxMessagesReadHandleFactory.MaxMessageReadHandle newMaxMessageHandle(int maxMessagesPerRead)

Implements abstract io.netty5.channel.MaxMessagesReadHandleFactory.newMaxMessageHandle.

Doc from io.netty5.channel.MaxMessagesReadHandleFactory.newMaxMessageHandle.

Creates a new MaxMessageReadHandle to use.

Parameters
maxMessagesPerRead:int

the maximum number of messages to read per read loop.

Returns:MaxMessagesReadHandleFactory.MaxMessageReadHandle

the handle.

Annotations
@Override
io.netty5.channel back to summary

private final Class AdaptiveReadHandleFactory.ReadHandleImpl

extends MaxMessageReadHandle
Class Inheritance

Field Summary

Modifier and TypeField and Description
private boolean
private int
private final int
private final int
private int
private int

Constructor Summary

AccessConstructor and Description
pack-priv
ReadHandleImpl(int maxMessagesPerRead, int minIndex, int maxIndex, int initial)

Method Summary

Modifier and TypeMethod and Description
public int
estimatedBufferCapacity()

Implements io.netty5.channel.ReadHandleFactory.ReadHandle.estimatedBufferCapacity.

Guess the capacity for the next receive buffer that is probably large enough to read all inbound data and small enough not to waste its space.
public boolean
lastRead(int
The number of bytes the read operation did attempt to read.
attemptedBytesRead
,
int
The number of bytes from the previous read operation. This may be negative if a read error occurs.
actualBytesRead
,
int
The number of messages read.
numMessagesRead
)

Overrides io.netty5.channel.MaxMessagesReadHandleFactory.MaxMessageReadHandle.lastRead.

Implements io.netty5.channel.ReadHandleFactory.ReadHandle.lastRead.

Notify the ReadHandle of the last read operation and its result.
public void
private void
record(int actualReadBytes)

private int

Field Detail

decreaseNowback to summary
private boolean decreaseNow
indexback to summary
private int index
maxIndexback to summary
private final int maxIndex
minIndexback to summary
private final int minIndex
nextReceiveBufferSizeback to summary
private int nextReceiveBufferSize
totalBytesReadback to summary
private int totalBytesRead

Constructor Detail

ReadHandleImplback to summary
pack-priv ReadHandleImpl(int maxMessagesPerRead, int minIndex, int maxIndex, int initial)

Method Detail

estimatedBufferCapacityback to summary
public int estimatedBufferCapacity()

Implements io.netty5.channel.ReadHandleFactory.ReadHandle.estimatedBufferCapacity.

Doc from io.netty5.channel.ReadHandleFactory.ReadHandle.estimatedBufferCapacity.

Guess the capacity for the next receive buffer that is probably large enough to read all inbound data and small enough not to waste its space.

Annotations
@Override
lastReadback to summary
public boolean lastRead(int attemptedBytesRead, int actualBytesRead, int numMessagesRead)

Overrides io.netty5.channel.MaxMessagesReadHandleFactory.MaxMessageReadHandle.lastRead.

Implements io.netty5.channel.ReadHandleFactory.ReadHandle.lastRead.

Doc from io.netty5.channel.ReadHandleFactory.ReadHandle.lastRead.

Notify the ReadHandle of the last read operation and its result.

Parameters
attemptedBytesRead:int

The number of bytes the read operation did attempt to read.

actualBytesRead:int

The number of bytes from the previous read operation. This may be negative if a read error occurs.

numMessagesRead:int

The number of messages read.

Returns:boolean

true if the read loop should continue reading, false otherwise.

Annotations
@Override
readCompleteback to summary
public void readComplete()

Overrides io.netty5.channel.MaxMessagesReadHandleFactory.MaxMessageReadHandle.readComplete.

Implements io.netty5.channel.ReadHandleFactory.ReadHandle.readComplete.

Doc from io.netty5.channel.ReadHandleFactory.ReadHandle.readComplete.

Method that must be called once the read loop was completed.

Annotations
@Override
recordback to summary
private void record(int actualReadBytes)
totalBytesReadback to summary
private int totalBytesRead()