A RetainableByteBuffer pool where RetainableByteBuffers are held in Pools that are
held in array elements.
Given a capacity factor of 1024, the first array element holds a Pool of RetainableByteBuffers
each of capacity 1024, the second array element holds a Pool of RetainableByteBuffers each of capacity
2048, and so on with capacities 3072, 4096, 5120, etc.
The maxHeapMemory and maxDirectMemory default heuristic is to use Runtime#maxMemory()
divided by 8.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| public static class | ArrayByteBufferPool.
A variant of the |
| private static class | |
| public static class | ArrayByteBufferPool.
A variant of |
| Modifier and Type | Field and Description |
|---|---|
| private final IntUnaryOperator | |
| private final AtomicLong | |
| private final AtomicLong | |
| private final ArrayByteBufferPool. | |
| private final ArrayByteBufferPool. | |
| private final int | |
| private final long | |
| private final long | |
| private final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| private static final Logger |
| Access | Constructor and Description |
|---|---|
| public | |
| public | ArrayByteBufferPool(int
the minimum ByteBuffer capacity minCapacity, int the capacity factor factor, int the maximum ByteBuffer capacity maxCapacity)Creates a new ArrayByteBufferPool with the given configuration. |
| public | ArrayByteBufferPool(int
the minimum ByteBuffer capacity minCapacity, int the capacity factor factor, int the maximum ByteBuffer capacity maxCapacity, int the maximum number of ByteBuffers for each bucket maxBucketSize)Creates a new ArrayByteBufferPool with the given configuration. |
| public | ArrayByteBufferPool(int
the minimum ByteBuffer capacity minCapacity, int the capacity factor factor, int the maximum ByteBuffer capacity maxCapacity, int the maximum number of ByteBuffers for each bucket maxBucketSize, long the max heap memory in bytes, -1 for unlimited memory or 0 to use default heuristic maxHeapMemory, long the max direct memory in bytes, -1 for unlimited memory or 0 to use default heuristic maxDirectMemory)Creates a new ArrayByteBufferPool with the given configuration. |
| protected | ArrayByteBufferPool(int
the minimum ByteBuffer capacity minCapacity, int the capacity factor factor, int the maximum ByteBuffer capacity maxCapacity, int the maximum number of ByteBuffers for each bucket maxBucketSize, long the max heap memory in bytes, -1 for unlimited memory or 0 to use default heuristic maxHeapMemory, long the max direct memory in bytes, -1 for unlimited memory or 0 to use default heuristic maxDirectMemory, IntUnaryOperator a bucketIndexFor, IntUnaryOperator IntUnaryOperator that takes a capacity and returns a bucket indexa bucketCapacity)IntUnaryOperator that takes a bucket index and returns a capacityCreates a new ArrayByteBufferPool with the given configuration. |
| Modifier and Type | Method and Description |
|---|---|
| public RetainableByteBuffer | acquire(int
The size of the buffer. The returned buffer will have at least this capacity. size, boolean true if a direct memory buffer is needed, false otherwise. direct)Implements org. Acquires a |
| protected ByteBuffer | |
| protected ByteBuffer | |
| private ArrayByteBufferPool. | |
| public void | clear()
Implements org. Removes all |
| private void | |
| public void | dump(Appendable
The appendable to dump to out, String The indent to apply after any new lines. indent)Implements org. Dump this object (and children) into an Appendable using the provided indent after any new lines. |
| private void | evict(boolean
true to search in the direct buffers buckets, false to search in the heap buffers buckets. direct, long the amount of bytes to evict. At least this much will be removed from the buckets. excess)This eviction mechanism searches for the RetainableByteBuffers that were released the longest time ago. |
| private Pool. | |
| private long | |
| public long | |
| public long | |
| public long | |
| public long | |
| private long | |
| private long | |
| public long | |
| public long | |
| public long | |
| public long | |
| public int | |
| private long | |
| public int | |
| private long | |
| private RetainableByteBuffer | |
| public Pool | |
| private void | |
| protected void | |
| public String |
| _bucketIndexFor | back to summary |
|---|---|
| private final IntUnaryOperator _bucketIndexFor | |
| _currentDirectMemory | back to summary |
|---|---|
| private final AtomicLong _currentDirectMemory | |
| _currentHeapMemory | back to summary |
|---|---|
| private final AtomicLong _currentHeapMemory | |
| _direct | back to summary |
|---|---|
| private final ArrayByteBufferPool. | |
| _indirect | back to summary |
|---|---|
| private final ArrayByteBufferPool. | |
| _maxCapacity | back to summary |
|---|---|
| private final int _maxCapacity | |
| _maxDirectMemory | back to summary |
|---|---|
| private final long _maxDirectMemory | |
| _maxHeapMemory | back to summary |
|---|---|
| private final long _maxHeapMemory | |
| _minCapacity | back to summary |
|---|---|
| private final int _minCapacity | |
| DEFAULT_FACTOR | back to summary |
|---|---|
| pack-priv static final int DEFAULT_FACTOR | |
| DEFAULT_MAX_CAPACITY_BY_FACTOR | back to summary |
|---|---|
| pack-priv static final int DEFAULT_MAX_CAPACITY_BY_FACTOR | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| ArrayByteBufferPool | back to summary |
|---|---|
| public ArrayByteBufferPool() Creates a new ArrayByteBufferPool with a default configuration.
Both | |
| ArrayByteBufferPool | back to summary |
|---|---|
| public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity) Creates a new ArrayByteBufferPool with the given configuration.
Both
| |
| ArrayByteBufferPool | back to summary |
|---|---|
| public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize) Creates a new ArrayByteBufferPool with the given configuration.
Both
| |
| ArrayByteBufferPool | back to summary |
|---|---|
| public ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory) Creates a new ArrayByteBufferPool with the given configuration.
| |
| ArrayByteBufferPool | back to summary |
|---|---|
| protected ArrayByteBufferPool(int minCapacity, int factor, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory, IntUnaryOperator bucketIndexFor, IntUnaryOperator bucketCapacity) Creates a new ArrayByteBufferPool with the given configuration.
| |
| acquire | back to summary |
|---|---|
| public RetainableByteBuffer acquire(int size, boolean direct) Implements org. Doc from org. Acquires a
| |
| allocate | back to summary |
|---|---|
| protected ByteBuffer allocate(int capacity) | |
| allocateDirect | back to summary |
|---|---|
| protected ByteBuffer allocateDirect(int capacity) | |
| bucketFor | back to summary |
|---|---|
| private ArrayByteBufferPool. | |
| clear | back to summary |
|---|---|
| public void clear() Implements org. Doc from org. Removes all
| |
| clearArray | back to summary |
|---|---|
| private void clearArray(ArrayByteBufferPool. | |
| dump | back to summary |
|---|---|
| public void dump(Appendable out, String indent) throws IOException Implements org. Doc from org. 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.
| |
| evict | back to summary |
|---|---|
| private void evict(boolean direct, long excess) This eviction mechanism searches for the RetainableByteBuffers that were released the longest time ago.
| |
| findOldestEntry | back to summary |
|---|---|
| private Pool. | |
| getAvailableByteBufferCount | back to summary |
|---|---|
| private long getAvailableByteBufferCount(boolean direct) | |
| getAvailableDirectByteBufferCount | back to summary |
|---|---|
public long getAvailableDirectByteBufferCount()
| |
| getAvailableDirectMemory | back to summary |
|---|---|
public long getAvailableDirectMemory()
| |
| getAvailableHeapByteBufferCount | back to summary |
|---|---|
public long getAvailableHeapByteBufferCount()
| |
| getAvailableHeapMemory | back to summary |
|---|---|
public long getAvailableHeapMemory()
| |
| getAvailableMemory | back to summary |
|---|---|
| private long getAvailableMemory(boolean direct) | |
| getByteBufferCount | back to summary |
|---|---|
| private long getByteBufferCount(boolean direct) | |
| getDirectByteBufferCount | back to summary |
|---|---|
public long getDirectByteBufferCount()
| |
| getDirectMemory | back to summary |
|---|---|
public long getDirectMemory()
| |
| getHeapByteBufferCount | back to summary |
|---|---|
public long getHeapByteBufferCount()
| |
| getHeapMemory | back to summary |
|---|---|
public long getHeapMemory()
| |
| getMaxCapacity | back to summary |
|---|---|
public int getMaxCapacity()
| |
| getMemory | back to summary |
|---|---|
| private long getMemory(boolean direct) | |
| getMinCapacity | back to summary |
|---|---|
public int getMinCapacity()
| |
| maxMemory | back to summary |
|---|---|
| private long maxMemory(long maxMemory) | |
| newRetainableByteBuffer | back to summary |
|---|---|
| private RetainableByteBuffer newRetainableByteBuffer(int capacity, boolean direct, Consumer<RetainableByteBuffer> releaser) | |
| poolFor | back to summary |
|---|---|
| public Pool | |
| releaseExcessMemory | back to summary |
|---|---|
| private void releaseExcessMemory(boolean direct) | |
| removed | back to summary |
|---|---|
| protected void removed(RetainableByteBuffer retainedBuffer) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| private final AtomicLong | |
| private final Consumer |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public long | |
| public boolean | release()
Overrides org. Overrides default org. Releases this resource, potentially decrementing a reference count (if any). |
| lastNanoTime | back to summary |
|---|---|
| private final AtomicLong lastNanoTime | |
| releaser | back to summary |
|---|---|
| private final Consumer<RetainableByteBuffer> releaser | |
| Buffer | back to summary |
|---|---|
| private Buffer(ByteBuffer buffer, Consumer<RetainableByteBuffer> releaser) | |
| getLastNanoTime | back to summary |
|---|---|
| public long getLastNanoTime() | |
| release | back to summary |
|---|---|
| public boolean release() Overrides org. Overrides default org. Doc from org. Releases this resource, potentially decrementing a reference count (if any).
| |
ArrayByteBufferPool that
uses buckets of buffers that increase in size by a power of
2 (eg 1k, 2k, 4k, 8k, etc.).
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | Quadratic(int minCapacity, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory)
|
| Quadratic | back to summary |
|---|---|
| public Quadratic() | |
| Quadratic | back to summary |
|---|---|
| public Quadratic(int minCapacity, int maxCapacity, int maxBucketSize) | |
| Quadratic | back to summary |
|---|---|
| public Quadratic(int minCapacity, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory) | |
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| private final Pool |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private Pool | |
| public String |
| _capacity | back to summary |
|---|---|
| private final int _capacity | |
| _pool | back to summary |
|---|---|
| private final Pool<RetainableByteBuffer> _pool | |
| RetainedBucket | back to summary |
|---|---|
| private RetainedBucket(int capacity, int poolSize) | |
| getPool | back to summary |
|---|---|
| private Pool | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
A variant of ArrayByteBufferPool that tracks buffer
acquires/releases, useful to identify buffer leaks.
Use getLeaks() when the system is idle to get
the Buffers that have been leaked, which contain
the stack trace information of where the buffer was acquired.
| Modifier and Type | Class and Description |
|---|---|
| public class |
| Modifier and Type | Field and Description |
|---|---|
| private final Set | |
| private static final Logger |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | Tracking(int minCapacity, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory)
|
| Modifier and Type | Method and Description |
|---|---|
| public RetainableByteBuffer | acquire(int
The size of the buffer. The returned buffer will have at least this capacity. size, boolean true if a direct memory buffer is needed, false otherwise. direct)Overrides org. Implements org. Acquires a |
| public String | |
| public Set |
| buffers | back to summary |
|---|---|
| private final Set<ArrayByteBufferPool. | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| Tracking | back to summary |
|---|---|
| public Tracking() | |
| Tracking | back to summary |
|---|---|
| public Tracking(int minCapacity, int maxCapacity, int maxBucketSize) | |
| Tracking | back to summary |
|---|---|
| public Tracking(int minCapacity, int maxCapacity, int maxBucketSize, long maxHeapMemory, long maxDirectMemory) | |
| acquire | back to summary |
|---|---|
| public RetainableByteBuffer acquire(int size, boolean direct) Overrides org. Implements org. Doc from org. Acquires a
| |
| dumpLeaks | back to summary |
|---|---|
| public String dumpLeaks() | |
| getLeaks | back to summary |
|---|---|
| public Set | |
| Modifier and Type | Field and Description |
|---|---|
| private final Instant | |
| private final Throwable | |
| private final List | |
| private final List | |
| private final List | |
| private final int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| public Instant | |
| public Throwable | |
| public int | |
| public boolean | release()
Overrides org. Overrides default org. Releases this resource, potentially decrementing a reference count (if any). |
| public void | retain()
Overrides org. Overrides default org. Retains this resource, potentially incrementing a reference count if there are resources that will be released. |
| acquireInstant | back to summary |
|---|---|
| private final Instant acquireInstant | |
| acquireStack | back to summary |
|---|---|
| private final Throwable acquireStack | |
| overReleaseStacks | back to summary |
|---|---|
| private final List<Throwable> overReleaseStacks | |
| releaseStacks | back to summary |
|---|---|
| private final List<Throwable> releaseStacks | |
| retainStacks | back to summary |
|---|---|
| private final List<Throwable> retainStacks | |
| size | back to summary |
|---|---|
| private final int size | |
| Buffer | back to summary |
|---|---|
| private Buffer(RetainableByteBuffer wrapped, int size) | |
| dump | back to summary |
|---|---|
| public String dump() | |
| getAcquireInstant | back to summary |
|---|---|
| public Instant getAcquireInstant() | |
| getAcquireStack | back to summary |
|---|---|
| public Throwable getAcquireStack() | |
| getSize | back to summary |
|---|---|
| public int getSize() | |
| release | back to summary |
|---|---|
| public boolean release() Overrides org. Overrides default org. Doc from org. Releases this resource, potentially decrementing a reference count (if any).
| |
| retain | back to summary |
|---|---|
| public void retain() Overrides org. Overrides default org. Doc from org. Retains this resource, potentially incrementing a reference count if there are resources that will be released.
| |