Class BufferPool

java.lang.Object
org.apache.hadoop.fs.impl.prefetch.BufferPool
All Implemented Interfaces:
Closeable, AutoCloseable

public class BufferPool extends Object implements Closeable
Manages a fixed pool of ByteBuffer instances.

Avoids creating a new buffer if a previously created buffer is already available.

  • Constructor Details

    • BufferPool

      public BufferPool(int size, int bufferSize, PrefetchingStatistics prefetchingStatistics)
      Initializes a new instance of the BufferPool class.
      Parameters:
      size - number of buffer in this pool.
      bufferSize - size in bytes of each buffer.
      prefetchingStatistics - statistics for this stream.
      Throws:
      IllegalArgumentException - if size is zero or negative.
      IllegalArgumentException - if bufferSize is zero or negative.
  • Method Details

    • getAll

      public List<BufferData> getAll()
      Gets a list of all blocks in this pool.
      Returns:
      a list of all blocks in this pool.
    • acquire

      public BufferData acquire(int blockNumber)
      Acquires a ByteBuffer; blocking if necessary until one becomes available.
      Parameters:
      blockNumber - the id of the block to acquire.
      Returns:
      the acquired block's BufferData.
    • tryAcquire

      public BufferData tryAcquire(int blockNumber)
      Acquires a buffer if one is immediately available. Otherwise returns null.
      Parameters:
      blockNumber - the id of the block to try acquire.
      Returns:
      the acquired block's BufferData or null.
    • release

      public void release(BufferData data)
      Releases a previously acquired resource.
      Parameters:
      data - the BufferData instance to release.
      Throws:
      IllegalArgumentException - if data is null.
      IllegalArgumentException - if data cannot be released due to its state.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • toString

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

      public int numCreated()
    • numAvailable

      public int numAvailable()