io.github.andrebeat.pool

This library provides classes for dealing with object pooling that allow:

  • blocking/non-blocking object acquisition
  • object invalidation
  • capping the number of pooled objects
  • creating new objects lazily, as needed
  • health checking
  • time-based pool eviction (idle instances)
  • GC-based pool eviction (soft and weak references)
  • efficient thread-safety

==Overview== In order create a new io.github.andrebeat.pool.Pool the constructor method should be used like so

scala> val pool = Pool(4, () => new Object)
pool: io.github.andrebeat.pool.SimplePool[Object] = _
scala> val lease = pool.acquire()
lease: io.github.andrebeat.pool.Lease[Object] = _
scala> lease.release()

Additionally, in order to avoid manually releasing the lease after its used, you can use the use method on the lease:

scala> val pool = Pool(4, () => new Object)
pool: io.github.andrebeat.pool.SimplePool[Object] = _
scala> val lease = pool.acquire()
lease: io.github.andrebeat.pool.Lease[Object] = _
scala> lease(println) // the lease is released automatically after its used
java.lang.Object@7970d6d

Attributes

Members list

Type members

Classlikes

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.

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

Supertypes
trait Pool[A]
class Object
trait Matchable
class Any
Known subtypes
class ExpiringPool[A]
class SimplePool[A]
Self type
class ExpiringPool[A <: AnyRef](capacity: Int, referenceType: ReferenceType, val maxIdleTime: Duration, _factory: () => A, _reset: A => Unit, _dispose: A => Unit, _healthCheck: A => Boolean) extends ArrayBlockingQueuePool[A]

An object pool that creates the objects as needed until a maximum number of objects has been created and automatically evicts objects after they have been idle for a given amount of time.

An object pool that creates the objects as needed until a maximum number of objects has been created and automatically evicts objects after they have been idle for a given amount of time.

Attributes

Companion
object
Supertypes
trait Pool[A]
class Object
trait Matchable
class Any
object ExpiringPool

Object containing factory methods for io.github.andrebeat.pool.ExpiringPool.

Object containing factory methods for io.github.andrebeat.pool.ExpiringPool.

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
trait Lease[A <: AnyRef]

A lease on an object requested from a io.github.andrebeat.pool.Pool allowing the object to be accessed and then released back to the pool when no longer needed.

A lease on an object requested from a io.github.andrebeat.pool.Pool allowing the object to be accessed and then released back to the pool when no longer needed.

Type parameters

A

the type of object stored in this lease

Attributes

Supertypes
class Object
trait Matchable
class Any
trait Pool[A <: AnyRef]

A pool of objects that may be leased. It is expected that all implementations of this trait are thread-safe.

A pool of objects that may be leased. It is expected that all implementations of this trait are thread-safe.

Type parameters

A

the type of object to pool

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class ExpiringPool[A]
class SimplePool[A]
object Pool

Object containing factory methods for io.github.andrebeat.pool.Pool.

Object containing factory methods for io.github.andrebeat.pool.Pool.

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Pool.type
sealed trait ReferenceType

An enum-type for Java reference types.

An enum-type for Java reference types.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Soft
object Strong
object Weak
object ReferenceType

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
class SimplePool[A <: AnyRef](capacity: Int, referenceType: ReferenceType, _factory: () => A, _reset: A => Unit, _dispose: A => Unit, _healthCheck: A => Boolean) extends ArrayBlockingQueuePool[A]

A simple object pool that creates the objects as needed until a maximum number of objects has been created.

A simple object pool that creates the objects as needed until a maximum number of objects has been created.

Attributes

Companion
object
Supertypes
trait Pool[A]
class Object
trait Matchable
class Any
object SimplePool

Object containing factory methods for io.github.andrebeat.pool.SimplePool.

Object containing factory methods for io.github.andrebeat.pool.SimplePool.

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
SimplePool.type