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 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