Class ArrayRetainableByteBufferPool

java.lang.Object
org.eclipse.jetty.io.ArrayRetainableByteBufferPool
All Implemented Interfaces:
RetainableByteBufferPool, Dumpable
Direct Known Subclasses:
ArrayByteBufferPool.Retained, LogarithmicArrayByteBufferPool.LogarithmicRetainablePool, MappedByteBufferPool.Retained

@ManagedObject public class ArrayRetainableByteBufferPool extends Object implements RetainableByteBufferPool, Dumpable

A RetainableByteBuffer pool where RetainableByteBuffers are held in Pools that are held in array elements.

Given a capacity factor of 1024, the first array element holds a Pool of RetainableByteBuffers each of capacity 1024, the second array element holds a Pool of RetainableByteBuffers each of capacity 2048, and so on.

The maxHeapMemory and maxDirectMemory default heuristic is to use Runtime.maxMemory() divided by 4.

  • Constructor Details

    • ArrayRetainableByteBufferPool

      public ArrayRetainableByteBufferPool()
      Creates a new ArrayRetainableByteBufferPool with a default configuration. Both maxHeapMemory and maxDirectMemory default to 0 to use default heuristic.
    • ArrayRetainableByteBufferPool

      public ArrayRetainableByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize)
      Creates a new ArrayRetainableByteBufferPool with the given configuration. Both maxHeapMemory and maxDirectMemory default to 0 to use default heuristic.
      Parameters:
      minCapacity - the minimum ByteBuffer capacity
      factor - the capacity factor
      maxCapacity - the maximum ByteBuffer capacity
      maxBucketSize - the maximum number of ByteBuffers for each bucket
    • ArrayRetainableByteBufferPool

      public ArrayRetainableByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory)
      Creates a new ArrayRetainableByteBufferPool with the given configuration.
      Parameters:
      minCapacity - the minimum ByteBuffer capacity
      factor - the capacity factor
      maxCapacity - the maximum ByteBuffer capacity
      maxBucketSize - the maximum number of ByteBuffers for each bucket
      maxHeapMemory - the max heap memory in bytes, -1 for unlimited memory or 0 to use default heuristic
      maxDirectMemory - the max direct memory in bytes, -1 for unlimited memory or 0 to use default heuristic
    • ArrayRetainableByteBufferPool

      protected ArrayRetainableByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory, Function<Integer,Integer> bucketIndexFor, Function<Integer,Integer> bucketCapacity)
      Creates a new ArrayRetainableByteBufferPool with the given configuration.
      Parameters:
      minCapacity - the minimum ByteBuffer capacity
      factor - the capacity factor
      maxCapacity - the maximum ByteBuffer capacity
      maxBucketSize - the maximum number of ByteBuffers for each bucket
      maxHeapMemory - the max heap memory in bytes, -1 for unlimited memory or 0 to use default heuristic
      maxDirectMemory - the max direct memory in bytes, -1 for unlimited memory or 0 to use default heuristic
      bucketIndexFor - a Function that takes a capacity and returns a bucket index
      bucketCapacity - a Function that takes a bucket index and returns a capacity
  • Method Details

    • getMinCapacity

      @ManagedAttribute("The minimum pooled buffer capacity") public int getMinCapacity()
    • getMaxCapacity

      @ManagedAttribute("The maximum pooled buffer capacity") public int getMaxCapacity()
    • acquire

      public RetainableByteBuffer acquire(int size, boolean direct)
      Description copied from interface: RetainableByteBufferPool
      Acquires a memory buffer from the pool.
      Specified by:
      acquire in interface RetainableByteBufferPool
      Parameters:
      size - The size of the buffer. The returned buffer will have at least this capacity.
      direct - true if a direct memory buffer is needed, false otherwise.
      Returns:
      a memory buffer with position and size set to 0.
    • allocate

      protected ByteBuffer allocate(int capacity)
    • allocateDirect

      protected ByteBuffer allocateDirect(int capacity)
    • removed

      protected void removed(RetainableByteBuffer retainedBuffer)
    • poolFor

      protected Pool<RetainableByteBuffer> poolFor(int capacity, boolean direct)
    • getDirectByteBufferCount

      @ManagedAttribute("The number of pooled direct ByteBuffers") public long getDirectByteBufferCount()
    • getHeapByteBufferCount

      @ManagedAttribute("The number of pooled heap ByteBuffers") public long getHeapByteBufferCount()
    • getAvailableDirectByteBufferCount

      @ManagedAttribute("The number of pooled direct ByteBuffers that are available") public long getAvailableDirectByteBufferCount()
    • getAvailableHeapByteBufferCount

      @ManagedAttribute("The number of pooled heap ByteBuffers that are available") public long getAvailableHeapByteBufferCount()
    • getDirectMemory

      @ManagedAttribute("The bytes retained by direct ByteBuffers") public long getDirectMemory()
    • getHeapMemory

      @ManagedAttribute("The bytes retained by heap ByteBuffers") public long getHeapMemory()
    • getAvailableDirectMemory

      @ManagedAttribute("The available bytes retained by direct ByteBuffers") public long getAvailableDirectMemory()
    • getAvailableHeapMemory

      @ManagedAttribute("The available bytes retained by heap ByteBuffers") public long getAvailableHeapMemory()
    • clear

      @ManagedOperation(value="Clears this RetainableByteBufferPool", impact="ACTION") public void clear()
      Specified by:
      clear in interface RetainableByteBufferPool
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • dump

      public void dump(Appendable out, String indent) throws IOException
      Description copied from interface: Dumpable
      Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
      Specified by:
      dump in interface Dumpable
      Parameters:
      out - The appendable to dump to
      indent - The indent to apply after any new lines.
      Throws:
      IOException - if unable to write to Appendable