Home / Class/ SpliceInChannelTask Class — netty Architecture

SpliceInChannelTask Class — netty Architecture

Architecture documentation for the SpliceInChannelTask class in AbstractEpollStreamChannel.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  23ec46b5_b38a_813e_80f1_bf10cbf04b9b["SpliceInChannelTask"]
  70734405_31fd_71db_63bc_2114f3b39591["AbstractEpollStreamChannel.java"]
  23ec46b5_b38a_813e_80f1_bf10cbf04b9b -->|defined in| 70734405_31fd_71db_63bc_2114f3b39591
  11b85b7a_c3dd_3259_223e_ae4e2c173dc4["SpliceInChannelTask()"]
  23ec46b5_b38a_813e_80f1_bf10cbf04b9b -->|method| 11b85b7a_c3dd_3259_223e_ae4e2c173dc4
  cbeb9409_d71b_bde8_7eec_8a8f96a365ed["operationComplete()"]
  23ec46b5_b38a_813e_80f1_bf10cbf04b9b -->|method| cbeb9409_d71b_bde8_7eec_8a8f96a365ed
  bf05d7ae_8b8c_3fe2_87fc_0d5befffe40f["spliceIn()"]
  23ec46b5_b38a_813e_80f1_bf10cbf04b9b -->|method| bf05d7ae_8b8c_3fe2_87fc_0d5befffe40f

Relationship Graph

Source Code

transport-classes-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollStreamChannel.java lines 889–963

    private final class SpliceInChannelTask extends SpliceInTask implements ChannelFutureListener {
        private final AbstractEpollStreamChannel ch;

        SpliceInChannelTask(AbstractEpollStreamChannel ch, int len, ChannelPromise promise) {
            super(len, promise);
            this.ch = ch;
        }

        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (!future.isSuccess()) {
                // Use tryFailure(...) as the promise might already be closed by spliceTo(...)
                promise.tryFailure(future.cause());
            }
        }

        @Override
        public boolean spliceIn(RecvByteBufAllocator.Handle handle) {
            assert ch.eventLoop().inEventLoop();
            if (len == 0) {
                // Use trySuccess() as the promise might already be closed by spliceTo(...)
                promise.trySuccess();
                return true;
            }
            try {
                // We create the pipe on the target channel as this will allow us to just handle pending writes
                // later in a correct fashion without get into any ordering issues when spliceTo(...) is called
                // on multiple Channels pointing to one target Channel.
                FileDescriptor pipeOut = ch.pipeOut;
                if (pipeOut == null) {
                    // Create a new pipe as non was created before.
                    FileDescriptor[] pipe = pipe();
                    ch.pipeIn = pipe[0];
                    pipeOut = ch.pipeOut = pipe[1];
                }

                int splicedIn = spliceIn(pipeOut, handle);
                if (splicedIn > 0) {
                    // Integer.MAX_VALUE is a special value which will result in splice forever.
                    if (len != Integer.MAX_VALUE) {
                        len -= splicedIn;
                    }

                    // Depending on if we are done with splicing inbound data we set the right promise for the
                    // outbound splicing.
                    final ChannelPromise splicePromise;
                    if (len == 0) {
                        splicePromise = promise;
                    } else {
                        splicePromise = ch.newPromise().addListener(this);
                    }

                    boolean autoRead = config().isAutoRead();

                    // Just call unsafe().write(...) and flush() as we not want to traverse the whole pipeline for this
                    // case.
                    ch.unsafe().write(new SpliceOutTask(ch, splicedIn, autoRead), splicePromise);
                    ch.unsafe().flush();
                    if (autoRead && !splicePromise.isDone()) {
                        // Write was not done which means the target channel was not writable. In this case we need to
                        // disable reading until we are done with splicing to the target channel because:
                        //
                        // - The user may want to trigger another splice operation once the splicing was complete.
                        config().setAutoRead(false);
                    }
                }

                return len == 0;
            } catch (Throwable cause) {
                // Use tryFailure(...) as the promise might already be closed by spliceTo(...)
                promise.tryFailure(cause);
                return true;
            }
        }
    }

Frequently Asked Questions

What is the SpliceInChannelTask class?
SpliceInChannelTask is a class in the netty codebase, defined in transport-classes-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollStreamChannel.java.
Where is SpliceInChannelTask defined?
SpliceInChannelTask is defined in transport-classes-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollStreamChannel.java at line 889.

Analyze Your Own Codebase

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

Try Supermodel Free