Object

com.thoughtworks.raii

ownership

Related Doc: package raii

Permalink

object ownership

The name space for types that models ownership of resources.

Author:

杨博 (Yang Bo) <[email protected]>

Example:
  1. import com.thoughtworks.raii.ownership._
    class TheOwner extends AutoCloseable {
      private val myStream: this.type Owned InputStream = this.own(new FileInputStream("foo.txt"))
      def close() = myStream.close()
      def withMyStream(f: Borrowing[InputStream] => Unit) = {
        f(myStream)
      }
    }
    val owner = new TheOwner
    owner.withMyStream { inputStream: Borrowing[InputStream] =>
      println(inputStream.read())
    }
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ownership
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. type Borrowing[+A] = ownership.OpacityTypes.Borrowing[A]

    Permalink

    An object A that may be scoped.

    An object A that may be scoped.

    A method that accepts a Borrowing parameter must follows all instructions on Scoped resource. However, a method that provides a Borrowing may create it either from GarbageCollectable or from Owned.

  2. trait Duplicate[A] extends AnyRef

    Permalink
  3. implicit final class DuplicateOps[A] extends AnyRef

    Permalink
  4. type GarbageCollectable[+A] = ownership.OpacityTypes.GarbageCollectable[A]

    Permalink

    An object A that is managed by garbage collector.

  5. trait Move[OldOwner <: Singleton, A] extends AnyRef

    Permalink
  6. implicit final class MoveOps[OldOwner <: Singleton, A] extends AnyRef

    Permalink
  7. final class OwnOps[Owner <: Singleton] extends AnyRef

    Permalink
  8. type Owned[-Owner <: Singleton, +A] = ownership.OpacityTypes.Owned[Owner, A]

    Permalink

    A Scoped resource managed by Owner.

    A Scoped resource managed by Owner.

    It's Owner's responsibility to close or release the underlying resource when exiting the scope.

  9. type Scoped[+A] = ownership.OpacityTypes.Owned[Nothing, A]

    Permalink

    An resource A that is only available in certain scope.

    An resource A that is only available in certain scope.

    For example, a FileInputStream that will be automatically closed when exiting a scope.

    Example:
    1. val outOfScopeStore = ArrayBuffer.empty[FileInputStream]
      def read(stream: Scoped[FileInputStream]) = {
        // OK! You can use a scoped resource inside `read` method
        stream.read();
        // Wrong! A scoped resource should not be stored.
        outOfScopeStore += stream
        // Wrong! A scoped resource is managed by another owner. It should not be closed inside the scope.
        stream.close();
      }
    Note

    You should not store Scoped resource for out-of-scope usage.

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. object Owned

    Permalink
  5. final def asInstanceOf[T0]: T0

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

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  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. def garbageCollectable[A](a: A): GarbageCollectable[A]

    Permalink

    Marks a as garbage collectable.

  11. final def getClass(): Class[_]

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

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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
  18. implicit def toOwnOps(owner: AnyRef): OwnOps[owner.type]

    Permalink
  19. def toString(): String

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

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

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

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

Inherited from AnyRef

Inherited from Any

Ungrouped