Class MappedByteBufferPool

  • All Implemented Interfaces:
    ByteBufferPool, Dumpable
    Direct Known Subclasses:
    MappedByteBufferPool.Tagged

    @ManagedObject
    public class MappedByteBufferPool
    extends AbstractByteBufferPool
    implements Dumpable

    A ByteBuffer pool where ByteBuffers are held in queues that are held in a Map.

    Given a capacity factor of 1024, the Map entry with key 1 holds a queue of ByteBuffers each of capacity 1024, the Map entry with key 2 holds a queue of ByteBuffers each of capacity 2048, and so on.

    • Field Detail

      • LOG

        private static final Logger LOG
      • _directBuffers

        private final java.util.concurrent.ConcurrentMap<java.lang.Integer,​ByteBufferPool.Bucket> _directBuffers
      • _heapBuffers

        private final java.util.concurrent.ConcurrentMap<java.lang.Integer,​ByteBufferPool.Bucket> _heapBuffers
      • _newBucket

        private final java.util.function.Function<java.lang.Integer,​ByteBufferPool.Bucket> _newBucket
      • _detailedDump

        private boolean _detailedDump
    • Constructor Detail

      • MappedByteBufferPool

        public MappedByteBufferPool()
        Creates a new MappedByteBufferPool with a default configuration.
      • MappedByteBufferPool

        public MappedByteBufferPool​(int factor)
        Creates a new MappedByteBufferPool with the given capacity factor.
        Parameters:
        factor - the capacity factor
      • MappedByteBufferPool

        public MappedByteBufferPool​(int factor,
                                    int maxQueueLength)
        Creates a new MappedByteBufferPool with the given configuration.
        Parameters:
        factor - the capacity factor
        maxQueueLength - the maximum ByteBuffer queue length
      • MappedByteBufferPool

        public MappedByteBufferPool​(int factor,
                                    int maxQueueLength,
                                    java.util.function.Function<java.lang.Integer,​ByteBufferPool.Bucket> newBucket)
        Creates a new MappedByteBufferPool with the given configuration.
        Parameters:
        factor - the capacity factor
        maxQueueLength - the maximum ByteBuffer queue length
        newBucket - the function that creates a Bucket
      • MappedByteBufferPool

        public MappedByteBufferPool​(int factor,
                                    int maxQueueLength,
                                    java.util.function.Function<java.lang.Integer,​ByteBufferPool.Bucket> newBucket,
                                    long maxHeapMemory,
                                    long maxDirectMemory)
        Creates a new MappedByteBufferPool with the given configuration.
        Parameters:
        factor - the capacity factor
        maxQueueLength - the maximum ByteBuffer queue length
        newBucket - the function that creates a Bucket
        maxHeapMemory - the max heap memory in bytes, -1 for unlimited memory or 0 to use default heuristic.
        maxDirectMemory - the max direct memory in bytes, -1 for unlimited memory or 0 to use default heuristic.
    • Method Detail

      • acquire

        public java.nio.ByteBuffer acquire​(int size,
                                           boolean direct)
        Description copied from interface: ByteBufferPool

        Requests a ByteBuffer of the given size.

        The returned buffer may have a bigger capacity than the size being requested but it will have the limit set to the given size.

        Specified by:
        acquire in interface ByteBufferPool
        Parameters:
        size - the size of the buffer
        direct - whether the buffer must be direct or not
        Returns:
        the requested buffer
        See Also:
        ByteBufferPool.release(ByteBuffer)
      • releaseMemory

        protected void releaseMemory​(boolean direct)
      • bucketFor

        protected int bucketFor​(int capacity)
      • capacityFor

        protected int capacityFor​(int bucket)
      • getDirectByteBufferCount

        @ManagedAttribute("The number of pooled direct ByteBuffers")
        public long getDirectByteBufferCount()
      • getHeapByteBufferCount

        @ManagedAttribute("The number of pooled heap ByteBuffers")
        public long getHeapByteBufferCount()
      • getByteBufferCount

        private long getByteBufferCount​(boolean direct)
      • bucketsFor

        java.util.concurrent.ConcurrentMap<java.lang.Integer,​ByteBufferPool.Bucket> bucketsFor​(boolean direct)
      • isDetailedDump

        public boolean isDetailedDump()
      • setDetailedDump

        public void setDetailedDump​(boolean detailedDump)
      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
                  throws java.io.IOException
        Description copied from interface: Dumpable
        Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
        Specified by:
        dump in interface Dumpable
        Parameters:
        out - The appendable to dump to
        indent - The indent to apply after any new lines.
        Throws:
        java.io.IOException - if unable to write to Appendable
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object