Package io.netty.handler.codec.http2
Class UniformStreamByteDistributor
- java.lang.Object
-
- io.netty.handler.codec.http2.UniformStreamByteDistributor
-
- All Implemented Interfaces:
StreamByteDistributor
public final class UniformStreamByteDistributor extends java.lang.Object implements StreamByteDistributor
AStreamByteDistributor
that ignores stream priority and uniformly allocates bytes to all streams. This class uses a minimum chunk size that will be allocated to each stream. While fewer streams may be written to in each call todistribute(int, Writer)
, doing this should improve the goodput on each written stream.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
UniformStreamByteDistributor.State
The remote flow control state for a single stream.-
Nested classes/interfaces inherited from interface io.netty.handler.codec.http2.StreamByteDistributor
StreamByteDistributor.StreamState, StreamByteDistributor.Writer
-
-
Field Summary
Fields Modifier and Type Field Description private int
minAllocationChunk
The minimum number of bytes that we will attempt to allocate to a stream.private java.util.Deque<UniformStreamByteDistributor.State>
queue
private Http2Connection.PropertyKey
stateKey
private long
totalStreamableBytes
-
Constructor Summary
Constructors Constructor Description UniformStreamByteDistributor(Http2Connection connection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
distribute(int maxBytes, StreamByteDistributor.Writer writer)
Distributes up tomaxBytes
to those streams containing streamable bytes and iterates across those streams to write the appropriate bytes.void
minAllocationChunk(int minAllocationChunk)
Sets the minimum allocation chunk that will be allocated to each stream.private UniformStreamByteDistributor.State
state(Http2Stream stream)
void
updateDependencyTree(int childStreamId, int parentStreamId, short weight, boolean exclusive)
Explicitly update the dependency tree.void
updateStreamableBytes(StreamByteDistributor.StreamState streamState)
Called when the streamable bytes for a stream has changed.
-
-
-
Field Detail
-
stateKey
private final Http2Connection.PropertyKey stateKey
-
queue
private final java.util.Deque<UniformStreamByteDistributor.State> queue
-
minAllocationChunk
private int minAllocationChunk
The minimum number of bytes that we will attempt to allocate to a stream. This is to help improve goodput on a per-stream basis.
-
totalStreamableBytes
private long totalStreamableBytes
-
-
Constructor Detail
-
UniformStreamByteDistributor
public UniformStreamByteDistributor(Http2Connection connection)
-
-
Method Detail
-
minAllocationChunk
public void minAllocationChunk(int minAllocationChunk)
Sets the minimum allocation chunk that will be allocated to each stream. Defaults to 1KiB.- Parameters:
minAllocationChunk
- the minimum number of bytes that will be allocated to each stream. Must be > 0.
-
updateStreamableBytes
public void updateStreamableBytes(StreamByteDistributor.StreamState streamState)
Description copied from interface:StreamByteDistributor
Called when the streamable bytes for a stream has changed. Until this method is called for the first time for a give stream, the stream is assumed to have no streamable bytes.- Specified by:
updateStreamableBytes
in interfaceStreamByteDistributor
-
updateDependencyTree
public void updateDependencyTree(int childStreamId, int parentStreamId, short weight, boolean exclusive)
Description copied from interface:StreamByteDistributor
Explicitly update the dependency tree. This method is called independently of stream state changes.- Specified by:
updateDependencyTree
in interfaceStreamByteDistributor
- Parameters:
childStreamId
- The stream identifier associated with the child stream.parentStreamId
- The stream identifier associated with the parent stream. May be0
, to makechildStreamId
and immediate child of the connection.weight
- The weight which is used relative to other child streams forparentStreamId
. This value must be between 1 and 256 (inclusive).exclusive
- IfchildStreamId
should be the exclusive dependency ofparentStreamId
.
-
distribute
public boolean distribute(int maxBytes, StreamByteDistributor.Writer writer) throws Http2Exception
Description copied from interface:StreamByteDistributor
Distributes up tomaxBytes
to those streams containing streamable bytes and iterates across those streams to write the appropriate bytes. Criteria for traversing streams is undefined and it is up to the implementation to determine when to stop at a given stream.The streamable bytes are not automatically updated by calling this method. It is up to the caller to indicate the number of bytes streamable after the write by calling
StreamByteDistributor.updateStreamableBytes(StreamState)
.- Specified by:
distribute
in interfaceStreamByteDistributor
- Parameters:
maxBytes
- the maximum number of bytes to write.- Returns:
true
if there are still streamable bytes that have not yet been written, otherwisefalse
.- Throws:
Http2Exception
- If an internal exception occurs and internal connection state would otherwise be corrupted.
-
state
private UniformStreamByteDistributor.State state(Http2Stream stream)
-
-