Home / Function/ doFlush() — netty Function Reference

doFlush() — netty Function Reference

Architecture documentation for the doFlush() function in ChunkedWriteHandler.java from the netty codebase.

Function java Buffer Search calls 8 called by 4

Entity Profile

Dependency Diagram

graph TD
  fea31415_af69_2ea8_b80b_97ecc8e7b566["doFlush()"]
  1e2ef44e_6c44_8584_e44f_ddda636afcfc["ChunkedWriteHandler"]
  fea31415_af69_2ea8_b80b_97ecc8e7b566 -->|defined in| 1e2ef44e_6c44_8584_e44f_ddda636afcfc
  046072d4_e093_33e5_660c_bf415febf6ae["resumeTransfer0()"]
  046072d4_e093_33e5_660c_bf415febf6ae -->|calls| fea31415_af69_2ea8_b80b_97ecc8e7b566
  ca4aff08_0ab6_b222_41eb_bfd962af48d1["flush()"]
  ca4aff08_0ab6_b222_41eb_bfd962af48d1 -->|calls| fea31415_af69_2ea8_b80b_97ecc8e7b566
  e145c761_5751_60ec_c348_80f23ae93f51["channelInactive()"]
  e145c761_5751_60ec_c348_80f23ae93f51 -->|calls| fea31415_af69_2ea8_b80b_97ecc8e7b566
  28421229_489e_cc1d_e4c9_95eb3986af20["channelWritabilityChanged()"]
  28421229_489e_cc1d_e4c9_95eb3986af20 -->|calls| fea31415_af69_2ea8_b80b_97ecc8e7b566
  5e77e506_0716_aa80_bbd5_9ae4fe677c28["discard()"]
  fea31415_af69_2ea8_b80b_97ecc8e7b566 -->|calls| 5e77e506_0716_aa80_bbd5_9ae4fe677c28
  ca4aff08_0ab6_b222_41eb_bfd962af48d1["flush()"]
  fea31415_af69_2ea8_b80b_97ecc8e7b566 -->|calls| ca4aff08_0ab6_b222_41eb_bfd962af48d1
  59e2cd7c_239b_2a62_529d_0c2d9e0ea412["queueIsEmpty()"]
  fea31415_af69_2ea8_b80b_97ecc8e7b566 -->|calls| 59e2cd7c_239b_2a62_529d_0c2d9e0ea412
  53f15a4d_7833_59bc_0644_b2f3ba06936e["closeInput()"]
  fea31415_af69_2ea8_b80b_97ecc8e7b566 -->|calls| 53f15a4d_7833_59bc_0644_b2f3ba06936e
  570121a6_3ee2_7394_cad2_8834a8f7c228["fail()"]
  fea31415_af69_2ea8_b80b_97ecc8e7b566 -->|calls| 570121a6_3ee2_7394_cad2_8834a8f7c228
  12066d6b_de59_74be_d499_8c490cf6271c["handleEndOfInputFuture()"]
  fea31415_af69_2ea8_b80b_97ecc8e7b566 -->|calls| 12066d6b_de59_74be_d499_8c490cf6271c
  71234431_8f6b_489e_5bcd_2f90a680e153["handleFuture()"]
  fea31415_af69_2ea8_b80b_97ecc8e7b566 -->|calls| 71234431_8f6b_489e_5bcd_2f90a680e153
  8772a3c8_0f59_0a18_cfc7_49c932daeefd["write()"]
  fea31415_af69_2ea8_b80b_97ecc8e7b566 -->|calls| 8772a3c8_0f59_0a18_cfc7_49c932daeefd
  style fea31415_af69_2ea8_b80b_97ecc8e7b566 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java lines 207–328

    private void doFlush(final ChannelHandlerContext ctx) {
        final Channel channel = ctx.channel();
        if (!channel.isActive()) {
            // Even after discarding all previous queued objects we should propagate the flush through
            // to ensure previous written objects via writeAndFlush(...) that were not queued will be flushed and
            // so eventually fail the promise.
            discard(null);
            ctx.flush();
            return;
        }

        if (queueIsEmpty()) {
            ctx.flush();
            return;
        }

        boolean requiresFlush = true;
        ByteBufAllocator allocator = ctx.alloc();
        while (channel.isWritable()) {
            final PendingWrite currentWrite = queue.peek();

            if (currentWrite == null) {
                break;
            }

            if (currentWrite.promise.isDone()) {
                // This might happen e.g. in the case when a write operation
                // failed, but there are still unconsumed chunks left.
                // Most chunked input sources would stop generating chunks
                // and report end of input, but this doesn't work with any
                // source wrapped in HttpChunkedInput.
                // Note, that we're not trying to release the message/chunks
                // as this had to be done already by someone who resolved the
                // promise (using ChunkedInput.close method).
                // See https://github.com/netty/netty/issues/8700.
                queue.remove();
                continue;
            }

            final Object pendingMessage = currentWrite.msg;

            if (pendingMessage instanceof ChunkedInput) {
                final ChunkedInput<?> chunks = (ChunkedInput<?>) pendingMessage;
                boolean endOfInput;
                boolean suspend;
                Object message = null;
                try {
                    message = chunks.readChunk(allocator);
                    endOfInput = chunks.isEndOfInput();
                    // No need to suspend when reached at the end.
                    suspend = message == null && !endOfInput;

                } catch (final Throwable t) {
                    queue.remove();

                    if (message != null) {
                        ReferenceCountUtil.release(message);
                    }

                    closeInput(chunks);
                    currentWrite.fail(t);
                    break;
                }

                if (suspend) {
                    // ChunkedInput.nextChunk() returned null and it has
                    // not reached at the end of input. Let's wait until
                    // more chunks arrive. Nothing to write or notify.
                    break;
                }

                if (message == null) {
                    // If message is null write an empty ByteBuf.
                    // See https://github.com/netty/netty/issues/1671
                    message = Unpooled.EMPTY_BUFFER;
                }

                if (endOfInput) {
                    // We need to remove the element from the queue before we call writeAndFlush() as this operation
                    // may cause an action that also touches the queue.
                    queue.remove();

Domain

Subdomains

Frequently Asked Questions

What does doFlush() do?
doFlush() is a function in the netty codebase, defined in handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java.
Where is doFlush() defined?
doFlush() is defined in handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java at line 207.
What does doFlush() call?
doFlush() calls 8 function(s): closeInput, discard, fail, flush, handleEndOfInputFuture, handleFuture, queueIsEmpty, write.
What calls doFlush()?
doFlush() is called by 4 function(s): channelInactive, channelWritabilityChanged, flush, resumeTransfer0.

Analyze Your Own Codebase

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

Try Supermodel Free