Home / Class/ ChannelOutboundBuffer Class — netty Architecture

ChannelOutboundBuffer Class — netty Architecture

Architecture documentation for the ChannelOutboundBuffer class in ChannelOutboundBuffer.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807["ChannelOutboundBuffer"]
  46f9db3c_4c12_e902_d891_0b2ce0bab9ce["ChannelOutboundBuffer.java"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|defined in| 46f9db3c_4c12_e902_d891_0b2ce0bab9ce
  1a7e836c_9290_2bb0_6b88_2d6e11449415["ChannelOutboundBuffer()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| 1a7e836c_9290_2bb0_6b88_2d6e11449415
  88f982fc_caf9_0319_b65e_2fb365723618["addMessage()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| 88f982fc_caf9_0319_b65e_2fb365723618
  064bcac5_7f92_8d78_e146_94926c257464["addFlush()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| 064bcac5_7f92_8d78_e146_94926c257464
  edd2d6a1_6e66_f250_6201_d45b2f33f2fa["incrementPendingOutboundBytes()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| edd2d6a1_6e66_f250_6201_d45b2f33f2fa
  9442861d_ae43_c572_95ea_8e92ddbb709f["decrementPendingOutboundBytes()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| 9442861d_ae43_c572_95ea_8e92ddbb709f
  eebc2e03_942d_1252_0ab7_824d613db683["total()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| eebc2e03_942d_1252_0ab7_824d613db683
  21a7944b_22f8_5903_9aba_e7a211ff0695["Object()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| 21a7944b_22f8_5903_9aba_e7a211ff0695
  948f3827_1828_0b89_8925_e65b9805d4d9["currentProgress()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| 948f3827_1828_0b89_8925_e65b9805d4d9
  292a6543_4b71_d410_0730_589bb8ddbf08["progress()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| 292a6543_4b71_d410_0730_589bb8ddbf08
  6dea3e34_a4b3_484d_ed24_d39287511a5a["remove()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| 6dea3e34_a4b3_484d_ed24_d39287511a5a
  cd969e8c_0b55_2177_ee6c_1c15a5b3292f["remove0()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| cd969e8c_0b55_2177_ee6c_1c15a5b3292f
  115bcbdc_e7fe_ba2c_e179_c7225d8ea4db["removeEntry()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| 115bcbdc_e7fe_ba2c_e179_c7225d8ea4db
  0ede732b_f018_f649_0cfa_0293b2b30200["removeBytes()"]
  509b1bc5_7cdc_9ee4_03d9_31eb2203d807 -->|method| 0ede732b_f018_f649_0cfa_0293b2b30200

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java lines 54–898

public final class ChannelOutboundBuffer {
    // Assuming a 64-bit JVM:
    //  - 16 bytes object header
    //  - 6 reference fields
    //  - 2 long fields
    //  - 2 int fields
    //  - 1 boolean field
    //  - padding
    static final int CHANNEL_OUTBOUND_BUFFER_ENTRY_OVERHEAD =
            SystemPropertyUtil.getInt("io.netty.transport.outboundBufferEntrySizeOverhead", 96);

    private static final InternalLogger logger = InternalLoggerFactory.getInstance(ChannelOutboundBuffer.class);

    private static final FastThreadLocal<ByteBuffer[]> NIO_BUFFERS = new FastThreadLocal<ByteBuffer[]>() {
        @Override
        protected ByteBuffer[] initialValue() throws Exception {
            return new ByteBuffer[1024];
        }
    };

    private final Channel channel;

    // Entry(flushedEntry) --> ... Entry(unflushedEntry) --> ... Entry(tailEntry)
    //
    // The Entry that is the first in the linked-list structure that was flushed
    private Entry flushedEntry;
    // The Entry which is the first unflushed in the linked-list structure
    private Entry unflushedEntry;
    // The Entry which represents the tail of the buffer
    private Entry tailEntry;
    // The number of flushed entries that are not written yet
    private int flushed;

    private int nioBufferCount;
    private long nioBufferSize;

    private boolean inFail;

    private static final AtomicLongFieldUpdater<ChannelOutboundBuffer> TOTAL_PENDING_SIZE_UPDATER =
            AtomicLongFieldUpdater.newUpdater(ChannelOutboundBuffer.class, "totalPendingSize");

    @SuppressWarnings("UnusedDeclaration")
    private volatile long totalPendingSize;

    private static final AtomicIntegerFieldUpdater<ChannelOutboundBuffer> UNWRITABLE_UPDATER =
            AtomicIntegerFieldUpdater.newUpdater(ChannelOutboundBuffer.class, "unwritable");

    @SuppressWarnings("UnusedDeclaration")
    private volatile int unwritable;

    private volatile Runnable fireChannelWritabilityChangedTask;

    ChannelOutboundBuffer(AbstractChannel channel) {
        this.channel = channel;
    }

    /**
     * Add given message to this {@link ChannelOutboundBuffer}. The given {@link ChannelPromise} will be notified once
     * the message was written.
     */
    public void addMessage(Object msg, int size, ChannelPromise promise) {
        Entry entry = Entry.newInstance(msg, size, total(msg), promise);
        if (tailEntry == null) {
            flushedEntry = null;
        } else {
            Entry tail = tailEntry;
            tail.next = entry;
        }
        tailEntry = entry;
        if (unflushedEntry == null) {
            unflushedEntry = entry;
        }

        // Touch the message to make it easier to debug buffer leaks.

        // this save both checking against the ReferenceCounted interface
        // and makes better use of virtual calls vs interface ones
        if (msg instanceof AbstractReferenceCountedByteBuf) {
            ((AbstractReferenceCountedByteBuf) msg).touch();
        } else {
            ReferenceCountUtil.touch(msg);

Frequently Asked Questions

What is the ChannelOutboundBuffer class?
ChannelOutboundBuffer is a class in the netty codebase, defined in transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java.
Where is ChannelOutboundBuffer defined?
ChannelOutboundBuffer is defined in transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java at line 54.

Analyze Your Own Codebase

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

Try Supermodel Free