Home / Class/ DefaultMessageSizeEstimator Class — netty Architecture

DefaultMessageSizeEstimator Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  f1c2337e_db2d_4566_3b41_ccca25c6bd54["DefaultMessageSizeEstimator"]
  be94460f_3964_b886_5959_e9a672808cdd["DefaultMessageSizeEstimator.java"]
  f1c2337e_db2d_4566_3b41_ccca25c6bd54 -->|defined in| be94460f_3964_b886_5959_e9a672808cdd
  641d3f17_eb49_2d56_f738_f95e2381bb11["DefaultMessageSizeEstimator()"]
  f1c2337e_db2d_4566_3b41_ccca25c6bd54 -->|method| 641d3f17_eb49_2d56_f738_f95e2381bb11
  7bf52b6e_566a_d889_0169_05364431b939["Handle()"]
  f1c2337e_db2d_4566_3b41_ccca25c6bd54 -->|method| 7bf52b6e_566a_d889_0169_05364431b939

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/DefaultMessageSizeEstimator.java lines 27–72

public final class DefaultMessageSizeEstimator implements MessageSizeEstimator {

    private static final class HandleImpl implements Handle {
        private final int unknownSize;

        private HandleImpl(int unknownSize) {
            this.unknownSize = unknownSize;
        }

        @Override
        public int size(Object msg) {
            if (msg instanceof ByteBuf) {
                return ((ByteBuf) msg).readableBytes();
            }
            if (msg instanceof ByteBufHolder) {
                return ((ByteBufHolder) msg).content().readableBytes();
            }
            if (msg instanceof FileRegion) {
                return 0;
            }
            return unknownSize;
        }
    }

    /**
     * Return the default implementation which returns {@code 8} for unknown messages.
     */
    public static final MessageSizeEstimator DEFAULT = new DefaultMessageSizeEstimator(8);

    private final Handle handle;

    /**
     * Create a new instance
     *
     * @param unknownSize       The size which is returned for unknown messages.
     */
    public DefaultMessageSizeEstimator(int unknownSize) {
        checkPositiveOrZero(unknownSize, "unknownSize");
        handle = new HandleImpl(unknownSize);
    }

    @Override
    public Handle newHandle() {
        return handle;
    }
}

Frequently Asked Questions

What is the DefaultMessageSizeEstimator class?
DefaultMessageSizeEstimator is a class in the netty codebase, defined in transport/src/main/java/io/netty/channel/DefaultMessageSizeEstimator.java.
Where is DefaultMessageSizeEstimator defined?
DefaultMessageSizeEstimator is defined in transport/src/main/java/io/netty/channel/DefaultMessageSizeEstimator.java at line 27.

Analyze Your Own Codebase

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

Try Supermodel Free