Home / Function/ write() — netty Function Reference

write() — netty Function Reference

Architecture documentation for the write() function in AbstractChannelHandlerContext.java from the netty codebase.

Function java Buffer Search calls 6 called by 2

Entity Profile

Dependency Diagram

graph TD
  99283ae3_ac1e_c2ab_31c8_7eec0221bc1c["write()"]
  219fdd98_e8e7_d4f7_fea0_eba60352e3de["AbstractChannelHandlerContext"]
  99283ae3_ac1e_c2ab_31c8_7eec0221bc1c -->|defined in| 219fdd98_e8e7_d4f7_fea0_eba60352e3de
  ecdd9021_5139_5faf_c9e9_00ec51590b75["ChannelFuture()"]
  ecdd9021_5139_5faf_c9e9_00ec51590b75 -->|calls| 99283ae3_ac1e_c2ab_31c8_7eec0221bc1c
  133fbebe_10e6_a3e9_8036_d39de250d4cd["run()"]
  133fbebe_10e6_a3e9_8036_d39de250d4cd -->|calls| 99283ae3_ac1e_c2ab_31c8_7eec0221bc1c
  7dbc9027_cf83_9c14_3f3e_8458eb46f7b9["validateWrite()"]
  99283ae3_ac1e_c2ab_31c8_7eec0221bc1c -->|calls| 7dbc9027_cf83_9c14_3f3e_8458eb46f7b9
  a25e13ec_7335_7e25_fe83_5b41ffe22020["invokeHandler()"]
  99283ae3_ac1e_c2ab_31c8_7eec0221bc1c -->|calls| a25e13ec_7335_7e25_fe83_5b41ffe22020
  b1146ab2_830a_2f47_42f2_bc9ab969ab97["notifyOutboundHandlerException()"]
  99283ae3_ac1e_c2ab_31c8_7eec0221bc1c -->|calls| b1146ab2_830a_2f47_42f2_bc9ab969ab97
  30046b18_f2a1_3cc6_01ab_3f4741be5605["invokeExceptionCaught()"]
  99283ae3_ac1e_c2ab_31c8_7eec0221bc1c -->|calls| 30046b18_f2a1_3cc6_01ab_3f4741be5605
  bca24481_45c3_570f_6222_6dfa6c8db7ea["safeExecute()"]
  99283ae3_ac1e_c2ab_31c8_7eec0221bc1c -->|calls| bca24481_45c3_570f_6222_6dfa6c8db7ea
  72e73230_ce94_86e0_b594_16bff83940a3["cancel()"]
  99283ae3_ac1e_c2ab_31c8_7eec0221bc1c -->|calls| 72e73230_ce94_86e0_b594_16bff83940a3
  style 99283ae3_ac1e_c2ab_31c8_7eec0221bc1c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java lines 780–841

    void write(Object msg, boolean flush, ChannelPromise promise) {
        if (validateWrite(msg, promise)) {
            final AbstractChannelHandlerContext next = findContextOutbound(flush ?
                    MASK_WRITE | MASK_FLUSH : MASK_WRITE);
            final Object m = pipeline.touch(msg, next);
            EventExecutor executor = next.executor();
            if (executor.inEventLoop()) {
                if (next.invokeHandler()) {
                    promise = ensurePromiseUseCorrectExecutor(promise);
                    try {
                        // DON'T CHANGE
                        // Duplex handlers implements both out/in interfaces causing a scalability issue
                        // see https://bugs.openjdk.org/browse/JDK-8180450
                        final ChannelHandler handler = next.handler();
                        final DefaultChannelPipeline.HeadContext headContext = pipeline.head;
                        if (handler == headContext) {
                            headContext.write(next, msg, promise);
                        } else if (handler instanceof ChannelDuplexHandler) {
                            ((ChannelDuplexHandler) handler).write(next, msg, promise);
                        } else if (handler instanceof ChannelOutboundHandlerAdapter) {
                            ((ChannelOutboundHandlerAdapter) handler).write(next, msg, promise);
                        } else {
                            ((ChannelOutboundHandler) handler).write(next, msg, promise);
                        }
                    } catch (Throwable t) {
                        notifyOutboundHandlerException(t, promise);
                    }
                    if (flush) {
                        try {
                            // DON'T CHANGE
                            // Duplex handlers implements both out/in interfaces causing a scalability issue
                            // see https://bugs.openjdk.org/browse/JDK-8180450
                            final ChannelHandler handler = next.handler();
                            final DefaultChannelPipeline.HeadContext headContext = pipeline.head;
                            if (handler == headContext) {
                                headContext.flush(next);
                            } else if (handler instanceof ChannelDuplexHandler) {
                                ((ChannelDuplexHandler) handler).flush(next);
                            } else if (handler instanceof ChannelOutboundHandlerAdapter) {
                                ((ChannelOutboundHandlerAdapter) handler).flush(next);
                            } else {
                                ((ChannelOutboundHandler) handler).flush(next);
                            }
                        } catch (Throwable t) {
                            next.invokeExceptionCaught(t);
                        }
                    }
                } else {
                    next.write(msg, flush, promise);
                }
            } else {
                final WriteTask task = WriteTask.newInstance(this, m, promise, flush);
                if (!safeExecute(executor, task, promise, m, !flush)) {
                    // We failed to submit the WriteTask. We need to cancel it so we decrement the pending bytes
                    // and put it back in the Recycler for re-use later.
                    //
                    // See https://github.com/netty/netty/issues/8343.
                    task.cancel();
                }
            }
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does write() do?
write() is a function in the netty codebase, defined in transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java.
Where is write() defined?
write() is defined in transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java at line 780.
What does write() call?
write() calls 6 function(s): cancel, invokeExceptionCaught, invokeHandler, notifyOutboundHandlerException, safeExecute, validateWrite.
What calls write()?
write() is called by 2 function(s): ChannelFuture, run.

Analyze Your Own Codebase

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

Try Supermodel Free