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

trait Lease[A <: AnyRef] extends 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

the type of object stored in this lease

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Lease
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def a: A
    Attributes
    protected[this]
  2. abstract def handleInvalidate(): Unit
    Attributes
    protected[this]
  3. abstract def handleRelease(): Unit
    Attributes
    protected[this]

Concrete 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 apply[B](f: (A) ⇒ B): B

    Gets the value from the lease, passing it onto the provided function and releasing it back to the pool after the function is run.

    Gets the value from the lease, passing it onto the provided function and releasing it back to the pool after the function is run.

    If needed, it is possible to invalidate the lease from inside the provided function, for example:

    val lease = pool.acquire()
    val x = lease { v =>
      if (/* invalid condition */) { lease.invalidate(); None }
      else Some(/* result */)
    }

    It is important that no references are kept to the leased object after this method finishes. For example, the following code is invalid since the variable x holds a reference to an object that was returned to the pool.

    val lease = pool.acquire()
    val x = lease(identity)
    B

    the type of object returned by the function f

    f

    a function that uses the value stored in the lease to produce a new value

    returns

    the value produced by the function f.

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. def get(): A

    Returns the object being leased by the pool.

    Returns the object being leased by the pool. Throws an java.lang.IllegalStateException if the lease has already been released or invalidated.

    returns

    the object being leased by the pool.

  11. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. def invalidate(): Unit

    Invalidates the current lease.

    Invalidates the current lease. The object is "destroyed" and is no longer eligible to be returned to the pool. Additionally, the number of live objects in the pool is decremented.

    If the lease has already been released or invalidated this method does nothing.

  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  18. def release(): Unit

    Releases the object back to the pool for reuse.

    Releases the object back to the pool for reuse. When releasing an object it is mandatory that there are no references to the returned object.

    When an object is released to a pool that has already been closed it is "destroyed".

    If the lease has already been released or invalidated this method does nothing.

  19. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  20. def toString(): String
    Definition Classes
    AnyRef → Any
  21. def use[B](f: (A) ⇒ B): B

    Gets the value from the lease, passing it onto the provided function and releasing it back to the pool after the function is run.

    Gets the value from the lease, passing it onto the provided function and releasing it back to the pool after the function is run.

    Alias method for apply.

    See also

    io.github.andrebeat.pool.Lease.apply

  22. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped