ArrayBlockingQueuePool

io.github.andrebeat.pool.ArrayBlockingQueuePool
abstract class ArrayBlockingQueuePool[A <: AnyRef](val _capacity: Int, val referenceType: ReferenceType) extends Pool[A]

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
trait Pool[A]
class Object
trait Matchable
class Any
Known subtypes
class ExpiringPool[A]
class SimplePool[A]
Self type

Members list

Type members

Classlikes

abstract protected class Item(val r: Ref[A])

Attributes

Supertypes
class Object
trait Matchable
class Any

Value members

Concrete methods

def capacity(): Int

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.

def live(): Int

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.

def size(): Int

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

def acquire(): Lease[A]

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
def close(): Unit

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
def drain(): Unit

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
def fill(): Unit

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
def leased(): Int

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
def tryAcquire(atMost: Duration): Option[Lease[A]]

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
def tryAcquire(): Option[Lease[A]]

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

val _capacity: Int

Returns the io.github.andrebeat.pool.ReferenceType of the objects stored in the pool.

Returns the io.github.andrebeat.pool.ReferenceType of the objects stored in the pool.

Attributes