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.
- Alphabetic
- By Inheritance
- Disposable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
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
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def dispose(): Future[Unit]
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- 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()