Trait/Object

com.twitter.util

Disposable

Related Docs: object Disposable | package util

Permalink

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

Abstract Value Members

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

    Permalink

    Dispose of a resource by deadline given.

  2. abstract def get: T

    Permalink

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def dispose(): Future[Unit]

    Permalink
  7. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  11. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  17. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  18. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped