Home / Class/ FlowState Class — netty Architecture

FlowState Class — netty Architecture

Architecture documentation for the FlowState class in DefaultHttp2RemoteFlowController.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6["FlowState"]
  387ab0e0_5536_b5a6_dd1e_6048c918e522["DefaultHttp2RemoteFlowController.java"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|defined in| 387ab0e0_5536_b5a6_dd1e_6048c918e522
  9345767c_c76b_94d9_3d90_508ae5c4c8da["FlowState()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| 9345767c_c76b_94d9_3d90_508ae5c4c8da
  ec787674_66eb_7f49_f9fb_2739d5f8c34e["isWritable()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| ec787674_66eb_7f49_f9fb_2739d5f8c34e
  b0e076f4_99dd_b8df_17f9_ec8a416b621d["Http2Stream()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| b0e076f4_99dd_b8df_17f9_ec8a416b621d
  835ae471_e0c2_93d0_0989_07e018e9a7b0["markedWritability()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| 835ae471_e0c2_93d0_0989_07e018e9a7b0
  f759ecf5_cc37_eec1_52ba_cfa686cab9e1["windowSize()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| f759ecf5_cc37_eec1_52ba_cfa686cab9e1
  8ff90321_aa45_54f3_2c52_ad6b0500f375["writeAllocatedBytes()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| 8ff90321_aa45_54f3_2c52_ad6b0500f375
  03b175d5_44cf_3343_f379_b5f478f70548["incrementStreamWindow()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| 03b175d5_44cf_3343_f379_b5f478f70548
  94766ce0_fe7f_fa71_b87e_dddbcf138d14["writableWindow()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| 94766ce0_fe7f_fa71_b87e_dddbcf138d14
  727b82c5_12af_6e57_ecb7_e1b96717f7b6["pendingBytes()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| 727b82c5_12af_6e57_ecb7_e1b96717f7b6
  d6e8f2fe_a4c4_6f62_80b8_d7ad1ad01eac["enqueueFrame()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| d6e8f2fe_a4c4_6f62_80b8_d7ad1ad01eac
  f8738cf0_d85b_703e_8ee7_73e6ccb0eda2["enqueueFrameWithoutMerge()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| f8738cf0_d85b_703e_8ee7_73e6ccb0eda2
  95e04053_03f6_b964_917a_d1938dde19b7["hasFrame()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| 95e04053_03f6_b964_917a_d1938dde19b7
  05c92a89_a96d_a965_bde7_0416aecd0b29["FlowControlled()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6 -->|method| 05c92a89_a96d_a965_bde7_0416aecd0b29

Relationship Graph

Source Code

codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2RemoteFlowController.java lines 271–534

    private final class FlowState implements StreamByteDistributor.StreamState {
        private final Http2Stream stream;
        private final Deque<FlowControlled> pendingWriteQueue;
        private int window;
        private long pendingBytes;
        private boolean markedWritable;

        /**
         * Set to true while a frame is being written, false otherwise.
         */
        private boolean writing;
        /**
         * Set to true if cancel() was called.
         */
        private boolean cancelled;

        FlowState(Http2Stream stream) {
            this.stream = stream;
            pendingWriteQueue = new ArrayDeque<FlowControlled>(2);
        }

        /**
         * Determine if the stream associated with this object is writable.
         * @return {@code true} if the stream associated with this object is writable.
         */
        boolean isWritable() {
            return windowSize() > pendingBytes() && !cancelled;
        }

        /**
         * The stream this state is associated with.
         */
        @Override
        public Http2Stream stream() {
            return stream;
        }

        /**
         * Returns the parameter from the last call to {@link #markedWritability(boolean)}.
         */
        boolean markedWritability() {
            return markedWritable;
        }

        /**
         * Save the state of writability.
         */
        void markedWritability(boolean isWritable) {
            this.markedWritable = isWritable;
        }

        @Override
        public int windowSize() {
            return window;
        }

        /**
         * Reset the window size for this stream.
         */
        void windowSize(int initialWindowSize) {
            window = initialWindowSize;
        }

        /**
         * Write the allocated bytes for this stream.
         * @return the number of bytes written for a stream or {@code -1} if no write occurred.
         */
        int writeAllocatedBytes(int allocated) {
            final int initialAllocated = allocated;
            int writtenBytes;
            // In case an exception is thrown we want to remember it and pass it to cancel(Throwable).
            Throwable cause = null;
            FlowControlled frame;
            try {
                assert !writing;
                writing = true;

                // Write the remainder of frames that we are allowed to
                boolean writeOccurred = false;
                while (!cancelled && (frame = peek()) != null) {
                    int maxBytes = min(allocated, writableWindow());

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free