Class ArrayByteBufferPool

java.lang.Object
org.eclipse.jetty.io.ArrayByteBufferPool
All Implemented Interfaces:
ByteBufferPool, Dumpable
Direct Known Subclasses:
ArrayByteBufferPool.Quadratic, ArrayByteBufferPool.Tracking

@ManagedObject public class ArrayByteBufferPool extends Object implements ByteBufferPool, 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 with capacities 3072, 4096, 5120, etc.

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

  • Constructor Details

    • ArrayByteBufferPool

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

      public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity)
      Creates a new ArrayByteBufferPool 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
    • ArrayByteBufferPool

      public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize)
      Creates a new ArrayByteBufferPool 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
    • ArrayByteBufferPool

      public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory)
      Creates a new ArrayByteBufferPool 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
    • ArrayByteBufferPool

      protected ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory, IntUnaryOperator bucketIndexFor, IntUnaryOperator bucketCapacity)
      Creates a new ArrayByteBufferPool 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 IntUnaryOperator that takes a capacity and returns a bucket index
      bucketCapacity - a IntUnaryOperator that takes a bucket index and returns a capacity
  • Method Details

    • isStatisticsEnabled

      @ManagedAttribute("Whether statistics are enabled") public boolean isStatisticsEnabled()
    • setStatisticsEnabled

      public void setStatisticsEnabled(boolean enabled)
    • 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: ByteBufferPool

      Acquires a RetainableByteBuffer from this pool.

      Specified by:
      acquire in interface ByteBufferPool
      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 RetainableByteBuffer with position and limit set to 0.
    • removeAndRelease

      public boolean removeAndRelease(RetainableByteBuffer buffer)
      Description copied from interface: ByteBufferPool
      Release the buffer in a way that will remove it from any pool that it may be in. If the buffer is not in a pool, calling this method is equivalent to calling Retainable.release(). Calling this method satisfies any contract that requires a call to Retainable.release().
      Specified by:
      removeAndRelease in interface ByteBufferPool
      Returns:
      true if a call to Retainable.release() would have returned true.
      See Also:
    • poolFor

      public 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

      public long getAvailableDirectMemory()
    • getAvailableHeapMemory

      public long getAvailableHeapMemory()
    • clear

      @ManagedOperation(value="Clears this ByteBufferPool", impact="ACTION") public void clear()
      Description copied from interface: ByteBufferPool

      Removes all non-retained pooled instances from this pool.

      Specified by:
      clear in interface ByteBufferPool
    • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object