Search in sources :

Example 1 with DatastoreLockTarget

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();
    }
}
Also used : DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext)

Example 2 with DatastoreLockTarget

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);
}
Also used : DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext) Test(org.junit.Test)

Example 3 with DatastoreLockTarget

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);
}
Also used : DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext) Test(org.junit.Test)

Example 4 with DatastoreLockTarget

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);
}
Also used : DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext) Test(org.junit.Test)

Example 5 with DatastoreLockTarget

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));
    }
}
Also used : DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget)

Aggregations

DatastoreLockTarget (com.b2international.snowowl.core.internal.locks.DatastoreLockTarget)16 DatastoreLockContext (com.b2international.snowowl.core.internal.locks.DatastoreLockContext)14 Test (org.junit.Test)5 Operation (io.swagger.v3.oas.annotations.Operation)4 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)4 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)2 IOperationLockManager (com.b2international.snowowl.core.locks.IOperationLockManager)2 CycleDetectedException (com.b2international.commons.exceptions.CycleDetectedException)1 IndexException (com.b2international.index.IndexException)1 BaseRevisionBranching (com.b2international.index.revision.BaseRevisionBranching)1 RevisionBranch (com.b2international.index.revision.RevisionBranch)1 Repository (com.b2international.snowowl.core.Repository)1 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)1 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)1 Locks (com.b2international.snowowl.core.locks.Locks)1 OverridingMethodsMustInvokeSuper (javax.annotation.OverridingMethodsMustInvokeSuper)1