Home / Class/ StreamBufferingEncoder Class — netty Architecture

StreamBufferingEncoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  29cd10ea_888d_e1b6_5974_a15b31b4b5f0["StreamBufferingEncoder"]
  ac8d53b1_507e_5b73_32c3_3f65876877d4["StreamBufferingEncoder.java"]
  29cd10ea_888d_e1b6_5974_a15b31b4b5f0 -->|defined in| ac8d53b1_507e_5b73_32c3_3f65876877d4
  66cc61bb_136a_5dd1_784d_881906334bbe["StreamBufferingEncoder()"]
  29cd10ea_888d_e1b6_5974_a15b31b4b5f0 -->|method| 66cc61bb_136a_5dd1_784d_881906334bbe
  23791ec7_12f8_5603_1b79_812b4b57ac0a["numBufferedStreams()"]
  29cd10ea_888d_e1b6_5974_a15b31b4b5f0 -->|method| 23791ec7_12f8_5603_1b79_812b4b57ac0a
  a895a0e3_4e36_d3ff_a06d_b6dd4c4f3bce["ChannelFuture()"]
  29cd10ea_888d_e1b6_5974_a15b31b4b5f0 -->|method| a895a0e3_4e36_d3ff_a06d_b6dd4c4f3bce
  33aede06_2799_6b12_4676_81ebe46c7c10["remoteSettings()"]
  29cd10ea_888d_e1b6_5974_a15b31b4b5f0 -->|method| 33aede06_2799_6b12_4676_81ebe46c7c10
  44468faa_3bed_025a_119e_5a314295a695["updateMaxConcurrentStreams()"]
  29cd10ea_888d_e1b6_5974_a15b31b4b5f0 -->|method| 44468faa_3bed_025a_119e_5a314295a695
  816a34d0_fc4e_027e_c76d_4a3950770b27["close()"]
  29cd10ea_888d_e1b6_5974_a15b31b4b5f0 -->|method| 816a34d0_fc4e_027e_c76d_4a3950770b27
  f81a0cff_9108_6302_08c7_2675d219dd9a["tryCreatePendingStreams()"]
  29cd10ea_888d_e1b6_5974_a15b31b4b5f0 -->|method| f81a0cff_9108_6302_08c7_2675d219dd9a
  440abbd5_e217_88f8_a202_422cc785f39a["cancelGoAwayStreams()"]
  29cd10ea_888d_e1b6_5974_a15b31b4b5f0 -->|method| 440abbd5_e217_88f8_a202_422cc785f39a
  15029587_15ac_6e5d_907f_bdef7fd29acc["canCreateStream()"]
  29cd10ea_888d_e1b6_5974_a15b31b4b5f0 -->|method| 15029587_15ac_6e5d_907f_bdef7fd29acc
  25f32514_1933_ab55_e770_41bb38b3d7b8["isExistingStream()"]
  29cd10ea_888d_e1b6_5974_a15b31b4b5f0 -->|method| 25f32514_1933_ab55_e770_41bb38b3d7b8

Relationship Graph

Source Code

codec-http2/src/main/java/io/netty/handler/codec/http2/StreamBufferingEncoder.java lines 57–406

public class StreamBufferingEncoder extends DecoratingHttp2ConnectionEncoder {

    /**
     * Thrown if buffered streams are terminated due to this encoder being closed.
     */
    public static final class Http2ChannelClosedException extends Http2Exception {
        private static final long serialVersionUID = 4768543442094476971L;

        public Http2ChannelClosedException() {
            super(Http2Error.REFUSED_STREAM, "Connection closed");
        }
    }

    private static final class GoAwayDetail {
        private final int lastStreamId;
        private final long errorCode;
        private final byte[] debugData;

        GoAwayDetail(int lastStreamId, long errorCode, byte[] debugData) {
            this.lastStreamId = lastStreamId;
            this.errorCode = errorCode;
            this.debugData = debugData.clone();
        }
    }

    /**
     * Thrown by {@link StreamBufferingEncoder} if buffered streams are terminated due to
     * receipt of a {@code GOAWAY}.
     */
    public static final class Http2GoAwayException extends Http2Exception {
        private static final long serialVersionUID = 1326785622777291198L;
        private final GoAwayDetail goAwayDetail;

        public Http2GoAwayException(int lastStreamId, long errorCode, byte[] debugData) {
            this(new GoAwayDetail(lastStreamId, errorCode, debugData));
        }

        Http2GoAwayException(GoAwayDetail goAwayDetail) {
            super(Http2Error.STREAM_CLOSED);
            this.goAwayDetail = goAwayDetail;
        }

        public int lastStreamId() {
            return goAwayDetail.lastStreamId;
        }

        public long errorCode() {
            return goAwayDetail.errorCode;
        }

        public byte[] debugData() {
            return goAwayDetail.debugData.clone();
        }
    }

    /**
     * Buffer for any streams and corresponding frames that could not be created due to the maximum
     * concurrent stream limit being hit.
     */
    private final TreeMap<Integer, PendingStream> pendingStreams = new TreeMap<Integer, PendingStream>();
    private int maxConcurrentStreams;
    private boolean closed;
    private GoAwayDetail goAwayDetail;

    public StreamBufferingEncoder(Http2ConnectionEncoder delegate) {
        this(delegate, SMALLEST_MAX_CONCURRENT_STREAMS);
    }

    public StreamBufferingEncoder(Http2ConnectionEncoder delegate, int initialMaxConcurrentStreams) {
        super(delegate);
        maxConcurrentStreams = initialMaxConcurrentStreams;
        connection().addListener(new Http2ConnectionAdapter() {

            @Override
            public void onGoAwayReceived(int lastStreamId, long errorCode, ByteBuf debugData) {
                goAwayDetail = new GoAwayDetail(
                    // Using getBytes(..., false) is safe here as GoAwayDetail(...) will clone the byte[].
                    lastStreamId, errorCode,
                    ByteBufUtil.getBytes(debugData, debugData.readerIndex(), debugData.readableBytes(), false));
                cancelGoAwayStreams(goAwayDetail);
            }

Frequently Asked Questions

What is the StreamBufferingEncoder class?
StreamBufferingEncoder is a class in the netty codebase, defined in codec-http2/src/main/java/io/netty/handler/codec/http2/StreamBufferingEncoder.java.
Where is StreamBufferingEncoder defined?
StreamBufferingEncoder is defined in codec-http2/src/main/java/io/netty/handler/codec/http2/StreamBufferingEncoder.java at line 57.

Analyze Your Own Codebase

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

Try Supermodel Free