Home / Class/ PendingWriteQueue Class — netty Architecture

PendingWriteQueue Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  83722386_341f_50b9_cd3a_d141138801ae["PendingWriteQueue"]
  7c730706_4857_23f2_d694_d1197e1b6af9["PendingWriteQueue.java"]
  83722386_341f_50b9_cd3a_d141138801ae -->|defined in| 7c730706_4857_23f2_d694_d1197e1b6af9
  16cd283d_aab9_ca01_5438_f6fe1156caaa["PendingWriteQueue()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| 16cd283d_aab9_ca01_5438_f6fe1156caaa
  ff536e40_0a4b_12c0_e94e_a2a0413256fb["isEmpty()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| ff536e40_0a4b_12c0_e94e_a2a0413256fb
  46561650_a7c0_09b3_f8da_a4d1c4544d81["size()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| 46561650_a7c0_09b3_f8da_a4d1c4544d81
  483ebe61_8165_99a5_8831_b7b67ac0c191["bytes()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| 483ebe61_8165_99a5_8831_b7b67ac0c191
  9045a57d_5230_2357_4ef7_f61e7cee74ba["add()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| 9045a57d_5230_2357_4ef7_f61e7cee74ba
  58e262d9_3782_2194_e391_e963af8a705d["ChannelFuture()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| 58e262d9_3782_2194_e391_e963af8a705d
  9465da28_383b_e0f3_4e91_d1dcedaa5bdf["removeAndFailAll()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| 9465da28_383b_e0f3_4e91_d1dcedaa5bdf
  f0f44ded_1e1e_19f3_602d_994b28cd58fb["removeAndFail()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| f0f44ded_1e1e_19f3_602d_994b28cd58fb
  2c764cb5_1103_a5d1_4774_278972921504["assertEmpty()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| 2c764cb5_1103_a5d1_4774_278972921504
  a74a1023_8945_1782_ee15_7f4896283503["ChannelPromise()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| a74a1023_8945_1782_ee15_7f4896283503
  617e4df4_9424_bd45_2693_30c49f4134b7["Object()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| 617e4df4_9424_bd45_2693_30c49f4134b7
  d80642d8_7dc6_939b_e48a_94fa31dc8c25["recycle()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| d80642d8_7dc6_939b_e48a_94fa31dc8c25
  a93247f6_033b_6516_d4f0_786bf935f89e["safeFail()"]
  83722386_341f_50b9_cd3a_d141138801ae -->|method| a93247f6_033b_6516_d4f0_786bf935f89e

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/PendingWriteQueue.java lines 34–341

public final class PendingWriteQueue {
    private static final InternalLogger logger = InternalLoggerFactory.getInstance(PendingWriteQueue.class);
    // Assuming a 64-bit JVM:
    //  - 16 bytes object header
    //  - 4 reference fields
    //  - 1 long fields
    private static final int PENDING_WRITE_OVERHEAD =
            SystemPropertyUtil.getInt("io.netty.transport.pendingWriteSizeOverhead", 64);

    private final ChannelOutboundInvoker invoker;
    private final EventExecutor executor;
    private final PendingBytesTracker tracker;

    // head and tail pointers for the linked-list structure. If empty head and tail are null.
    private PendingWrite head;
    private PendingWrite tail;
    private int size;
    private long bytes;

    public PendingWriteQueue(ChannelHandlerContext ctx) {
        tracker = PendingBytesTracker.newTracker(ctx.channel());
        this.invoker = ctx;
        this.executor = ctx.executor();
    }

    public PendingWriteQueue(Channel channel) {
        tracker = PendingBytesTracker.newTracker(channel);
        this.invoker = channel;
        this.executor = channel.eventLoop();
    }

    /**
     * Returns {@code true} if there are no pending write operations left in this queue.
     */
    public boolean isEmpty() {
        assert executor.inEventLoop();
        return head == null;
    }

    /**
     * Returns the number of pending write operations.
     */
    public int size() {
        assert executor.inEventLoop();
        return size;
    }

    /**
     * Returns the total number of bytes that are pending because of pending messages. This is only an estimate so
     * it should only be treated as a hint.
     */
    public long bytes() {
        assert executor.inEventLoop();
        return bytes;
    }

    private int size(Object msg) {
        // It is possible for writes to be triggered from removeAndFailAll(). To preserve ordering,
        // we should add them to the queue and let removeAndFailAll() fail them later.
        int messageSize = tracker.size(msg);
        if (messageSize < 0) {
            // Size may be unknown so just use 0
            messageSize = 0;
        }
        return messageSize + PENDING_WRITE_OVERHEAD;
    }

    /**
     * Add the given {@code msg} and {@link ChannelPromise}.
     */
    public void add(Object msg, ChannelPromise promise) {
        assert executor.inEventLoop();
        ObjectUtil.checkNotNull(msg, "msg");
        ObjectUtil.checkNotNull(promise, "promise");
        // It is possible for writes to be triggered from removeAndFailAll(). To preserve ordering,
        // we should add them to the queue and let removeAndFailAll() fail them later.
        int messageSize = size(msg);

        PendingWrite write = PendingWrite.newInstance(msg, messageSize, promise);
        PendingWrite currentTail = tail;
        if (currentTail == null) {

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free