Packages

final class UniqueLockMonitor extends AutoCloseable

A stateful implementation of an auto-closable lock/monitor for the specified lock with an ability to unlock it preliminarily. The class philosophy and namings are borrowed from C++ std::unique_lock<>.

Usage example:

import scala.util.Using
import java.util.concurrent.locks.ReentrantLock

class Test {

  private val statusLock = new ReentrantLock()

  def tryWithResourceExample() = {
     Using( UniqueLockMonitor.lockAndMonitor( statusLock ) ) { monitor =>
        // do something inside a lock
     }
  }

  def preliminaryUnlockExample() = {
     Using( UniqueLockMonitor.lockAndMonitor( statusLock ) ) { monitor =>
         // do something inside a lock
         monitor.unlock()
         // do something else outside locking and UniqueLockMonitor.close() now does nothing
     }
  }

}
Note

this class isn't reentrant and isn't supposed to be shared across threads or used as a field. This class should be used as a stack/method local variable with try-with-resources.

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

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( ... ) @native()
  6. def close(): Unit

    Auto close (unlock) if it hasn't been released or unlocked already.

    Auto close (unlock) if it hasn't been released or unlocked already.

    Definition Classes
    UniqueLockMonitor → AutoCloseable
  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[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]
    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. def lock(): UniqueLockMonitor

    Lock manually.

    Lock manually. Consequent multiple locks aren't allowed to avoid mistakes and sharing monitor instances.

    returns

    the same instance

  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. def release(): Lock

    Release/take a lock from monitor, so it wouldn't be unlocked automatically in close.

    Release/take a lock from monitor, so it wouldn't be unlocked automatically in close. You can't use lock/unlock after releasing a monitor.

  18. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  19. def toString(): String
    Definition Classes
    AnyRef → Any
  20. def unlock(): UniqueLockMonitor

    Unlock manually.

    Unlock manually. Consequent multiple unlocks aren't allowed to avoid mistakes and sharing monitor instances.

    returns

    the same instance

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

Inherited from AutoCloseable

Inherited from AnyRef

Inherited from Any

Ungrouped