abstract class ArrayBlockingQueuePool[A <: AnyRef] 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).
- Self Type
- ArrayBlockingQueuePool[A]
- Alphabetic
- By Inheritance
- ArrayBlockingQueuePool
- Pool
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new ArrayBlockingQueuePool(_capacity: Int, referenceType: ReferenceType)
Abstract Value Members
- abstract def dispose(a: A): Unit
Object "destructor".
Object "destructor". This method is called whenever the object is evicted from the pool. For example, when doing connection pooling it is necessary to close the connection whenever it is evicted (i.e. permanently removed) from the pool.
- Attributes
- protected
- Definition Classes
- Pool
- abstract def factory(): A
Factory method for creating new objects.
Factory method for creating new objects.
- returns
a new object.
- Attributes
- protected
- Definition Classes
- Pool
- abstract def handleClose(): Unit
- Attributes
- protected
- Definition Classes
- Pool
- abstract def healthCheck(a: A): Boolean
An health check that is performed on an object before its leased from the pool.
An health check that is performed on an object before its leased from the pool. If the health check passes the object is successfully leased. Otherwise, the object is destroyed (and a new one is fetched or created)
- Attributes
- protected
- Definition Classes
- Pool
- abstract def newItem(a: A): Item
- Attributes
- protected[this]
- abstract def reset(a: A): Unit
Resets the internal state of object.
Resets the internal state of object. This method is called on an object whenever it is added/released back to the pool. For example, if pooling an object like a java.nio.ByteBuffer it might make sense to call its
reset()
method whenever the object is released to the pool, so that its future users do not observe the internal state introduced by previous ones.- Attributes
- protected
- Definition Classes
- Pool
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- val _capacity: Int
- 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.
- returns
a lease for an object from this pool.
- Definition Classes
- Pool
- Exceptions thrown
ClosedPoolException
If this pool is closed.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def capacity(): Int
Returns the capacity of the pool, i.e.
Returns the capacity of the pool, i.e. the maximum number of objects the pool can hold.
- returns
the capacity of the pool.
- Definition Classes
- ArrayBlockingQueuePool → Pool
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
- def close(): Unit
Closes this pool, and properly disposes of each pooled object, releasing any resources associated with the pool (e.g.
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.
- Definition Classes
- Pool
- val closed: AtomicBoolean
- Attributes
- protected[this]
- Definition Classes
- Pool
- def destroy(a: A): Unit
- Attributes
- protected[this]
- Annotations
- @inline()
- def drain(): Unit
Drains the object pool, i.e.
Drains the object pool, i.e. evicts every object currently pooled.
- Definition Classes
- Pool
- Exceptions thrown
ClosedPoolException
If this pool is closed.
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- 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.
- Definition Classes
- Pool
- Exceptions thrown
ClosedPoolException
If this pool is closed.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- def handleAcquire(): Lease[A]
- Attributes
- protected[this]
- Definition Classes
- ArrayBlockingQueuePool → Pool
- final def handleDrain(): Unit
- Attributes
- protected[this]
- Definition Classes
- ArrayBlockingQueuePool → Pool
- Annotations
- @tailrec()
- final def handleFill(): Unit
- Attributes
- protected[this]
- Definition Classes
- ArrayBlockingQueuePool → Pool
- Annotations
- @tailrec()
- def handleTryAcquire(atMost: Duration): Option[Lease[A]]
- Attributes
- protected[this]
- Definition Classes
- ArrayBlockingQueuePool → Pool
- def handleTryAcquire(): Option[Lease[A]]
- Attributes
- protected[this]
- Definition Classes
- ArrayBlockingQueuePool → Pool
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- val items: ArrayBlockingQueue[Item]
- Attributes
- protected[this]
- 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.- returns
the number of leased objects.
- Definition Classes
- Pool
- def live(): Int
Returns the number of live objects, i.e.
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.- returns
the number of live objects.
- Definition Classes
- ArrayBlockingQueuePool → Pool
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- val referenceType: ReferenceType
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.
- Definition Classes
- ArrayBlockingQueuePool → Pool
- 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.- returns
the number of objects in the pool.
- Definition Classes
- ArrayBlockingQueuePool → Pool
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- 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.
- atMost
maximum wait time for the lease to be available.
- returns
a lease for an object from this pool if available until the given duration,
None
otherwise.
- Definition Classes
- Pool
- Exceptions thrown
ClosedPoolException
If this pool is closed.
- 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.
- returns
a lease for an object from this pool if available,
None
otherwise.
- Definition Classes
- Pool
- Exceptions thrown
ClosedPoolException
If this pool is closed.
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)