org.opends.server.core
Class LockFileManager

java.lang.Object
  extended by org.opends.server.core.LockFileManager

public class LockFileManager
extends java.lang.Object

This class provides a mechanism for allowing the Directory Server to utilize file locks as provided by the underlying OS. File locks may be exclusive or shared, and will be visible between different processes on the same system.


Constructor Summary
LockFileManager()
           
 
Method Summary
static boolean acquireExclusiveLock(java.lang.String lockFile, java.lang.StringBuilder failureReason)
          Attempts to acquire an exclusive lock on the specified file.
static boolean acquireSharedLock(java.lang.String lockFile, java.lang.StringBuilder failureReason)
          Attempts to acquire a shared lock on the specified file.
static java.lang.String getBackendLockFileName(Backend backend)
          Retrieves the filename that should be used for the lock file for the specified backend.
static java.lang.String getLockDirectoryPath()
          Retrieves the path to the directory that should be used to hold the lock files.
static java.lang.String getServerLockFileName()
          Retrieves the filename that should be used for the lock file for the Directory Server instance.
static boolean releaseLock(java.lang.String lockFile, java.lang.StringBuilder failureReason)
          Attempts to release the lock on the specified file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LockFileManager

public LockFileManager()
Method Detail

acquireSharedLock

public static boolean acquireSharedLock(java.lang.String lockFile,
                                        java.lang.StringBuilder failureReason)
Attempts to acquire a shared lock on the specified file.

Parameters:
lockFile - The file for which to obtain the shared lock.
failureReason - A buffer that can be used to hold a reason that the lock could not be acquired.
Returns:
true if the lock was obtained successfully, or false if it could not be obtained.

acquireExclusiveLock

public static boolean acquireExclusiveLock(java.lang.String lockFile,
                                           java.lang.StringBuilder failureReason)
Attempts to acquire an exclusive lock on the specified file.

Parameters:
lockFile - The file for which to obtain the exclusive lock.
failureReason - A buffer that can be used to hold a reason that the lock could not be acquired.
Returns:
true if the lock was obtained successfully, or false if it could not be obtained.

releaseLock

public static boolean releaseLock(java.lang.String lockFile,
                                  java.lang.StringBuilder failureReason)
Attempts to release the lock on the specified file. If an exclusive lock is held, then it will be released. If a shared lock is held, then its reference count will be reduced, and the lock will be released if the resulting reference count is zero. If we don't know anything about the requested file, then don't do anything.

Parameters:
lockFile - The file for which to release the associated lock.
failureReason - A buffer that can be used to hold information about a problem that occurred preventing the successful release.
Returns:
true if the lock was found and released successfully, or false if a problem occurred that might have prevented the lock from being released.

getLockDirectoryPath

public static java.lang.String getLockDirectoryPath()
Retrieves the path to the directory that should be used to hold the lock files.

Returns:
The path to the directory that should be used to hold the lock files.

getServerLockFileName

public static java.lang.String getServerLockFileName()
Retrieves the filename that should be used for the lock file for the Directory Server instance.

Returns:
The filename that should be used for the lock file for the Directory Server instance.

getBackendLockFileName

public static java.lang.String getBackendLockFileName(Backend backend)
Retrieves the filename that should be used for the lock file for the specified backend.

Parameters:
backend - The backend for which to retrieve the filename for the lock file.
Returns:
The filename that should be used for the lock file for the specified backend.