Interface RetainableByteBuffer

All Superinterfaces:
Retainable
All Known Implementing Classes:
AbstractRetainableByteBuffer, ArrayByteBufferPool.Tracking.Buffer, NonRetainableByteBuffer, RetainableByteBuffer.Wrapper

public interface RetainableByteBuffer extends Retainable

A pooled ByteBuffer which maintains a reference count that is incremented with Retainable.retain() and decremented with Retainable.release().

The ByteBuffer is released to a ByteBufferPool when Retainable.release() is called one more time than Retainable.retain(); in such case, the call to Retainable.release() returns true.

A RetainableByteBuffer can either be:

  • Field Details

    • EMPTY

      static final RetainableByteBuffer EMPTY
      A Zero-capacity, non-retainable RetainableByteBuffer.
  • Method Details

    • wrap

      static RetainableByteBuffer wrap(ByteBuffer byteBuffer)

      Returns a non-retainable RetainableByteBuffer that wraps the given ByteBuffer.

      Use this method to wrap user-provided ByteBuffers, or ByteBuffers that hold constant bytes, to make them look like RetainableByteBuffers.

      The returned RetainableByteBuffer Retainable.canRetain() method always returns false.

      RetainableByteBuffers returned by this method are not suitable to be wrapped in other Retainable implementations that may delegate calls to Retainable.retain().

      Parameters:
      byteBuffer - the ByteBuffer to wrap
      Returns:
      a non-retainable RetainableByteBuffer
      See Also:
    • wrap

      static RetainableByteBuffer wrap(ByteBuffer byteBuffer, Retainable retainable)

      Returns a RetainableByteBuffer that wraps the given ByteBuffer and Retainable.

      Parameters:
      byteBuffer - the ByteBuffer to wrap
      retainable - the associated Retainable.
      Returns:
      a RetainableByteBuffer
      See Also:
    • isRetained

      boolean isRetained()
      Returns:
      whether this instance is retained
      See Also:
    • getByteBuffer

      ByteBuffer getByteBuffer()
      Get the wrapped, not null, ByteBuffer.
      Returns:
      the wrapped, not null, ByteBuffer
    • isDirect

      default boolean isDirect()
      Returns:
      whether the ByteBuffer is direct
    • remaining

      default int remaining()
      Returns:
      the number of remaining bytes in the ByteBuffer
    • hasRemaining

      default boolean hasRemaining()
      Returns:
      whether the ByteBuffer has remaining bytes
    • capacity

      default int capacity()
      Returns:
      the ByteBuffer capacity
    • clear

      default void clear()
      See Also: