Packages

  • package root
    Definition Classes
    root
  • package io
    Definition Classes
    root
  • package github
    Definition Classes
    io
  • package andrebeat
    Definition Classes
    github
  • package pool

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

    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
    Definition Classes
    andrebeat
  • ArrayBlockingQueuePool
  • ExpiringPool
  • Lease
  • Pool
  • ReferenceType
  • SimplePool

class SimplePool[A <: AnyRef] extends ArrayBlockingQueuePool[A]

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

Linear Supertypes
ArrayBlockingQueuePool[A], Pool[A], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. SimplePool
  2. ArrayBlockingQueuePool
  3. Pool
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new SimplePool(capacity: Int, referenceType: ReferenceType, _factory: () ⇒ A, _reset: (A) ⇒ Unit, _dispose: (A) ⇒ Unit, _healthCheck: (A) ⇒ Boolean)

Type Members

  1. abstract class Item extends AnyRef
    Attributes
    protected
    Definition Classes
    ArrayBlockingQueuePool
  2. final class SimpleItem extends Item
    Attributes
    protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. 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.

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. val capacity: Int
    Definition Classes
    ArrayBlockingQueuePoolPool
  7. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  8. 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
  9. val closed: AtomicBoolean
    Attributes
    protected[this]
    Definition Classes
    Pool
  10. def destroy(a: A): Unit
    Attributes
    protected[this]
    Definition Classes
    ArrayBlockingQueuePool
    Annotations
    @inline()
  11. 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[this]
    Definition Classes
    SimplePoolPool
    Annotations
    @inline()
  12. 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.

  13. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  15. def factory(): A

    Factory method for creating new objects.

    Factory method for creating new objects.

    returns

    a new object.

    Attributes
    protected[this]
    Definition Classes
    SimplePoolPool
    Annotations
    @inline()
  16. 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.

  17. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  18. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  19. def handleAcquire(): Lease[A]
    Attributes
    protected[this]
    Definition Classes
    ArrayBlockingQueuePoolPool
  20. def handleClose(): Unit
    Attributes
    protected[this]
    Definition Classes
    SimplePoolPool
    Annotations
    @inline()
  21. final def handleDrain(): Unit
    Attributes
    protected[this]
    Definition Classes
    ArrayBlockingQueuePoolPool
    Annotations
    @tailrec()
  22. final def handleFill(): Unit
    Attributes
    protected[this]
    Definition Classes
    ArrayBlockingQueuePoolPool
    Annotations
    @tailrec()
  23. def handleTryAcquire(atMost: Duration): Option[Lease[A]]
    Attributes
    protected[this]
    Definition Classes
    ArrayBlockingQueuePoolPool
  24. def handleTryAcquire(): Option[Lease[A]]
    Attributes
    protected[this]
    Definition Classes
    ArrayBlockingQueuePoolPool
  25. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  26. 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[this]
    Definition Classes
    SimplePoolPool
    Annotations
    @inline()
  27. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  28. val items: ArrayBlockingQueue[Item]
    Attributes
    protected[this]
    Definition Classes
    ArrayBlockingQueuePool
  29. 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
  30. 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
    ArrayBlockingQueuePoolPool
  31. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  32. def newItem(a: A): Item
    Attributes
    protected[this]
    Definition Classes
    SimplePoolArrayBlockingQueuePool
    Annotations
    @inline()
  33. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  34. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  35. val referenceType: ReferenceType
    Definition Classes
    ArrayBlockingQueuePoolPool
  36. 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[this]
    Definition Classes
    SimplePoolPool
    Annotations
    @inline()
  37. 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
    ArrayBlockingQueuePoolPool
  38. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  39. def toString(): String
    Definition Classes
    AnyRef → Any
  40. 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.

  41. 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.

  42. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  43. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  44. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from ArrayBlockingQueuePool[A]

Inherited from Pool[A]

Inherited from AnyRef

Inherited from Any

Ungrouped