use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget in project snow-owl by b2ihealthcare.
the class DefaultOperationLockManager method unlock.
@Override
public void unlock(final DatastoreLockContext context, final Iterable<DatastoreLockTarget> targets) throws IllegalArgumentException {
final Map<DatastoreLockTarget, DatastoreLockContext> notUnlockedTargets = Maps.newHashMap();
synchronized (syncObject) {
for (final DatastoreLockTarget targetToUnlock : targets) {
for (final IOperationLock existingLock : getExistingLocks()) {
if (existingLock.targetEquals(targetToUnlock) && !canContextUnlock(context, existingLock)) {
notUnlockedTargets.put(existingLock.getTarget(), existingLock.getContext());
}
}
}
if (!notUnlockedTargets.isEmpty()) {
LOG.warn(buildMessage(RELEASE_FAILED_MESSAGE, context, notUnlockedTargets));
}
for (final DatastoreLockTarget targetToUnlock : targets) {
final IOperationLock existingLock = getOrCreateLock(context, targetToUnlock);
try {
existingLock.release(context);
fireTargetReleased(existingLock.getTarget(), context);
} finally {
if (!existingLock.isLocked()) {
removeLock(existingLock);
}
}
}
syncObject.notifyAll();
}
}
use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget in project snow-owl by b2ihealthcare.
the class DatastoreLockTests method testUnlock.
@Test
public void testUnlock() {
final DatastoreLockContext context = createContext(USER, DatastoreLockContextDescriptions.MAINTENANCE);
final DatastoreLockTarget target = new DatastoreLockTarget("snomedStore", "MAIN");
manager.lock(context, TIMEOUT, target);
checkIfLockExists(context, true, target);
manager.unlock(context, target);
checkIfLockExists(context, false, target);
}
use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget in project snow-owl by b2ihealthcare.
the class DatastoreLockTests method testLockBranchAndRepository.
@Test
public void testLockBranchAndRepository() {
final DatastoreLockContext context = createContext(USER, DatastoreLockContextDescriptions.CREATE_VERSION);
final DatastoreLockTarget target = new DatastoreLockTarget("snomedStore", "MAIN");
manager.lock(context, 10_000L, target);
checkIfLockExists(context, true, target);
}
use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget in project snow-owl by b2ihealthcare.
the class DatastoreLockTests method testLockAllNotAbleToLockAnother.
@Test(expected = LockedException.class)
public void testLockAllNotAbleToLockAnother() {
final DatastoreLockContext context = createContext(USER, DatastoreLockContextDescriptions.MAINTENANCE);
final DatastoreLockTarget allLockTarget = DatastoreLockTarget.ALL;
manager.lock(context, 1_000L, allLockTarget);
manager.lock(context, 1_000L, allLockTarget);
}
use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget in project snow-owl by b2ihealthcare.
the class DatastoreLockTests method checkIfLockExists.
private void checkIfLockExists(DatastoreLockContext context, boolean expected, DatastoreLockTarget... targets) {
for (int i = 0; i < targets.length; i++) {
final DatastoreLockTarget target = targets[i];
final OperationLock operationLock = new OperationLock(i, target);
operationLock.acquire(context);
final OperationLockInfo info = new OperationLockInfo(i, operationLock.getLevel(), operationLock.getCreationDate(), target, context);
assertTrue(expected == manager.getLocks().contains(info));
}
}
Aggregations