Class BufferPool


  • public class BufferPool
    extends java.lang.Object
    Pool for reusing byte buffers in Tribes messaging.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static 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 java.util.concurrent.ConcurrentLinkedQueue<XByteBuffer> queue
      Queue of available buffers.
      protected java.util.concurrent.atomic.AtomicInteger size
      Current total size of pooled buffers in bytes.
      protected static StringManager sm
      String manager for internationalized messages.
    • 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 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