UniformStreamByteDistributor Class — netty Architecture
Architecture documentation for the UniformStreamByteDistributor class in UniformStreamByteDistributor.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 5377af2d_bff0_e163_253c_99c207830ae4["UniformStreamByteDistributor"] d72c463f_00af_2ec5_ed7b_8e37cf72c7b4["UniformStreamByteDistributor.java"] 5377af2d_bff0_e163_253c_99c207830ae4 -->|defined in| d72c463f_00af_2ec5_ed7b_8e37cf72c7b4 85a0db04_bf80_87a7_f9ce_baa702dc7660["UniformStreamByteDistributor()"] 5377af2d_bff0_e163_253c_99c207830ae4 -->|method| 85a0db04_bf80_87a7_f9ce_baa702dc7660 49d0480f_9f52_fbe6_d5f9_d51919d08664["minAllocationChunk()"] 5377af2d_bff0_e163_253c_99c207830ae4 -->|method| 49d0480f_9f52_fbe6_d5f9_d51919d08664 156bbb11_157a_2a4e_aa30_e317b707854a["updateStreamableBytes()"] 5377af2d_bff0_e163_253c_99c207830ae4 -->|method| 156bbb11_157a_2a4e_aa30_e317b707854a 168ebffc_c6a3_93a3_5c74_45c06118d657["updateDependencyTree()"] 5377af2d_bff0_e163_253c_99c207830ae4 -->|method| 168ebffc_c6a3_93a3_5c74_45c06118d657 9aa76083_f372_5469_df81_9b5573b58931["distribute()"] 5377af2d_bff0_e163_253c_99c207830ae4 -->|method| 9aa76083_f372_5469_df81_9b5573b58931 1855896a_7852_d423_0884_fd95c4761297["State()"] 5377af2d_bff0_e163_253c_99c207830ae4 -->|method| 1855896a_7852_d423_0884_fd95c4761297
Relationship Graph
Source Code
codec-http2/src/main/java/io/netty/handler/codec/http2/UniformStreamByteDistributor.java lines 35–202
public final class UniformStreamByteDistributor implements StreamByteDistributor {
private final Http2Connection.PropertyKey stateKey;
private final Deque<State> queue = new ArrayDeque<State>(4);
/**
* 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.
*/
private int minAllocationChunk = DEFAULT_MIN_ALLOCATION_CHUNK;
private long totalStreamableBytes;
public UniformStreamByteDistributor(Http2Connection connection) {
// Add a state for the connection.
stateKey = connection.newKey();
Http2Stream connectionStream = connection.connectionStream();
connectionStream.setProperty(stateKey, new State(connectionStream));
// Register for notification of new streams.
connection.addListener(new Http2ConnectionAdapter() {
@Override
public void onStreamAdded(Http2Stream stream) {
stream.setProperty(stateKey, new State(stream));
}
@Override
public void onStreamClosed(Http2Stream stream) {
state(stream).close();
}
});
}
/**
* Sets the minimum allocation chunk that will be allocated to each stream. Defaults to 1KiB.
*
* @param minAllocationChunk the minimum number of bytes that will be allocated to each stream.
* Must be > 0.
*/
public void minAllocationChunk(int minAllocationChunk) {
checkPositive(minAllocationChunk, "minAllocationChunk");
this.minAllocationChunk = minAllocationChunk;
}
@Override
public void updateStreamableBytes(StreamState streamState) {
state(streamState.stream()).updateStreamableBytes(streamableBytes(streamState),
streamState.hasFrame(),
streamState.windowSize());
}
@Override
public void updateDependencyTree(int childStreamId, int parentStreamId, short weight, boolean exclusive) {
// This class ignores priority and dependency!
}
@Override
public boolean distribute(int maxBytes, Writer writer) throws Http2Exception {
final int size = queue.size();
if (size == 0) {
return totalStreamableBytes > 0;
}
final int chunkSize = max(minAllocationChunk, maxBytes / size);
State state = queue.pollFirst();
do {
state.enqueued = false;
if (state.windowNegative) {
continue;
}
if (maxBytes == 0 && state.streamableBytes > 0) {
// Stop at the first state that can't send. Add this state back to the head of the queue. Note
// that empty frames at the head of the queue will always be written, assuming the stream window
// is not negative.
queue.addFirst(state);
state.enqueued = true;
break;
}
// Allocate as much data as we can for this stream.
int chunk = min(chunkSize, min(maxBytes, state.streamableBytes));
maxBytes -= chunk;
Source
Frequently Asked Questions
What is the UniformStreamByteDistributor class?
UniformStreamByteDistributor is a class in the netty codebase, defined in codec-http2/src/main/java/io/netty/handler/codec/http2/UniformStreamByteDistributor.java.
Where is UniformStreamByteDistributor defined?
UniformStreamByteDistributor is defined in codec-http2/src/main/java/io/netty/handler/codec/http2/UniformStreamByteDistributor.java at line 35.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free