| | |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.locks.Lock; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | |
| | | import org.opends.server.core.SearchOperation; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.LockManager.DNLock; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.util.LDIFException; |
| | |
| | | * |
| | | * @return The write lock that has been acquired for the entry. |
| | | */ |
| | | Lock writeLockEntry(DN entryDN) |
| | | DNLock writeLockEntry(DN entryDN) |
| | | { |
| | | Lock lock = LockManager.lockWrite(entryDN); |
| | | DNLock lock = null; |
| | | while (lock == null) |
| | | { |
| | | lock = LockManager.lockWrite(entryDN); |
| | | lock = DirectoryServer.getLockManager().tryWriteLockEntry(entryDN); |
| | | } |
| | | |
| | | return lock; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Attempts to acquire a read lock on the specified entry, trying up to five |
| | | * times before failing. |
| | | * Attempts to acquire a read lock on the specified entry. |
| | | * |
| | | * @param entryDN The DN of the entry for which to acquire the read lock. |
| | | * |
| | |
| | | * |
| | | * @throws DirectoryException If the read lock cannot be acquired. |
| | | */ |
| | | Lock readLockEntry(DN entryDN) |
| | | throws DirectoryException |
| | | DNLock readLockEntry(DN entryDN) throws DirectoryException |
| | | { |
| | | final Lock lock = LockManager.lockRead(entryDN); |
| | | if (lock == null) |
| | | { |
| | | throw new DirectoryException(ResultCode.BUSY, |
| | | ERR_BACKEND_CANNOT_LOCK_ENTRY.get(entryDN)); |
| | | } |
| | | else |
| | | final DNLock lock = DirectoryServer.getLockManager().tryReadLockEntry(entryDN); |
| | | if (lock != null) |
| | | { |
| | | return lock; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Releases the lock held on the specified entry. |
| | | * |
| | | * @param entryDN The DN of the entry for which the lock is held. |
| | | * @param lock The lock held on the entry. |
| | | */ |
| | | void unlockEntry(DN entryDN, Lock lock) |
| | | { |
| | | LockManager.unlock(entryDN, lock); |
| | | throw new DirectoryException(ResultCode.BUSY, ERR_BACKEND_CANNOT_LOCK_ENTRY.get(entryDN)); |
| | | } |
| | | |
| | | |
| | |
| | | for (Task t : tasks.values()) |
| | | { |
| | | DN taskEntryDN = t.getTaskEntryDN(); |
| | | Lock lock = readLockEntry(taskEntryDN); |
| | | |
| | | DNLock lock = readLockEntry(taskEntryDN); |
| | | try |
| | | { |
| | | Entry e = t.getTaskEntry().duplicate(true); |
| | |
| | | } |
| | | finally |
| | | { |
| | | unlockEntry(taskEntryDN, lock); |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | |
| | |
| | | for (RecurringTask rt : recurringTasks.values()) |
| | | { |
| | | DN recurringTaskEntryDN = rt.getRecurringTaskEntryDN(); |
| | | Lock lock = readLockEntry(recurringTaskEntryDN); |
| | | |
| | | DNLock lock = readLockEntry(recurringTaskEntryDN); |
| | | try |
| | | { |
| | | Entry e = rt.getRecurringTaskEntry().duplicate(true); |
| | |
| | | } |
| | | finally |
| | | { |
| | | unlockEntry(recurringTaskEntryDN, lock); |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | |