Home / Function/ writeAllocatedBytes() — netty Function Reference

writeAllocatedBytes() — netty Function Reference

Architecture documentation for the writeAllocatedBytes() function in DefaultHttp2RemoteFlowController.java from the netty codebase.

Function java Buffer Allocators calls 5 called by 1

Entity Profile

Dependency Diagram

graph TD
  8ff90321_aa45_54f3_2c52_ad6b0500f375["writeAllocatedBytes()"]
  b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6["FlowState"]
  8ff90321_aa45_54f3_2c52_ad6b0500f375 -->|defined in| b2e83a60_2b9a_b7db_749c_dd2e3fd31ba6
  b418b091_1216_530c_9ba3_7c08661c27d1["write()"]
  b418b091_1216_530c_9ba3_7c08661c27d1 -->|calls| 8ff90321_aa45_54f3_2c52_ad6b0500f375
  8e51738b_ec39_64b4_209a_eaf98c44fe11["cancel()"]
  8ff90321_aa45_54f3_2c52_ad6b0500f375 -->|calls| 8e51738b_ec39_64b4_209a_eaf98c44fe11
  94766ce0_fe7f_fa71_b87e_dddbcf138d14["writableWindow()"]
  8ff90321_aa45_54f3_2c52_ad6b0500f375 -->|calls| 94766ce0_fe7f_fa71_b87e_dddbcf138d14
  b418b091_1216_530c_9ba3_7c08661c27d1["write()"]
  8ff90321_aa45_54f3_2c52_ad6b0500f375 -->|calls| b418b091_1216_530c_9ba3_7c08661c27d1
  68c5ee5a_728f_9d02_8350_e9002006ac91["decrementPendingBytes()"]
  8ff90321_aa45_54f3_2c52_ad6b0500f375 -->|calls| 68c5ee5a_728f_9d02_8350_e9002006ac91
  c8771e8a_dd16_cfa8_0f08_61e2eb9b9b47["decrementFlowControlWindow()"]
  8ff90321_aa45_54f3_2c52_ad6b0500f375 -->|calls| c8771e8a_dd16_cfa8_0f08_61e2eb9b9b47
  style 8ff90321_aa45_54f3_2c52_ad6b0500f375 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2RemoteFlowController.java lines 338–399

        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());
                    if (maxBytes <= 0 && frame.size() > 0) {
                        // The frame still has data, but the amount of allocated bytes has been exhausted.
                        // Don't write needless empty frames.
                        break;
                    }
                    writeOccurred = true;
                    int initialFrameSize = frame.size();
                    try {
                        frame.write(ctx, max(0, maxBytes));
                        if (frame.size() == 0) {
                            // This frame has been fully written, remove this frame and notify it.
                            // Since we remove this frame first, we're guaranteed that its error
                            // method will not be called when we call cancel.
                            pendingWriteQueue.remove();
                            frame.writeComplete();
                        }
                    } finally {
                        // Decrement allocated by how much was actually written.
                        allocated -= initialFrameSize - frame.size();
                    }
                }

                if (!writeOccurred) {
                    // Either there was no frame, or the amount of allocated bytes has been exhausted.
                    return -1;
                }

            } catch (Throwable t) {
                // Mark the state as cancelled, we'll clear the pending queue via cancel() below.
                cancelled = true;
                cause = t;
            } finally {
                writing = false;
                // Make sure we always decrement the flow control windows
                // by the bytes written.
                writtenBytes = initialAllocated - allocated;

                decrementPendingBytes(writtenBytes, false);
                decrementFlowControlWindow(writtenBytes);

                // If a cancellation occurred while writing, call cancel again to
                // clear and error all of the pending writes.
                if (cancelled) {
                    cancel(INTERNAL_ERROR, cause);
                }
            }
            return writtenBytes;
        }

Domain

Subdomains

Called By

Frequently Asked Questions

What does writeAllocatedBytes() do?
writeAllocatedBytes() is a function in the netty codebase, defined in codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2RemoteFlowController.java.
Where is writeAllocatedBytes() defined?
writeAllocatedBytes() is defined in codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2RemoteFlowController.java at line 338.
What does writeAllocatedBytes() call?
writeAllocatedBytes() calls 5 function(s): cancel, decrementFlowControlWindow, decrementPendingBytes, writableWindow, write.
What calls writeAllocatedBytes()?
writeAllocatedBytes() is called by 1 function(s): write.

Analyze Your Own Codebase

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

Try Supermodel Free