Class BufferPool
java.lang.Object
org.apache.hadoop.fs.impl.prefetch.BufferPool
- All Implemented Interfaces:
Closeable,AutoCloseable
Manages a fixed pool of
ByteBuffer instances.
Avoids creating a new buffer if a previously created buffer is already available.
-
Constructor Summary
ConstructorsConstructorDescriptionBufferPool(int size, int bufferSize, PrefetchingStatistics prefetchingStatistics) Initializes a new instance of theBufferPoolclass. -
Method Summary
Modifier and TypeMethodDescriptionacquire(int blockNumber) Acquires aByteBuffer; blocking if necessary until one becomes available.voidclose()getAll()Gets a list of all blocks in this pool.intintvoidrelease(BufferData data) Releases a previously acquired resource.toString()tryAcquire(int blockNumber) Acquires a buffer if one is immediately available.
-
Constructor Details
-
BufferPool
Initializes a new instance of theBufferPoolclass.- 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
Gets a list of all blocks in this pool.- Returns:
- a list of all blocks in this pool.
-
acquire
Acquires aByteBuffer; blocking if necessary until one becomes available.- Parameters:
blockNumber- the id of the block to acquire.- Returns:
- the acquired block's
BufferData.
-
tryAcquire
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
BufferDataor null.
-
release
Releases a previously acquired resource.- Parameters:
data- theBufferDatainstance to release.- Throws:
IllegalArgumentException- if data is null.IllegalArgumentException- if data cannot be released due to its state.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
toString
-
numCreated
public int numCreated() -
numAvailable
public int numAvailable()
-