Class ArrayByteBufferPool

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

@ManagedObject public class ArrayByteBufferPool extends AbstractByteBufferPool implements Dumpable

A ByteBuffer pool where ByteBuffers are held in queues that are held in array elements.

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

  • Field Details

    • LOG

      private static final Logger LOG
    • _maxCapacity

      private final int _maxCapacity
    • _minCapacity

      private final int _minCapacity
    • _direct

      private final ByteBufferPool.Bucket[] _direct
    • _indirect

      private final ByteBufferPool.Bucket[] _indirect
    • _detailedDump

      private boolean _detailedDump
  • Constructor Details

    • ArrayByteBufferPool

      public ArrayByteBufferPool()
      Creates a new ArrayByteBufferPool with a default configuration.
    • ArrayByteBufferPool

      public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity)
      Creates a new ArrayByteBufferPool with the given configuration.
      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 maxQueueLength)
      Creates a new ArrayByteBufferPool with the given configuration.
      Parameters:
      minCapacity - the minimum ByteBuffer capacity
      factor - the capacity factor
      maxCapacity - the maximum ByteBuffer capacity
      maxQueueLength - the maximum ByteBuffer queue length
    • ArrayByteBufferPool

      public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxQueueLength, 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
      maxQueueLength - the maximum ByteBuffer queue length
      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.
  • Method Details

    • acquire

      public ByteBuffer acquire(int size, boolean direct)
      Description copied from interface: ByteBufferPool

      Requests a ByteBuffer of the given size.

      The returned buffer may have a bigger capacity than the size being requested but it will have the limit set to the given size.

      Specified by:
      acquire in interface ByteBufferPool
      Parameters:
      size - the size of the buffer
      direct - whether the buffer must be direct or not
      Returns:
      the requested buffer
      See Also:
    • release

      public void release(ByteBuffer buffer)
      Description copied from interface: ByteBufferPool

      Returns a ByteBuffer, usually obtained with ByteBufferPool.acquire(int, boolean) (but not necessarily), making it available for recycling and reuse.

      Specified by:
      release in interface ByteBufferPool
      Parameters:
      buffer - the buffer to return
      See Also:
    • newBucket

      private ByteBufferPool.Bucket newBucket(int key, boolean direct)
    • clear

      public void clear()
      Overrides:
      clear in class AbstractByteBufferPool
    • releaseMemory

      protected void releaseMemory(boolean direct)
    • bucketFor

      protected int bucketFor(int capacity)
    • capacityFor

      protected int capacityFor(int bucket)
    • bucketFor

      private ByteBufferPool.Bucket bucketFor(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()
    • getByteBufferCount

      private long getByteBufferCount(boolean direct)
    • bucketsFor

      ByteBufferPool.Bucket[] bucketsFor(boolean direct)
    • isDetailedDump

      public boolean isDetailedDump()
    • setDetailedDump

      public void setDetailedDump(boolean detailedDump)
    • 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