org.szegedi.nbpipe
Interface ByteBufferPool

All Known Implementing Classes:
GlobalByteBufferPool

public interface ByteBufferPool

A ByteBufferPool is a facility for dinamically managing a large number of byte buffers. It manages both direct memory and file-mapped buffers. In a normal usage pattern, an application will start by requesting a memory buffer, then after a demand for memory rises, it will switch to file-based buffers.

Author:
Attila Szegedi, szegedia at freemail dot hu

Field Summary
static int TYPE_FILE
           
static int TYPE_MEMORY
           
static int TYPE_UNKNOWN
           
 
Method Summary
 int getBufferType(java.nio.ByteBuffer buffer)
           
 java.nio.ByteBuffer getFileBuffer()
          Returns a buffer from this pool.
 java.nio.ByteBuffer getMemoryBuffer()
          Returns a buffer from this pool.
 void putBuffer(java.nio.ByteBuffer buffer)
          Returns a buffer to this pool.
 

Field Detail

TYPE_MEMORY

public static final int TYPE_MEMORY
See Also:
Constant Field Values

TYPE_FILE

public static final int TYPE_FILE
See Also:
Constant Field Values

TYPE_UNKNOWN

public static final int TYPE_UNKNOWN
See Also:
Constant Field Values
Method Detail

getMemoryBuffer

public java.nio.ByteBuffer getMemoryBuffer()
Returns a buffer from this pool. The method first attempts to return a memory buffer. If one is not available, it attempts to return a file buffer. If neither a file buffer is available, it will (depending on whether the pool blocks when exhausted) block while a memory buffer becomes available, or allocate a new, non-direct, one-shot memory buffer from the heap.


getFileBuffer

public java.nio.ByteBuffer getFileBuffer()
Returns a buffer from this pool. The method first attempts to return a file buffer. If one is not available, it attempts to return a memory buffer. If neither a memory buffer is available, it will (depending on whether the pool blocks when exhausted) block while a file buffer becomes available, or allocate a new, non-direct, one-shot memory buffer from the heap.


putBuffer

public void putBuffer(java.nio.ByteBuffer buffer)
Returns a buffer to this pool. If the buffer is a non-direct buffer, it should be ignored. If the buffer is a direct buffer, but is recognized as not belonging to this pool, an IllegalArgumentException should be thrown.


getBufferType

public int getBufferType(java.nio.ByteBuffer buffer)