org.opends.server.types
Class LockManager

java.lang.Object
  extended by org.opends.server.types.LockManager

@PublicAPI(stability=UNCOMMITTED,
           mayInstantiate=false,
           mayExtend=false,
           mayInvoke=true)
public final class LockManager
extends java.lang.Object

This class defines a Directory Server component that can keep track of all locks needed throughout the Directory Server. It is intended primarily for entry locking but support for other types of objects might be added in the future.


Field Summary
static int DEFAULT_CONCURRENCY_LEVEL
          The default concurrency level to use for the lock table.
static boolean DEFAULT_FAIR_ORDERING
          The default setting for the use of fair ordering locks.
static int DEFAULT_INITIAL_TABLE_SIZE
          The default initial size to use for the lock table.
static float DEFAULT_LOAD_FACTOR
          The default load factor to use for the lock table.
static long DEFAULT_TIMEOUT
          The default length of time in milliseconds to wait while attempting to acquire a read or write lock.
 
Constructor Summary
LockManager()
           
 
Method Summary
static java.util.concurrent.locks.ReentrantReadWriteLock destroyLock(DN entryDN)
          Removes any reference to the specified entry from the lock table.
static java.util.concurrent.locks.Lock lockRead(DN entryDN)
          Attempts to acquire a read lock for the specified entry.
static java.util.concurrent.locks.Lock lockRead(DN entryDN, long timeout)
          Attempts to acquire a read lock for the specified entry.
static int lockTableSize()
          Retrieves the number of entries currently held in the lock table.
static java.util.concurrent.locks.Lock lockWrite(DN entryDN)
          Attempts to acquire the write lock for the specified entry.
static java.util.concurrent.locks.Lock lockWrite(DN entryDN, long timeout)
          Attempts to acquire the write lock for the specified entry.
static void reinitializeLockTable()
          Recreates the lock table.
static java.util.concurrent.locks.Lock tryLockRead(DN entryDN)
          Attempts to acquire a read lock on the specified entry.
static java.util.concurrent.locks.Lock tryLockWrite(DN entryDN)
          Attempts to acquire a write lock on the specified entry.
static void unlock(DN entryDN, java.util.concurrent.locks.Lock lock)
          Releases a read or write lock held on the specified entry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FAIR_ORDERING

public static final boolean DEFAULT_FAIR_ORDERING
The default setting for the use of fair ordering locks.

See Also:
Constant Field Values

DEFAULT_INITIAL_TABLE_SIZE

public static final int DEFAULT_INITIAL_TABLE_SIZE
The default initial size to use for the lock table.

See Also:
Constant Field Values

DEFAULT_CONCURRENCY_LEVEL

public static final int DEFAULT_CONCURRENCY_LEVEL
The default concurrency level to use for the lock table.

See Also:
Constant Field Values

DEFAULT_LOAD_FACTOR

public static final float DEFAULT_LOAD_FACTOR
The default load factor to use for the lock table.

See Also:
Constant Field Values

DEFAULT_TIMEOUT

public static final long DEFAULT_TIMEOUT
The default length of time in milliseconds to wait while attempting to acquire a read or write lock.

See Also:
Constant Field Values
Constructor Detail

LockManager

public LockManager()
Method Detail

reinitializeLockTable

public static void reinitializeLockTable()
Recreates the lock table. This should be called only in the case that the Directory Server is in the process of an in-core restart because it will destroy the existing lock table.


tryLockRead

public static java.util.concurrent.locks.Lock tryLockRead(DN entryDN)
Attempts to acquire a read lock on the specified entry. It will succeed only if the write lock is not already held. If any blocking is required, then this call will fail rather than block.

Parameters:
entryDN - The DN of the entry for which to obtain the read lock.
Returns:
The read lock that was acquired, or null if it was not possible to obtain a read lock for some reason.

lockRead

public static java.util.concurrent.locks.Lock lockRead(DN entryDN)
Attempts to acquire a read lock for the specified entry. Multiple threads can hold the read lock concurrently for an entry as long as the write lock is held. If the write lock is held, then no other read or write locks will be allowed for that entry until the write lock is released. A default timeout will be used for the lock.

Parameters:
entryDN - The DN of the entry for which to obtain the read lock.
Returns:
The read lock that was acquired, or null if it was not possible to obtain a read lock for some reason.

lockRead

public static java.util.concurrent.locks.Lock lockRead(DN entryDN,
                                                       long timeout)
Attempts to acquire a read lock for the specified entry. Multiple threads can hold the read lock concurrently for an entry as long as the write lock is not held. If the write lock is held, then no other read or write locks will be allowed for that entry until the write lock is released.

Parameters:
entryDN - The DN of the entry for which to obtain the read lock.
timeout - The maximum length of time in milliseconds to wait for the lock before timing out.
Returns:
The read lock that was acquired, or null if it was not possible to obtain a read lock for some reason.

tryLockWrite

public static java.util.concurrent.locks.Lock tryLockWrite(DN entryDN)
Attempts to acquire a write lock on the specified entry. It will succeed only if the lock is not already held. If any blocking is required, then this call will fail rather than block.

Parameters:
entryDN - The DN of the entry for which to obtain the write lock.
Returns:
The write lock that was acquired, or null if it was not possible to obtain a write lock for some reason.

lockWrite

public static java.util.concurrent.locks.Lock lockWrite(DN entryDN)
Attempts to acquire the write lock for the specified entry. Only a single thread may hold the write lock for an entry at any given time, and during that time no read locks may be held for it. A default timeout will be used for the lock.

Parameters:
entryDN - The DN of the entry for which to obtain the write lock.
Returns:
The write lock that was acquired, or null if it was not possible to obtain a write lock for some reason.

lockWrite

public static java.util.concurrent.locks.Lock lockWrite(DN entryDN,
                                                        long timeout)
Attempts to acquire the write lock for the specified entry. Only a single thread may hold the write lock for an entry at any given time, and during that time no read locks may be held for it.

Parameters:
entryDN - The DN of the entry for which to obtain the write lock.
timeout - The maximum length of time in milliseconds to wait for the lock before timing out.
Returns:
The write lock that was acquired, or null if it was not possible to obtain a read lock for some reason.

unlock

public static void unlock(DN entryDN,
                          java.util.concurrent.locks.Lock lock)
Releases a read or write lock held on the specified entry.

Parameters:
entryDN - The DN of the entry for which to release the lock.
lock - The read or write lock held for the entry.

destroyLock

public static java.util.concurrent.locks.ReentrantReadWriteLock destroyLock(DN entryDN)
Removes any reference to the specified entry from the lock table. This may be helpful if there is a case where a lock has been orphaned somehow and must be removed before other threads may acquire it.

Parameters:
entryDN - The DN of the entry for which to remove the lock from the table.
Returns:
The read write lock that was removed from the table, or null if nothing was in the table for the specified entry. If a lock object is returned, it may be possible to get information about who was holding it.

lockTableSize

public static int lockTableSize()
Retrieves the number of entries currently held in the lock table. Note that this may be an expensive operation.

Returns:
The number of entries currently held in the lock table.