Class AbstractPooledDerivedByteBuf

All Implemented Interfaces:
ByteBufConvertible, ReferenceCounted, Comparable<ByteBuf>
Direct Known Subclasses:
PooledDuplicatedByteBuf, PooledSlicedByteBuf

abstract class AbstractPooledDerivedByteBuf extends AbstractReferenceCountedByteBuf
Abstract base class for derived ByteBuf implementations.
  • Field Details

    • recyclerHandle

    • rootParent

      private AbstractByteBuf rootParent
    • parent

      private ByteBuf parent
      Deallocations of a pooled derived buffer should always propagate through the entire chain of derived buffers. This is because each pooled derived buffer maintains its own reference count and we should respect each one. If deallocations cause a release of the "root parent" then then we may prematurely release the underlying content before all the derived buffers have been released.
  • Constructor Details

  • Method Details

    • parent

      final void parent(ByteBuf newParent)
    • unwrap

      public final AbstractByteBuf unwrap()
      Description copied from class: ByteBuf
      Return the underlying buffer instance if this buffer is a wrapper of another buffer.
      Specified by:
      unwrap in class ByteBuf
      Returns:
      null if this buffer is not a wrapper
    • init

      final <U extends AbstractPooledDerivedByteBuf> U init(AbstractByteBuf unwrapped, ByteBuf wrapped, int readerIndex, int writerIndex, int maxCapacity)
    • deallocate

      protected final void deallocate()
      Description copied from class: AbstractReferenceCountedByteBuf
      Specified by:
      deallocate in class AbstractReferenceCountedByteBuf
    • alloc

      public final ByteBufAllocator alloc()
      Description copied from class: ByteBuf
      Returns the ByteBufAllocator which created this buffer.
      Specified by:
      alloc in class ByteBuf
    • order

      @Deprecated public final ByteOrder order()
      Deprecated.
      Description copied from class: ByteBuf
      Returns the endianness of this buffer.
      Specified by:
      order in class ByteBuf
    • isReadOnly

      public boolean isReadOnly()
      Description copied from class: ByteBuf
      Returns true if and only if this buffer is read-only.
      Overrides:
      isReadOnly in class AbstractByteBuf
    • isDirect

      public final boolean isDirect()
      Description copied from class: ByteBuf
      Returns true if and only if this buffer is backed by an NIO direct buffer.
      Specified by:
      isDirect in class ByteBuf
    • hasArray

      public boolean hasArray()
      Description copied from class: ByteBuf
      Returns true if and only if this buffer has a backing byte array. If this method returns true, you can safely call ByteBuf.array() and ByteBuf.arrayOffset().
      Specified by:
      hasArray in class ByteBuf
    • array

      public byte[] array()
      Description copied from class: ByteBuf
      Returns the backing byte array of this buffer.
      Specified by:
      array in class ByteBuf
    • hasMemoryAddress

      public boolean hasMemoryAddress()
      Description copied from class: ByteBuf
      Returns true if and only if this buffer has a reference to the low-level memory address that points to the backing data.
      Specified by:
      hasMemoryAddress in class ByteBuf
    • isContiguous

      public boolean isContiguous()
      Description copied from class: ByteBuf
      Returns true if this ByteBuf implementation is backed by a single memory region. Composite buffer implementations must return false even if they currently hold ≤ 1 components. For buffers that return true, it's guaranteed that a successful call to ByteBuf.discardReadBytes() will increase the value of ByteBuf.maxFastWritableBytes() by the current readerIndex.

      This method will return false by default, and a false return value does not necessarily mean that the implementation is composite or that it is not backed by a single memory region.

      Overrides:
      isContiguous in class ByteBuf
    • nioBufferCount

      public final int nioBufferCount()
      Description copied from class: ByteBuf
      Returns the maximum number of NIO ByteBuffers that consist this buffer. Note that ByteBuf.nioBuffers() or ByteBuf.nioBuffers(int, int) might return a less number of ByteBuffers.
      Specified by:
      nioBufferCount in class ByteBuf
      Returns:
      -1 if this buffer has no underlying ByteBuffer. the number of the underlying ByteBuffers if this buffer has at least one underlying ByteBuffer. Note that this method does not return 0 to avoid confusion.
      See Also:
    • internalNioBuffer

      public final ByteBuffer internalNioBuffer(int index, int length)
      Description copied from class: ByteBuf
      Internal use only: Exposes the internal NIO buffer.
      Specified by:
      internalNioBuffer in class ByteBuf
    • retainedSlice

      public final ByteBuf retainedSlice()
      Description copied from class: ByteBuf
      Returns a retained slice of this buffer's readable bytes. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method is identical to buf.slice(buf.readerIndex(), buf.readableBytes()). This method does not modify readerIndex or writerIndex of this buffer.

      Note that this method returns a retained buffer unlike ByteBuf.slice(). This method behaves similarly to slice().retain() except that this method may return a buffer implementation that produces less garbage.

      Overrides:
      retainedSlice in class AbstractByteBuf
    • slice

      public ByteBuf slice(int index, int length)
      Description copied from class: ByteBuf
      Returns a slice of this buffer's sub-region. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method does not modify readerIndex or writerIndex of this buffer.

      Also be aware that this method will NOT call ByteBuf.retain() and so the reference count will NOT be increased.

      Overrides:
      slice in class AbstractByteBuf
    • duplicate0

      final ByteBuf duplicate0()