Class AbstractObjectPool<T>
- java.lang.Object
-
- co.elastic.apm.agent.objectpool.impl.AbstractObjectPool<T>
-
- All Implemented Interfaces:
ObjectPool<T>
- Direct Known Subclasses:
ListBasedObjectPool,QueueBasedObjectPool
public abstract class AbstractObjectPool<T> extends java.lang.Object implements ObjectPool<T>
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractObjectPool(Allocator<T> allocator, Resetter<T> resetter)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description TcreateInstance()Tries to reuse any existing instance if pool has any, otherwise creates a new un-pooled instancelonggetGarbageCreated()voidrecycle(T obj)Recycles an objectprotected abstract booleanreturnToPool(T obj)Pushes object reference back into the available pooled instancesprotected abstract TtryCreateInstance()Tries to create an instance in pool-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface co.elastic.apm.agent.objectpool.ObjectPool
clear, getObjectsInPool
-
-
-
-
Method Detail
-
createInstance
public final T createInstance()
Description copied from interface:ObjectPoolTries to reuse any existing instance if pool has any, otherwise creates a new un-pooled instance- Specified by:
createInstancein interfaceObjectPool<T>- Returns:
- object instance, either from pool or freshly allocated
-
recycle
public final void recycle(T obj)
Description copied from interface:ObjectPoolRecycles an object- Specified by:
recyclein interfaceObjectPool<T>- Parameters:
obj- object to recycle
-
getGarbageCreated
public final long getGarbageCreated()
- Specified by:
getGarbageCreatedin interfaceObjectPool<T>- Returns:
- number of times that objects could not be returned to the pool because the pool was already full
-
returnToPool
protected abstract boolean returnToPool(T obj)
Pushes object reference back into the available pooled instances- Parameters:
obj- recycled object to return to pool- Returns:
- true if object has been returned to pool, false if pool is already full
-
tryCreateInstance
@Nullable protected abstract T tryCreateInstance()
Tries to create an instance in pool- Returns:
nullif pool capacity is exhausted
-
-