Class ElasticByteBufferPool

java.lang.Object
org.apache.hadoop.io.ElasticByteBufferPool
All Implemented Interfaces:
ByteBufferPool

@Public @Stable public class ElasticByteBufferPool extends Object implements ByteBufferPool
This is a simple ByteBufferPool which just creates ByteBuffers as needed. It also caches ByteBuffers after they're released. It will always return the smallest cached buffer with at least the capacity you request. We don't try to do anything clever here like try to limit the maximum cache size.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static final class 
    org.apache.hadoop.io.ElasticByteBufferPool.Key
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    getBuffer(boolean direct, int length)
    Get a new direct ByteBuffer.
    void
    Release a buffer back to the pool.
    int
    size(boolean direct)
    Get the size of the buffer pool, for the specified buffer type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.apache.hadoop.io.ByteBufferPool

    release
  • Constructor Details

    • ElasticByteBufferPool

      public ElasticByteBufferPool()
  • Method Details

    • getBuffer

      public ByteBuffer getBuffer(boolean direct, int length)
      Description copied from interface: ByteBufferPool
      Get a new direct ByteBuffer. The pool can provide this from removing a buffer from its internal cache, or by allocating a new buffer.
      Specified by:
      getBuffer in interface ByteBufferPool
      Parameters:
      direct - Whether the buffer should be direct.
      length - The minimum length the buffer will have.
      Returns:
      A new ByteBuffer. This ByteBuffer must be direct. Its capacity can be less than what was requested, but must be at least 1 byte.
    • putBuffer

      public void putBuffer(ByteBuffer buffer)
      Description copied from interface: ByteBufferPool
      Release a buffer back to the pool. The pool may choose to put this buffer into its cache.
      Specified by:
      putBuffer in interface ByteBufferPool
      Parameters:
      buffer - a direct bytebuffer
    • size

      @Private @Unstable public int size(boolean direct)
      Get the size of the buffer pool, for the specified buffer type.
      Parameters:
      direct - Whether the size is returned for direct buffers
      Returns:
      The size