Home / Class/ FrameReadListener Class — netty Architecture

FrameReadListener Class — netty Architecture

Architecture documentation for the FrameReadListener class in DefaultHttp2ConnectionDecoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  0189a990_8f54_63f5_92fb_f168c031db1e["FrameReadListener"]
  a43ecbf7_4477_1770_e9bd_6bd36bd824e3["DefaultHttp2ConnectionDecoder.java"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|defined in| a43ecbf7_4477_1770_e9bd_6bd36bd824e3
  8d250926_1eab_67b5_7ae5_94ae1e073f54["onDataRead()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| 8d250926_1eab_67b5_7ae5_94ae1e073f54
  a7f0343e_581c_7e4a_796e_4e4c426bb22e["onHeadersRead()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| a7f0343e_581c_7e4a_796e_4e4c426bb22e
  b92057c2_3375_415d_8eff_8bd832d2e7da["onPriorityRead()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| b92057c2_3375_415d_8eff_8bd832d2e7da
  553507db_4414_04ec_77da_598c22714cba["onRstStreamRead()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| 553507db_4414_04ec_77da_598c22714cba
  e5e8d893_d71c_3912_5f16_c4fe70a744aa["onSettingsAckRead()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| e5e8d893_d71c_3912_5f16_c4fe70a744aa
  d255073a_061c_c1a7_3e47_5eba139b16a0["applyLocalSettings()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| d255073a_061c_c1a7_3e47_5eba139b16a0
  d780413a_8e67_042a_0c5e_5b57b04b4009["onSettingsRead()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| d780413a_8e67_042a_0c5e_5b57b04b4009
  9160568b_5ab7_eed1_a1e2_513bb43f2c2f["onPingRead()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| 9160568b_5ab7_eed1_a1e2_513bb43f2c2f
  2074e931_bfd6_dcf2_cc93_e3f1d31db7a8["onPingAckRead()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| 2074e931_bfd6_dcf2_cc93_e3f1d31db7a8
  081ac2df_dd8d_01c3_d08e_00974bf739a2["onPushPromiseRead()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| 081ac2df_dd8d_01c3_d08e_00974bf739a2
  eb465ea7_30d1_dedc_0515_575d1fb0044e["onGoAwayRead()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| eb465ea7_30d1_dedc_0515_575d1fb0044e
  53802dd0_94ed_d039_ec4b_e98bdf4f8d6f["onWindowUpdateRead()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| 53802dd0_94ed_d039_ec4b_e98bdf4f8d6f
  d0471baa_b036_62f4_478e_f36505626ac8["onUnknownFrame()"]
  0189a990_8f54_63f5_92fb_f168c031db1e -->|method| d0471baa_b036_62f4_478e_f36505626ac8

Relationship Graph

Source Code

codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java lines 250–694

    private final class FrameReadListener implements Http2FrameListener {
        @Override
        public int onDataRead(final ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding,
                              boolean endOfStream) throws Http2Exception {
            Http2Stream stream = connection.stream(streamId);
            Http2LocalFlowController flowController = flowController();
            int readable = data.readableBytes();
            int bytesToReturn = readable + padding;

            final boolean shouldIgnore;
            try {
                shouldIgnore = shouldIgnoreHeadersOrDataFrame(ctx, streamId, stream, endOfStream, "DATA");
            } catch (Http2Exception e) {
                // Ignoring this frame. We still need to count the frame towards the connection flow control
                // window, but we immediately mark all bytes as consumed.
                flowController.receiveFlowControlledFrame(stream, data, padding, endOfStream);
                flowController.consumeBytes(stream, bytesToReturn);
                throw e;
            } catch (Throwable t) {
                throw connectionError(INTERNAL_ERROR, t, "Unhandled error on data stream id %d", streamId);
            }

            if (shouldIgnore) {
                // Ignoring this frame. We still need to count the frame towards the connection flow control
                // window, but we immediately mark all bytes as consumed.
                flowController.receiveFlowControlledFrame(stream, data, padding, endOfStream);
                flowController.consumeBytes(stream, bytesToReturn);

                // Verify that the stream may have existed after we apply flow control.
                verifyStreamMayHaveExisted(streamId, endOfStream, "DATA");

                // All bytes have been consumed.
                return bytesToReturn;
            }
            Http2Exception error = null;
            switch (stream.state()) {
                case OPEN:
                case HALF_CLOSED_LOCAL:
                    break;
                case HALF_CLOSED_REMOTE:
                case CLOSED:
                    error = streamError(stream.id(), STREAM_CLOSED, "Stream %d in unexpected state: %s",
                        stream.id(), stream.state());
                    break;
                default:
                    error = streamError(stream.id(), PROTOCOL_ERROR,
                        "Stream %d in unexpected state: %s", stream.id(), stream.state());
                    break;
            }

            int unconsumedBytes = unconsumedBytes(stream);
            try {
                flowController.receiveFlowControlledFrame(stream, data, padding, endOfStream);
                // Update the unconsumed bytes after flow control is applied.
                unconsumedBytes = unconsumedBytes(stream);

                // If the stream is in an invalid state to receive the frame, throw the error.
                if (error != null) {
                    throw error;
                }

                verifyContentLength(stream, readable, endOfStream);

                // Call back the application and retrieve the number of bytes that have been
                // immediately processed.
                bytesToReturn = listener.onDataRead(ctx, streamId, data, padding, endOfStream);

                if (endOfStream) {
                    lifecycleManager.closeStreamRemote(stream, ctx.newSucceededFuture());
                }

                return bytesToReturn;
            } catch (Http2Exception | RuntimeException e) {
                // If an exception happened during delivery, the listener may have returned part
                // of the bytes before the error occurred. If that's the case, subtract that from
                // the total processed bytes so that we don't return too many bytes.
                int delta = unconsumedBytes - unconsumedBytes(stream);
                bytesToReturn -= delta;
                throw e;
            } finally {
                // If appropriate, return the processed bytes to the flow controller.

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free