@InterfaceAudience.Private public class ByteBufferPool extends Object
Note: This pool returns off heap ByteBuffers by default. If on heap ByteBuffers to be pooled, pass 'directByteBuffer' as false while construction of the pool.
This class is thread safe.
ByteBufferListOutputStream| Modifier and Type | Field and Description |
|---|---|
static String |
BUFFER_SIZE_KEY |
private Queue<ByteBuffer> |
buffers |
private int |
bufferSize |
private AtomicInteger |
count |
static int |
DEFAULT_BUFFER_SIZE |
private boolean |
directByteBuffer |
private static org.slf4j.Logger |
LOG |
static String |
MAX_POOL_SIZE_KEY |
private int |
maxPoolSize |
private boolean |
maxPoolSizeInfoLevelLogged |
| Constructor and Description |
|---|
ByteBufferPool(int bufferSize,
int maxPoolSize) |
ByteBufferPool(int bufferSize,
int maxPoolSize,
boolean directByteBuffer) |
| Modifier and Type | Method and Description |
|---|---|
ByteBuffer |
getBuffer() |
int |
getBufferSize() |
int |
getQueueSize() |
void |
putbackBuffer(ByteBuffer buf)
Return back a ByteBuffer after its use.
|
private static final org.slf4j.Logger LOG
public static final String MAX_POOL_SIZE_KEY
public static final String BUFFER_SIZE_KEY
public static final int DEFAULT_BUFFER_SIZE
private final Queue<ByteBuffer> buffers
private final int bufferSize
private final int maxPoolSize
private AtomicInteger count
private final boolean directByteBuffer
private boolean maxPoolSizeInfoLevelLogged
public ByteBufferPool(int bufferSize, int maxPoolSize)
bufferSize - Size of each buffer created by this pool.maxPoolSize - Max number of buffers to keep in this pool.public ByteBufferPool(int bufferSize, int maxPoolSize, boolean directByteBuffer)
bufferSize - Size of each buffer created by this pool.maxPoolSize - Max number of buffers to keep in this pool.directByteBuffer - Whether to create direct ByteBuffer or on heap ByteBuffer.public ByteBuffer getBuffer()
putbackBuffer(ByteBuffer)public void putbackBuffer(ByteBuffer buf)
buf - ByteBuffer to return.public int getBufferSize()
public int getQueueSize()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.