Home / Class/ TestNumReadsRecvByteBufAllocator Class — netty Architecture

TestNumReadsRecvByteBufAllocator Class — netty Architecture

Architecture documentation for the TestNumReadsRecvByteBufAllocator class in SocketHalfClosedTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  38ffc96b_e914_9350_94c3_286119b0d901["TestNumReadsRecvByteBufAllocator"]
  f83511ba_39cb_73dd_453f_92c6a5fe10ae["SocketHalfClosedTest.java"]
  38ffc96b_e914_9350_94c3_286119b0d901 -->|defined in| f83511ba_39cb_73dd_453f_92c6a5fe10ae
  2667c82c_a70f_32b0_7185_86903848b6b0["TestNumReadsRecvByteBufAllocator()"]
  38ffc96b_e914_9350_94c3_286119b0d901 -->|method| 2667c82c_a70f_32b0_7185_86903848b6b0
  c33178d3_b88c_79e4_05de_cd364c9ea4f2["ExtendedHandle()"]
  38ffc96b_e914_9350_94c3_286119b0d901 -->|method| c33178d3_b88c_79e4_05de_cd364c9ea4f2

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketHalfClosedTest.java lines 796–864

    private static final class TestNumReadsRecvByteBufAllocator implements RecvByteBufAllocator {
        private final int numReads;
        TestNumReadsRecvByteBufAllocator(int numReads) {
            this.numReads = numReads;
        }

        @Override
        public ExtendedHandle newHandle() {
            return new ExtendedHandle() {
                private int attemptedBytesRead;
                private int lastBytesRead;
                private int numMessagesRead;
                @Override
                public ByteBuf allocate(ByteBufAllocator alloc) {
                    return alloc.ioBuffer(guess(), guess());
                }

                @Override
                public int guess() {
                    return 1; // only ever allocate buffers of size 1 to ensure the number of reads is controlled.
                }

                @Override
                public void reset(ChannelConfig config) {
                    numMessagesRead = 0;
                }

                @Override
                public void incMessagesRead(int numMessages) {
                    numMessagesRead += numMessages;
                }

                @Override
                public void lastBytesRead(int bytes) {
                    lastBytesRead = bytes;
                }

                @Override
                public int lastBytesRead() {
                    return lastBytesRead;
                }

                @Override
                public void attemptedBytesRead(int bytes) {
                    attemptedBytesRead = bytes;
                }

                @Override
                public int attemptedBytesRead() {
                    return attemptedBytesRead;
                }

                @Override
                public boolean continueReading() {
                    return numMessagesRead < numReads;
                }

                @Override
                public boolean continueReading(UncheckedBooleanSupplier maybeMoreDataSupplier) {
                    return continueReading() && maybeMoreDataSupplier.get();
                }

                @Override
                public void readComplete() {
                    // Nothing needs to be done or adjusted after each read cycle is completed.
                }
            };
        }
    }

Frequently Asked Questions

What is the TestNumReadsRecvByteBufAllocator class?
TestNumReadsRecvByteBufAllocator is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketHalfClosedTest.java.
Where is TestNumReadsRecvByteBufAllocator defined?
TestNumReadsRecvByteBufAllocator is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketHalfClosedTest.java at line 796.

Analyze Your Own Codebase

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

Try Supermodel Free