Home / Class/ AbstractByteBufAllocator Class — netty Architecture

AbstractByteBufAllocator Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  736a25f3_56bb_7053_ff2f_de4baf6ec402["AbstractByteBufAllocator"]
  b9a9ce64_caae_409a_1611_8cf05560a231["AbstractByteBufAllocator.java"]
  736a25f3_56bb_7053_ff2f_de4baf6ec402 -->|defined in| b9a9ce64_caae_409a_1611_8cf05560a231
  51c536f6_5e7d_0f0f_895c_72efa2477f4a["ByteBuf()"]
  736a25f3_56bb_7053_ff2f_de4baf6ec402 -->|method| 51c536f6_5e7d_0f0f_895c_72efa2477f4a
  e73fb8d4_01f0_a977_a5a3_6d9e0761346b["CompositeByteBuf()"]
  736a25f3_56bb_7053_ff2f_de4baf6ec402 -->|method| e73fb8d4_01f0_a977_a5a3_6d9e0761346b
  79e3f940_8943_5876_1a8e_9914cb7e2a9b["AbstractByteBufAllocator()"]
  736a25f3_56bb_7053_ff2f_de4baf6ec402 -->|method| 79e3f940_8943_5876_1a8e_9914cb7e2a9b
  19555353_59a6_a0fa_b7c4_6ca326afbc6e["validate()"]
  736a25f3_56bb_7053_ff2f_de4baf6ec402 -->|method| 19555353_59a6_a0fa_b7c4_6ca326afbc6e
  b408795c_edb1_6eb8_6161_c2ef0b3a3a58["String()"]
  736a25f3_56bb_7053_ff2f_de4baf6ec402 -->|method| b408795c_edb1_6eb8_6161_c2ef0b3a3a58
  7172b923_cb28_190b_8ff2_7986d51e1946["calculateNewCapacity()"]
  736a25f3_56bb_7053_ff2f_de4baf6ec402 -->|method| 7172b923_cb28_190b_8ff2_7986d51e1946

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java lines 30–260

public abstract class AbstractByteBufAllocator implements ByteBufAllocator {
    static final int DEFAULT_INITIAL_CAPACITY = 256;
    static final int DEFAULT_MAX_CAPACITY = Integer.MAX_VALUE;
    static final int DEFAULT_MAX_COMPONENTS = 16;
    static final int CALCULATE_THRESHOLD = 1048576 * 4; // 4 MiB page

    static {
        ResourceLeakDetector.addExclusions(AbstractByteBufAllocator.class, "toLeakAwareBuffer");
    }

    protected static ByteBuf toLeakAwareBuffer(ByteBuf buf) {
        ResourceLeakTracker<ByteBuf> leak = AbstractByteBuf.leakDetector.track(buf);
        if (leak != null) {
            if (AbstractByteBuf.leakDetector.isRecordEnabled()) {
                buf = new AdvancedLeakAwareByteBuf(buf, leak);
            } else {
                buf = new SimpleLeakAwareByteBuf(buf, leak);
            }
        }
        return buf;
    }

    protected static CompositeByteBuf toLeakAwareBuffer(CompositeByteBuf buf) {
        ResourceLeakTracker<ByteBuf> leak = AbstractByteBuf.leakDetector.track(buf);
        if (leak != null) {
            if (AbstractByteBuf.leakDetector.isRecordEnabled()) {
                buf = new AdvancedLeakAwareCompositeByteBuf(buf, leak);
            } else {
                buf = new SimpleLeakAwareCompositeByteBuf(buf, leak);
            }
        }
        return buf;
    }

    private final boolean directByDefault;
    private final ByteBuf emptyBuf;

    /**
     * Instance use heap buffers by default
     */
    protected AbstractByteBufAllocator() {
        this(false);
    }

    /**
     * Create new instance
     *
     * @param preferDirect {@code true} if {@link #buffer(int)} should try to allocate a direct buffer rather than
     *                     a heap buffer
     */
    protected AbstractByteBufAllocator(boolean preferDirect) {
        directByDefault = preferDirect && PlatformDependent.canReliabilyFreeDirectBuffers();
        emptyBuf = new EmptyByteBuf(this);
    }

    @Override
    public ByteBuf buffer() {
        if (directByDefault) {
            return directBuffer();
        }
        return heapBuffer();
    }

    @Override
    public ByteBuf buffer(int initialCapacity) {
        if (directByDefault) {
            return directBuffer(initialCapacity);
        }
        return heapBuffer(initialCapacity);
    }

    @Override
    public ByteBuf buffer(int initialCapacity, int maxCapacity) {
        if (directByDefault) {
            return directBuffer(initialCapacity, maxCapacity);
        }
        return heapBuffer(initialCapacity, maxCapacity);
    }

    @Override
    public ByteBuf ioBuffer() {

Frequently Asked Questions

What is the AbstractByteBufAllocator class?
AbstractByteBufAllocator is a class in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java.
Where is AbstractByteBufAllocator defined?
AbstractByteBufAllocator is defined in buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java at line 30.

Analyze Your Own Codebase

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

Try Supermodel Free