ModeShape Distribution 3.0.0.Beta4

org.modeshape.jcr.value.binary
Class NamedLocks

java.lang.Object
  extended by 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
protected  class NamedLocks.NamedLock
           
protected static class NamedLocks.WrappedLock
           
 
Constructor Summary
NamedLocks()
           
 
Method Summary
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., NamedLocks.WrappedLock.lock(), NamedLocks.WrappedLock.lockInterruptibly(), NamedLocks.WrappedLock.tryLock() or NamedLocks.WrappedLock.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., NamedLocks.WrappedLock.lock(), NamedLocks.WrappedLock.lockInterruptibly(), NamedLocks.WrappedLock.tryLock() or NamedLocks.WrappedLock.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

ModeShape Distribution 3.0.0.Beta4

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