Home / Function/ write() — netty Function Reference

write() — netty Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  dabb27f9_26d0_6cce_3476_d90ad2682131["write()"]
  ba77a225_4637_fe77_ee1f_54a9774ca7f8["Http2FrameCodec"]
  dabb27f9_26d0_6cce_3476_d90ad2682131 -->|defined in| ba77a225_4637_fe77_ee1f_54a9774ca7f8
  eec5ebc4_e523_f193_b813_bbf1598e4e9f["id()"]
  dabb27f9_26d0_6cce_3476_d90ad2682131 -->|calls| eec5ebc4_e523_f193_b813_bbf1598e4e9f
  396fd1f5_befd_2a62_19e3_268bf7458c0e["writeHeadersFrame()"]
  dabb27f9_26d0_6cce_3476_d90ad2682131 -->|calls| 396fd1f5_befd_2a62_19e3_268bf7458c0e
  04411e16_ed38_8b7c_ab2f_823a00072c36["increaseInitialConnectionWindow()"]
  dabb27f9_26d0_6cce_3476_d90ad2682131 -->|calls| 04411e16_ed38_8b7c_ab2f_823a00072c36
  dafb708f_d534_42b0_93ed_f04119450f7d["consumeBytes()"]
  dabb27f9_26d0_6cce_3476_d90ad2682131 -->|calls| dafb708f_d534_42b0_93ed_f04119450f7d
  2f958372_1e41_1ad3_a4a7_5139b366d29b["writeGoAwayFrame()"]
  dabb27f9_26d0_6cce_3476_d90ad2682131 -->|calls| 2f958372_1e41_1ad3_a4a7_5139b366d29b
  6e205303_bd86_2dc6_ac06_0635c7f76774["writePushPromise()"]
  dabb27f9_26d0_6cce_3476_d90ad2682131 -->|calls| 6e205303_bd86_2dc6_ac06_0635c7f76774
  style dabb27f9_26d0_6cce_3476_d90ad2682131 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java lines 302–365

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
        if (msg instanceof Http2DataFrame) {
            Http2DataFrame dataFrame = (Http2DataFrame) msg;
            encoder().writeData(ctx, dataFrame.stream().id(), dataFrame.content(),
                    dataFrame.padding(), dataFrame.isEndStream(), promise);
        } else if (msg instanceof Http2HeadersFrame) {
            writeHeadersFrame(ctx, (Http2HeadersFrame) msg, promise);
        } else if (msg instanceof Http2WindowUpdateFrame) {
            Http2WindowUpdateFrame frame = (Http2WindowUpdateFrame) msg;
            Http2FrameStream frameStream = frame.stream();
            // It is legit to send a WINDOW_UPDATE frame for the connection stream. The parent channel doesn't attempt
            // to set the Http2FrameStream so we assume if it is null the WINDOW_UPDATE is for the connection stream.
            try {
                if (frameStream == null) {
                    increaseInitialConnectionWindow(frame.windowSizeIncrement());
                } else {
                    consumeBytes(frameStream.id(), frame.windowSizeIncrement());
                }
                promise.setSuccess();
            } catch (Throwable t) {
                promise.setFailure(t);
            }
        } else if (msg instanceof Http2ResetFrame) {
            Http2ResetFrame rstFrame = (Http2ResetFrame) msg;
            int id = rstFrame.stream().id();
            // Only ever send a reset frame if stream may have existed before as otherwise we may send a RST on a
            // stream in an invalid state and cause a connection error.
            if (connection().streamMayHaveExisted(id)) {
                encoder().writeRstStream(ctx, rstFrame.stream().id(), rstFrame.errorCode(), promise);
            } else {
                ReferenceCountUtil.release(rstFrame);
                promise.setFailure(Http2Exception.streamError(
                        rstFrame.stream().id(), Http2Error.PROTOCOL_ERROR, "Stream never existed"));
            }
        } else if (msg instanceof Http2PingFrame) {
            Http2PingFrame frame = (Http2PingFrame) msg;
            encoder().writePing(ctx, frame.ack(), frame.content(), promise);
        } else if (msg instanceof Http2SettingsFrame) {
            encoder().writeSettings(ctx, ((Http2SettingsFrame) msg).settings(), promise);
        } else if (msg instanceof Http2SettingsAckFrame) {
            // In the event of manual SETTINGS ACK, it is assumed the encoder will apply the earliest received but not
            // yet ACKed settings.
            encoder().writeSettingsAck(ctx, promise);
        } else if (msg instanceof Http2GoAwayFrame) {
            writeGoAwayFrame(ctx, (Http2GoAwayFrame) msg, promise);
        } else if (msg instanceof Http2PushPromiseFrame) {
            Http2PushPromiseFrame pushPromiseFrame = (Http2PushPromiseFrame) msg;
            writePushPromise(ctx, pushPromiseFrame, promise);
        } else if (msg instanceof Http2PriorityFrame) {
            Http2PriorityFrame priorityFrame = (Http2PriorityFrame) msg;
            encoder().writePriority(ctx, priorityFrame.stream().id(), priorityFrame.streamDependency(),
                    priorityFrame.weight(), priorityFrame.exclusive(), promise);
        } else if (msg instanceof Http2UnknownFrame) {
            Http2UnknownFrame unknownFrame = (Http2UnknownFrame) msg;
            encoder().writeFrame(ctx, unknownFrame.frameType(), unknownFrame.stream().id(),
                    unknownFrame.flags(), unknownFrame.content(), promise);
        } else if (!(msg instanceof Http2Frame)) {
            ctx.write(msg, promise);
        } else {
            ReferenceCountUtil.release(msg);
            throw new UnsupportedMessageTypeException(msg, SUPPORTED_MESSAGES);
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does write() do?
write() is a function in the netty codebase, defined in codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java.
Where is write() defined?
write() is defined in codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java at line 302.
What does write() call?
write() calls 6 function(s): consumeBytes, id, increaseInitialConnectionWindow, writeGoAwayFrame, writeHeadersFrame, writePushPromise.

Analyze Your Own Codebase

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

Try Supermodel Free