# Class BufferPool

java.lang.Object
org.apache.catalina.tribes.io.BufferPool

public class BufferPool extends Object
Pool for reusing byte buffers in Tribes messaging.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `DEFAULT_POOL_SIZE`
  Default maximum pool size in bytes (100 MiB).
  `protected static BufferPool`
  `instance`
  Singleton instance of the buffer pool.
  `protected int`
  `maxSize`
  Maximum pool size in bytes.
  `protected final ConcurrentLinkedQueue<XByteBuffer>`
  `queue`
  Queue of available buffers.
  `protected final AtomicInteger`
  `size`
  Current total size of pooled buffers in bytes.
  `protected static final StringManager`
  `sm`
  String manager for internationalized messages.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  Clears all buffers from the pool.
  `XByteBuffer`
  `getBuffer(int minSize, boolean discard)`
  Retrieves a buffer from the pool.
  `static BufferPool`
  `getBufferPool()`
  Returns the singleton buffer pool instance.
  `int`
  `getMaxSize()`
  Returns the maximum pool size.
  `void`
  `returnBuffer(XByteBuffer buffer)`
  Returns a buffer to the pool for reuse.
  `void`
  `setMaxSize(int bytes)`
  Sets the maximum pool size.

  ### Methods inherited from class Object

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

- ## Field Details

  - ### 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 AtomicInteger size
    Current total size of pooled buffers in bytes.

  - ### queue

    protected final ConcurrentLinkedQueue<XByteBuffer> queue
    Queue of available buffers.

- ## Method Details

  - ### 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 size
      `discard` - 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