| | |
| | | import java.nio.channels.FileChannel; |
| | | import java.nio.channels.FileLock; |
| | | import java.util.HashMap; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.opends.server.api.Backend; |
| | | |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | |
| | | import static org.opends.messages.CoreMessages.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | |
| | | new HashMap<String,Integer>(); |
| | | |
| | | // The lock providing threadsafe access to the lock map data. |
| | | private static ReentrantLock mapLock = new ReentrantLock(); |
| | | private static Object mapLock = new Object(); |
| | | |
| | | |
| | | |
| | |
| | | public static boolean acquireSharedLock(String lockFile, |
| | | StringBuilder failureReason) |
| | | { |
| | | mapLock.lock(); |
| | | |
| | | try |
| | | synchronized (mapLock) |
| | | { |
| | | // Check to see if there's already an exclusive lock on the file. If so, |
| | | // then we can't get a shared lock on it. |
| | |
| | | return true; |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | mapLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public static boolean acquireExclusiveLock(String lockFile, |
| | | StringBuilder failureReason) |
| | | { |
| | | mapLock.lock(); |
| | | |
| | | try |
| | | synchronized (mapLock) |
| | | { |
| | | // Check to see if there's already an exclusive lock on the file. If so, |
| | | // then we can't get another exclusive lock on it. |
| | |
| | | return true; |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | mapLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | public static boolean releaseLock(String lockFile, |
| | | StringBuilder failureReason) |
| | | { |
| | | mapLock.lock(); |
| | | |
| | | try |
| | | synchronized (mapLock) |
| | | { |
| | | // See if we hold an exclusive lock on the file. If so, then release it |
| | | // and get remove it from the lock table. |
| | |
| | | failureReason.append(ERR_FILELOCKER_UNLOCK_UNKNOWN_FILE.get(lockFile)); |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | mapLock.unlock(); |
| | | } |
| | | } |
| | | |
| | | |