ArrayBlockingQueuePool
A generic object pooling implementation based on java.util.concurrent.ArrayBlockingQueue. This implementation relies on the thread-safety and blocking/non-blocking mechanisms of the underlying data structure to implement the pool interface. Furthermore, for synchronization and tracking of live instances an java.util.concurrent.atomic.AtomicInteger is used. No locks are used in this implementation.
The type of items inserted in the queue must implement the Item
interface. This class defines methods for consuming the item (e.g. disposing of any resources associated with it) and a method that's called whenever an item is successfully inserted into the queue (useful for triggering a side-effect). This class is also responsible for dealing with the reference type that's wrapping the value (i.e. ensure calling its destructor if the value is defined).
Attributes
- Graph
-
- Supertypes
- Known subtypes
-
class ExpiringPool[A]class SimplePool[A]
- Self type
Members list
Type members
Classlikes
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
Value members
Concrete methods
Returns the capacity of the pool, i.e. the maximum number of objects the pool can hold.
Returns the capacity of the pool, i.e. the maximum number of objects the pool can hold.
Attributes
- Returns
-
the capacity of the pool.
Returns the number of live objects, i.e. the number of currently pooled objects plus leased objects.
Returns the number of live objects, i.e. the number of currently pooled objects plus leased objects.
The value returned by this method is only accurate when the referenceType
is io.github.andrebeat.pool.ReferenceType.Strong, since GC-based eviction is checked only when trying to acquire an object.
Attributes
- Returns
-
the number of live objects.
Returns the number of objects in the pool.
Returns the number of objects in the pool.
The value returned by this method is only accurate when the referenceType
is io.github.andrebeat.pool.ReferenceType.Strong, since GC-based eviction is checked only when trying to acquire an object.
Attributes
- Returns
-
the number of objects in the pool.
Inherited methods
Acquire a lease for an object blocking if none is available.
Acquire a lease for an object blocking if none is available.
Attributes
- Returns
-
a lease for an object from this pool.
- Throws
-
ClosedPoolException
If this pool is closed.
- Inherited from:
- Pool
Closes this pool, and properly disposes of each pooled object, releasing any resources associated with the pool (e.g. background timer threads).
Closes this pool, and properly disposes of each pooled object, releasing any resources associated with the pool (e.g. background timer threads).
If the pool has already been closed this method does nothing.
Attributes
- Inherited from:
- Pool
Drains the object pool, i.e. evicts every object currently pooled.
Drains the object pool, i.e. evicts every object currently pooled.
Attributes
- Throws
-
ClosedPoolException
If this pool is closed.
- Inherited from:
- Pool
Fills the object pool by creating (and pooling) new objects until the number of live objects reaches the pool capacity.
Fills the object pool by creating (and pooling) new objects until the number of live objects reaches the pool capacity.
Attributes
- Throws
-
ClosedPoolException
If this pool is closed.
- Inherited from:
- Pool
Returns the number of leased objects.
Returns the number of leased objects.
The value returned by this method is only accurate when the referenceType
is io.github.andrebeat.pool.ReferenceType.Strong, since GC-based eviction is checked only when trying to acquire an object.
Attributes
- Returns
-
the number of leased objects.
- Inherited from:
- Pool
Try to acquire a lease for an object blocking at most until the given duration.
Try to acquire a lease for an object blocking at most until the given duration.
Value parameters
- atMost
-
maximum wait time for the lease to be available.
Attributes
- Returns
-
a lease for an object from this pool if available until the given duration,
None
otherwise. - Throws
-
ClosedPoolException
If this pool is closed.
- Inherited from:
- Pool
Try to acquire a lease for an object without blocking.
Try to acquire a lease for an object without blocking.
Attributes
- Returns
-
a lease for an object from this pool if available,
None
otherwise. - Throws
-
ClosedPoolException
If this pool is closed.
- Inherited from:
- Pool
Concrete fields
Returns the io.github.andrebeat.pool.ReferenceType of the objects stored in the pool.