Home / Class/ StateOnlyComparator Class — netty Architecture

StateOnlyComparator Class — netty Architecture

Architecture documentation for the StateOnlyComparator class in WeightedFairQueueByteDistributor.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  0efd6e94_f7c3_5a76_d967_17d4b213f016["StateOnlyComparator"]
  71cf42ec_8b96_e844_a28e_f91e8e96ff66["WeightedFairQueueByteDistributor.java"]
  0efd6e94_f7c3_5a76_d967_17d4b213f016 -->|defined in| 71cf42ec_8b96_e844_a28e_f91e8e96ff66
  b3a17d55_8d87_d700_8e02_461a42255873["compare()"]
  0efd6e94_f7c3_5a76_d967_17d4b213f016 -->|method| b3a17d55_8d87_d700_8e02_461a42255873

Relationship Graph

Source Code

codec-http2/src/main/java/io/netty/handler/codec/http2/WeightedFairQueueByteDistributor.java lines 392–416

    private static final class StateOnlyComparator implements Comparator<State>, Serializable {
        private static final long serialVersionUID = -4806936913002105966L;

        static final StateOnlyComparator INSTANCE = new StateOnlyComparator();

        @Override
        public int compare(State o1, State o2) {
            // "priority only streams" (which have not been activated) are higher priority than streams used for data.
            boolean o1Actived = o1.wasStreamReservedOrActivated();
            if (o1Actived != o2.wasStreamReservedOrActivated()) {
                return o1Actived ? -1 : 1;
            }
            // Numerically greater depth is higher priority.
            int x = o2.dependencyTreeDepth - o1.dependencyTreeDepth;

            // I also considered tracking the number of streams which are "activated" (eligible transfer data) at each
            // subtree. This would require a traversal from each node to the root on dependency tree structural changes,
            // and then it would require a re-prioritization at each of these nodes (instead of just the nodes where the
            // direct parent changed). The costs of this are judged to be relatively high compared to the nominal
            // benefit it provides to the heuristic. Instead folks should just increase maxStateOnlySize.

            // Last resort is to give larger stream ids more priority.
            return x != 0 ? x : o1.streamId - o2.streamId;
        }
    }

Frequently Asked Questions

What is the StateOnlyComparator class?
StateOnlyComparator is a class in the netty codebase, defined in codec-http2/src/main/java/io/netty/handler/codec/http2/WeightedFairQueueByteDistributor.java.
Where is StateOnlyComparator defined?
StateOnlyComparator is defined in codec-http2/src/main/java/io/netty/handler/codec/http2/WeightedFairQueueByteDistributor.java at line 392.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free