| | |
| | | |
| | | import org.opends.server.api.Backend; |
| | | |
| | | import static org.opends.server.loggers.Debug.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugCought; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugEnabled; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import static org.opends.server.messages.CoreMessages.*; |
| | | import static org.opends.server.messages.MessageHandler.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | |
| | | */ |
| | | public class LockFileManager |
| | | { |
| | | /** |
| | | * The fully-qualified name of this class for debugging purposes. |
| | | */ |
| | | private static final String CLASS_NAME = |
| | | "org.opends.server.core.LockFileManager"; |
| | | |
| | | |
| | | |
| | |
| | | public static boolean acquireSharedLock(String lockFile, |
| | | StringBuilder failureReason) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "acquireSharedLock", |
| | | String.valueOf(lockFile)); |
| | | |
| | | mapLock.lock(); |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "acquireSharedLock", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_FILELOCKER_LOCK_SHARED_FAILED_CREATE; |
| | | failureReason.append(getMessage(msgID, lockFile, |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "acquireSharedLock", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_FILELOCKER_LOCK_SHARED_FAILED_OPEN; |
| | | failureReason.append(getMessage(msgID, lockFile, |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "acquireSharedLock", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_FILELOCKER_LOCK_SHARED_FAILED_LOCK; |
| | | failureReason.append(getMessage(msgID, |
| | |
| | | public static boolean acquireExclusiveLock(String lockFile, |
| | | StringBuilder failureReason) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "acquireExclusiveLock", |
| | | String.valueOf(lockFile)); |
| | | |
| | | mapLock.lock(); |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "acquireExclusiveLock", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_FAILED_CREATE; |
| | | failureReason.append(getMessage(msgID, lockFile, |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "acquireExclusiveLock", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_FAILED_OPEN; |
| | | failureReason.append(getMessage(msgID, lockFile, |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "acquireExclusiveLock", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_FAILED_LOCK; |
| | | failureReason.append(getMessage(msgID, lockFile, |
| | |
| | | public static boolean releaseLock(String lockFile, |
| | | StringBuilder failureReason) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "releaseLock", |
| | | String.valueOf(lockFile)); |
| | | |
| | | mapLock.lock(); |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "releaseLock", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_FILELOCKER_UNLOCK_EXCLUSIVE_FAILED_RELEASE; |
| | | failureReason.append(getMessage(msgID, lockFile, |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "releaseLock", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // Even though we couldn't close the channel for some reason, this |
| | | // should still be OK because we released the lock above. |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "releaseLock", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_FILELOCKER_UNLOCK_SHARED_FAILED_RELEASE; |
| | | failureReason.append(getMessage(msgID, lockFile, |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "releaseLock", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // Even though we couldn't close the channel for some reason, this |
| | | // should still be OK because we released the lock above. |
| | |
| | | */ |
| | | public static String getLockDirectoryPath() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getLockFileDirectory"); |
| | | |
| | | String lockDirectory = System.getProperty(PROPERTY_LOCK_DIRECTORY); |
| | | if ((lockDirectory == null) || (lockDirectory.length() == 0)) |
| | |
| | | */ |
| | | public static String getServerLockFileName() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getServerLockFileName"); |
| | | |
| | | StringBuilder buffer = new StringBuilder(); |
| | | buffer.append(getLockDirectoryPath()); |
| | |
| | | */ |
| | | public static String getBackendLockFileName(Backend backend) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getBackendLockFileName", |
| | | String.valueOf(backend)); |
| | | |
| | | StringBuilder buffer = new StringBuilder(); |
| | | buffer.append(getLockDirectoryPath()); |