Packages

trait Disposable[+T] extends AnyRef

Resource Management

com.twitter.util.Disposable represents a live resource that must be disposed after use. com.twitter.util.Managed is a factory for creating and composing such resources. Managed resources are composed together so their lifetimes are synchronized.

The following example shows how to build and use composite managed resources:

// Create managed Tracer
def mkManagedTracer() = new Managed[Tracer] {
  def make() = new Disposable[Tracer] {
    val underlying = new Tracer()
    def get = underlying
    def dispose(deadline: Time) = underlying.close() // assumes Tracer uses relese() to manage lifetime
  }
}

// Create managed Server using Tracer as dependency
def mkManagedServer(t: Tracer) = new Managed[Server] {
  def make() = new Disposable[Server] {
    val underlying = new Server(t) // Server requires tracer to be created
    def get = underlying
    def dispose(deadline: Time) = underlying.close() // assumes Server uses close() to manage lifetime
  }
}

// Create composite resource
val compRes: Managed[Server] = for {
  a <- mkManagedTracer()
  b <- mkManagedServer(a)
} yield b

// Use composite resource in safe fashion. It's guaranteed that both resources
// will be properly closed/released when done using them.
compRes foreach { b =>
  // use b (which is type Server in this case)
} // dispose called on both resources

Disposable/Managed Semantics

com.twitter.util.Disposable: get can be called multiple times and should return same instance; dispose can be called only once and should release resource that get is returning; calling get after dispose is undefined.

com.twitter.util.Managed: multiple calls to make could return a) new instance or b) ref counted instance of the underlying resource or c) same instance when resource doesn't need to be actually disposed, etc.

Disposable is a container for a resource that must be explicitly disposed when no longer needed. After this, the resource is no longer available.

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

Abstract Value Members

  1. abstract def dispose(deadline: Time): Future[Unit]

    Dispose of a resource by deadline given.

  2. abstract def get: T

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. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. final def dispose(): Future[Unit]
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  10. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  17. def toString(): String
    Definition Classes
    AnyRef → Any
  18. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  19. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  20. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped