org.modeshape.jcr.value.binary

## Class NamedLocks

- java.lang.Object
- - org.modeshape.jcr.value.binary.NamedLocks

-     public class NamedLocks
      extends Object

  A utility class that represents a set of named locks, allowing callers to atomically obtain a lock with a given name. Locks are released as normal. This class uses reference counts to remove locks only when a named lock is no longer being used.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `NamedLocks.NamedLock`
    `protected static class` | `NamedLocks.WrappedLock`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NamedLocks()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Lock` | `lock(String name, boolean writeLock)`
    `Lock` | `readLock(String name)` Obtain a read lock for the supplied name.
    `int` | `size()` Get the number of named locks.
    `protected void` | `unlock(NamedLocks.NamedLock namedLock, Lock rawLock)`
    `Lock` | `writeLock(String name)` Obtain a write lock for the supplied name.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### NamedLocks

          public NamedLocks()

  - ### Method Detail

    - #### writeLock

          public Lock writeLock(String name)

      Obtain a write lock for the supplied name. When this method returns, the current thread will have obtained the lock. Therefore, there is no need to call any of the lock methods (e.g., `Lock.lock()`, `Lock.lockInterruptibly()`, `Lock.tryLock()` or `Lock.tryLock(long, TimeUnit)`), as those methods will immediately return.
      Parameters:
        `name` - the name of the lock
      Returns:
        the lock held by the current thread; never null

    - #### readLock

          public Lock readLock(String name)

      Obtain a read lock for the supplied name. When this method returns, the current thread will have obtained the lock. Therefore, there is no need to call any of the lock methods (e.g., `Lock.lock()`, `Lock.lockInterruptibly()`, `Lock.tryLock()` or `Lock.tryLock(long, TimeUnit)`), as those methods will immediately return.
      Parameters:
        `name` - the name of the lock
      Returns:
        the lock held by the current thread; never null

    - #### lock

          protected final Lock lock(String name,
                  boolean writeLock)

    - #### unlock

          protected void unlock(NamedLocks.NamedLock namedLock,
                    Lock rawLock)

    - #### size

          public int size()

      Get the number of named locks.
      Returns:
        the number of named locks; never negative

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.