Class QueueBasedObjectPool<T>
- java.lang.Object
-
- co.elastic.apm.agent.objectpool.impl.AbstractObjectPool<T>
-
- co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool<T>
-
- All Implemented Interfaces:
ObjectPool<T>
public class QueueBasedObjectPool<T> extends AbstractObjectPool<T>
-
-
Field Summary
-
Fields inherited from class co.elastic.apm.agent.objectpool.impl.AbstractObjectPool
allocator, resetter
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()intgetObjectsInPool()static <T> QueueBasedObjectPool<T>of(java.util.Queue<T> queue, boolean preAllocate, Allocator<T> allocator, Resetter<T> resetter)Creates a queue based pooled for types that do not implementRecyclable, useofRecyclable(Queue, boolean, Allocator)for types that implementRecyclable.static <T extends Recyclable>
QueueBasedObjectPool<T>ofRecyclable(java.util.Queue<T> queue, boolean preAllocate, Allocator<T> allocator)Creates a queue based pooled for types that implementRecyclable, useof(Queue, boolean, Allocator, Resetter)for other pooled object types.protected booleanreturnToPool(T obj)Pushes object reference back into the available pooled instancesTtryCreateInstance()Tries to create an instance in pool-
Methods inherited from class co.elastic.apm.agent.objectpool.impl.AbstractObjectPool
createInstance, getGarbageCreated, recycle
-
-
-
-
Method Detail
-
ofRecyclable
public static <T extends Recyclable> QueueBasedObjectPool<T> ofRecyclable(java.util.Queue<T> queue, boolean preAllocate, Allocator<T> allocator)
Creates a queue based pooled for types that implementRecyclable, useof(Queue, boolean, Allocator, Resetter)for other pooled object types.- Parameters:
queue- the underlying queuepreAllocate- when set to true, queue will be be pre-allocated with object instance.allocator- a factory used to create new instances of the recyclable object. This factory is used when there are no objects in the queue and to preallocate the queue
-
of
public static <T> QueueBasedObjectPool<T> of(java.util.Queue<T> queue, boolean preAllocate, Allocator<T> allocator, Resetter<T> resetter)
Creates a queue based pooled for types that do not implementRecyclable, useofRecyclable(Queue, boolean, Allocator)for types that implementRecyclable.- Parameters:
queue- the underlying queuepreAllocate- when set to true, queue will be be pre-allocated with object instances fitting queue sizeallocator- a factory used to create new instances of the recyclable object. This factory is used when there are no objects in the queue and to preallocate the queueresetter- a reset strategy class
-
tryCreateInstance
@Nullable public T tryCreateInstance()
Description copied from class:AbstractObjectPoolTries to create an instance in pool- Specified by:
tryCreateInstancein classAbstractObjectPool<T>- Returns:
nullif pool capacity is exhausted
-
returnToPool
protected boolean returnToPool(T obj)
Description copied from class:AbstractObjectPoolPushes object reference back into the available pooled instances- Specified by:
returnToPoolin classAbstractObjectPool<T>- Parameters:
obj- recycled object to return to pool- Returns:
- true if object has been returned to pool, false if pool is already full
-
getObjectsInPool
public int getObjectsInPool()
- Returns:
- number of available objects in pool
-
clear
public void clear()
-
-