Package org.apache.catalina.tribes.io
Class BufferPool
- java.lang.Object
-
- org.apache.catalina.tribes.io.BufferPool
-
public class BufferPool extends java.lang.ObjectPool for reusing byte buffers in Tribes messaging.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_POOL_SIZEDefault maximum pool size in bytes (100 MiB).protected static BufferPoolinstanceSingleton instance of the buffer pool.protected intmaxSizeMaximum pool size in bytes.protected java.util.concurrent.ConcurrentLinkedQueue<XByteBuffer>queueQueue of available buffers.protected java.util.concurrent.atomic.AtomicIntegersizeCurrent total size of pooled buffers in bytes.protected static StringManagersmString manager for internationalized messages.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears all buffers from the pool.XByteBuffergetBuffer(int minSize, boolean discard)Retrieves a buffer from the pool.static BufferPoolgetBufferPool()Returns the singleton buffer pool instance.intgetMaxSize()Returns the maximum pool size.voidreturnBuffer(XByteBuffer buffer)Returns a buffer to the pool for reuse.voidsetMaxSize(int bytes)Sets the maximum pool size.
-
-
-
Field Detail
-
DEFAULT_POOL_SIZE
public static final int DEFAULT_POOL_SIZE
Default maximum pool size in bytes (100 MiB).
-
sm
protected static final StringManager sm
String manager for internationalized messages.
-
instance
protected static volatile BufferPool instance
Singleton instance of the buffer pool.
-
maxSize
protected int maxSize
Maximum pool size in bytes.
-
size
protected final java.util.concurrent.atomic.AtomicInteger size
Current total size of pooled buffers in bytes.
-
queue
protected final java.util.concurrent.ConcurrentLinkedQueue<XByteBuffer> queue
Queue of available buffers.
-
-
Method Detail
-
getBufferPool
public static BufferPool getBufferPool()
Returns the singleton buffer pool instance.- Returns:
- the buffer pool
-
getBuffer
public XByteBuffer getBuffer(int minSize, boolean discard)
Retrieves a buffer from the pool.- Parameters:
minSize- minimum buffer sizediscard- discard flag- Returns:
- the buffer
-
returnBuffer
public void returnBuffer(XByteBuffer buffer)
Returns a buffer to the pool for reuse.- Parameters:
buffer- the buffer to return
-
clear
public void clear()
Clears all buffers from the pool.
-
setMaxSize
public void setMaxSize(int bytes)
Sets the maximum pool size.- Parameters:
bytes- maximum size in bytes
-
getMaxSize
public int getMaxSize()
Returns the maximum pool size.- Returns:
- maximum size in bytes
-
-