Home / Class/ UnpooledByteBufAllocator Class — netty Architecture

UnpooledByteBufAllocator Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  e5651d92_5383_a8ce_bfcd_cd981e4f9b40["UnpooledByteBufAllocator"]
  0b4b2671_fb24_9a0d_bc3a_aef00ae524b0["UnpooledByteBufAllocator.java"]
  e5651d92_5383_a8ce_bfcd_cd981e4f9b40 -->|defined in| 0b4b2671_fb24_9a0d_bc3a_aef00ae524b0
  7e60225a_5d7a_2f46_88d7_de46fcb36376["UnpooledByteBufAllocator()"]
  e5651d92_5383_a8ce_bfcd_cd981e4f9b40 -->|method| 7e60225a_5d7a_2f46_88d7_de46fcb36376
  2db8ecdf_07ef_92cb_6507_98b4bf0d5fbc["ByteBuf()"]
  e5651d92_5383_a8ce_bfcd_cd981e4f9b40 -->|method| 2db8ecdf_07ef_92cb_6507_98b4bf0d5fbc
  57cb49ec_4447_b2f1_bc74_56c1e750d687["CompositeByteBuf()"]
  e5651d92_5383_a8ce_bfcd_cd981e4f9b40 -->|method| 57cb49ec_4447_b2f1_bc74_56c1e750d687
  79aaa5e7_b883_60cf_bafd_94ac073a5968["isDirectBufferPooled()"]
  e5651d92_5383_a8ce_bfcd_cd981e4f9b40 -->|method| 79aaa5e7_b883_60cf_bafd_94ac073a5968
  4103597e_87dd_bff3_cc2c_fcfa9ec41c4e["ByteBufAllocatorMetric()"]
  e5651d92_5383_a8ce_bfcd_cd981e4f9b40 -->|method| 4103597e_87dd_bff3_cc2c_fcfa9ec41c4e
  a165a69c_bd61_4171_4627_569ebd6427e5["incrementDirect()"]
  e5651d92_5383_a8ce_bfcd_cd981e4f9b40 -->|method| a165a69c_bd61_4171_4627_569ebd6427e5
  4b85b556_2a4a_8153_b494_7ee0a3ca085a["decrementDirect()"]
  e5651d92_5383_a8ce_bfcd_cd981e4f9b40 -->|method| 4b85b556_2a4a_8153_b494_7ee0a3ca085a
  a8161e32_05f2_2814_d64d_f8a57a64cc40["incrementHeap()"]
  e5651d92_5383_a8ce_bfcd_cd981e4f9b40 -->|method| a8161e32_05f2_2814_d64d_f8a57a64cc40
  b7fa94a1_44bc_14c8_f9b7_6f4d1ea8bd33["decrementHeap()"]
  e5651d92_5383_a8ce_bfcd_cd981e4f9b40 -->|method| b7fa94a1_44bc_14c8_f9b7_6f4d1ea8bd33

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/UnpooledByteBufAllocator.java lines 28–304

public final class UnpooledByteBufAllocator extends AbstractByteBufAllocator implements ByteBufAllocatorMetricProvider {

    private final UnpooledByteBufAllocatorMetric metric = new UnpooledByteBufAllocatorMetric();
    private final boolean disableLeakDetector;
    private final boolean noCleaner;

    /**
     * Default instance which uses leak-detection for direct buffers.
     */
    public static final UnpooledByteBufAllocator DEFAULT =
            new UnpooledByteBufAllocator(PlatformDependent.directBufferPreferred());

    /**
     * Create a new instance which uses leak-detection for direct buffers.
     *
     * @param preferDirect {@code true} if {@link #buffer(int)} should try to allocate a direct buffer rather than
     *                     a heap buffer
     */
    public UnpooledByteBufAllocator(boolean preferDirect) {
        this(preferDirect, false);
    }

    /**
     * Create a new instance
     *
     * @param preferDirect {@code true} if {@link #buffer(int)} should try to allocate a direct buffer rather than
     *                     a heap buffer
     * @param disableLeakDetector {@code true} if the leak-detection should be disabled completely for this
     *                            allocator. This can be useful if the user just want to depend on the GC to handle
     *                            direct buffers when not explicit released.
     */
    public UnpooledByteBufAllocator(boolean preferDirect, boolean disableLeakDetector) {
        this(preferDirect, disableLeakDetector, PlatformDependent.useDirectBufferNoCleaner());
    }

    /**
     * Create a new instance
     *
     * @param preferDirect {@code true} if {@link #buffer(int)} should try to allocate a direct buffer rather than
     *                     a heap buffer
     * @param disableLeakDetector {@code true} if the leak-detection should be disabled completely for this
     *                            allocator. This can be useful if the user just want to depend on the GC to handle
     *                            direct buffers when not explicit released.
     * @param tryNoCleaner {@code true} if we should try to use {@link PlatformDependent#allocateDirectNoCleaner(int)}
     *                            to allocate direct memory.
     */
    public UnpooledByteBufAllocator(boolean preferDirect, boolean disableLeakDetector, boolean tryNoCleaner) {
        super(preferDirect);
        this.disableLeakDetector = disableLeakDetector;
        noCleaner = tryNoCleaner && PlatformDependent.hasUnsafe()
                && PlatformDependent.hasDirectBufferNoCleanerConstructor();
    }

    @Override
    protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity) {
        return PlatformDependent.hasUnsafe() ?
                new InstrumentedUnpooledUnsafeHeapByteBuf(this, initialCapacity, maxCapacity) :
                new InstrumentedUnpooledHeapByteBuf(this, initialCapacity, maxCapacity);
    }

    @Override
    protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity) {
        final ByteBuf buf;
        if (PlatformDependent.hasUnsafe()) {
            buf = noCleaner ? new InstrumentedUnpooledUnsafeNoCleanerDirectByteBuf(this, initialCapacity, maxCapacity) :
                    new InstrumentedUnpooledUnsafeDirectByteBuf(this, initialCapacity, maxCapacity);
        } else {
            buf = new InstrumentedUnpooledDirectByteBuf(this, initialCapacity, maxCapacity);
        }
        return disableLeakDetector ? buf : toLeakAwareBuffer(buf);
    }

    @Override
    public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
        CompositeByteBuf buf = new CompositeByteBuf(this, false, maxNumComponents);
        return disableLeakDetector ? buf : toLeakAwareBuffer(buf);
    }

    @Override
    public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) {
        CompositeByteBuf buf = new CompositeByteBuf(this, true, maxNumComponents);

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free