Package org.opends.server.core
Class LockFileManager
- java.lang.Object
-
- org.opends.server.core.LockFileManager
-
public final class LockFileManager extends 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.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
acquireExclusiveLock(String lockFile, StringBuilder failureReason, DirectoryEnvironmentConfig environmentConfig)
Attempts to acquire an exclusive lock on the specified file.static void
acquireExclusiveLockForBackend(String backendID, LocalizableMessageDescriptor.Arg2<Object,Object> failureMsg, DirectoryEnvironmentConfig environmentConfig)
Attempts to acquire an exclusive lock on the specified backend ID.static boolean
acquireSharedLock(String lockFile, StringBuilder failureReason, DirectoryEnvironmentConfig environmentConfig)
Attempts to acquire a shared lock on the specified file.static void
acquireSharedLockForBackend(String backendID, LocalizableMessageDescriptor.Arg2<Object,Object> failureMsg, DirectoryEnvironmentConfig environmentConfig)
Attempts to acquire an shared lock on the specified backend ID.static String
getServerLockFileName(DirectoryEnvironmentConfig environmentConfig)
Retrieves the filename that should be used for the lock file for the Directory Server instance.static void
releaseBackendLock(String backendID, LocalizableMessageDescriptor.Arg2<Object,Object> failureMsg, DirectoryEnvironmentConfig environmentConfig)
Attempts to release a lock on the backend id.static boolean
releaseLock(String lockFile, StringBuilder failureReason)
Attempts to release the lock on the specified file.
-
-
-
Method Detail
-
acquireSharedLockForBackend
public static void acquireSharedLockForBackend(String backendID, LocalizableMessageDescriptor.Arg2<Object,Object> failureMsg, DirectoryEnvironmentConfig environmentConfig) throws LdapException
Attempts to acquire an shared lock on the specified backend ID.- Parameters:
backendID
- The backend ID for which to obtain the shared lock.failureMsg
- the message to use in case the backend lock cannot be obtained.environmentConfig
- the environment config- Throws:
LdapException
- if the shared lock could not be obtained.
-
acquireExclusiveLockForBackend
public static void acquireExclusiveLockForBackend(String backendID, LocalizableMessageDescriptor.Arg2<Object,Object> failureMsg, DirectoryEnvironmentConfig environmentConfig) throws LdapException
Attempts to acquire an exclusive lock on the specified backend ID.- Parameters:
backendID
- The backend ID for which to obtain the exclusive lock.failureMsg
- the message to use in case the backend lock cannot be obtained.environmentConfig
- the environment config- Throws:
LdapException
- if the exclusive lock could not be obtained.
-
acquireSharedLock
public static boolean acquireSharedLock(String lockFile, StringBuilder failureReason, DirectoryEnvironmentConfig environmentConfig)
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.environmentConfig
- The environment config- Returns:
true
if the lock was obtained successfully, orfalse
if it could not be obtained.
-
acquireExclusiveLock
public static boolean acquireExclusiveLock(String lockFile, StringBuilder failureReason, DirectoryEnvironmentConfig environmentConfig)
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.environmentConfig
- The environment config- Returns:
true
if the lock was obtained successfully, orfalse
if it could not be obtained.
-
releaseBackendLock
public static void releaseBackendLock(String backendID, LocalizableMessageDescriptor.Arg2<Object,Object> failureMsg, DirectoryEnvironmentConfig environmentConfig) throws LdapException
Attempts to release a lock on the backend id. 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:
backendID
- The backend ID for which to release the associated lock.failureMsg
- the message to use in case the backe3nd lock cannot be released.environmentConfig
- the environment config- Throws:
LdapException
- if a problem occurred that might have prevented the lock from being released.
-
releaseLock
public static boolean releaseLock(String lockFile, 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, orfalse
if a problem occurred that might have prevented the lock from being released.
-
getServerLockFileName
public static String getServerLockFileName(DirectoryEnvironmentConfig environmentConfig)
Retrieves the filename that should be used for the lock file for the Directory Server instance.- Parameters:
environmentConfig
- the environment config- Returns:
- The filename that should be used for the lock file for the Directory Server instance.
-
-