@UnstableApi public final class UniformStreamByteDistributor extends java.lang.Object implements StreamByteDistributor
StreamByteDistributor
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 to StreamByteDistributor.distribute(int, Writer)
, doing this
should improve the goodput on each written stream.Modifier and Type | Class and Description |
---|---|
private class |
UniformStreamByteDistributor.State
The remote flow control state for a single stream.
|
StreamByteDistributor.StreamState, StreamByteDistributor.Writer
Modifier and Type | Field and 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 and Description |
---|
UniformStreamByteDistributor(Http2Connection connection) |
Modifier and Type | Method and Description |
---|---|
boolean |
distribute(int maxBytes,
StreamByteDistributor.Writer writer)
Distributes up to
maxBytes 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) |
(package private) int |
streamableBytes0(Http2Stream stream)
For testing only!
|
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.
|
private final Http2Connection.PropertyKey stateKey
private final java.util.Deque<UniformStreamByteDistributor.State> queue
private int minAllocationChunk
private long totalStreamableBytes
public UniformStreamByteDistributor(Http2Connection connection)
public void minAllocationChunk(int minAllocationChunk)
minAllocationChunk
- the minimum number of bytes that will be allocated to each stream.
Must be > 0.public void updateStreamableBytes(StreamByteDistributor.StreamState streamState)
StreamByteDistributor
updateStreamableBytes
in interface StreamByteDistributor
public void updateDependencyTree(int childStreamId, int parentStreamId, short weight, boolean exclusive)
StreamByteDistributor
updateDependencyTree
in interface StreamByteDistributor
childStreamId
- The stream identifier associated with the child stream.parentStreamId
- The stream identifier associated with the parent stream. May be 0
,
to make childStreamId
and immediate child of the connection.weight
- The weight which is used relative to other child streams for parentStreamId
. This value
must be between 1 and 256 (inclusive).exclusive
- If childStreamId
should be the exclusive dependency of parentStreamId
.public boolean distribute(int maxBytes, StreamByteDistributor.Writer writer) throws Http2Exception
StreamByteDistributor
maxBytes
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)
.
distribute
in interface StreamByteDistributor
maxBytes
- the maximum number of bytes to write.true
if there are still streamable bytes that have not yet been written,
otherwise false
.Http2Exception
- If an internal exception occurs and internal connection state would otherwise be
corrupted.private UniformStreamByteDistributor.State state(Http2Stream stream)
int streamableBytes0(Http2Stream stream)