use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget in project snow-owl by b2ihealthcare.
the class DatastoreLockTests method testUnlockAll.
@Test
public void testUnlockAll() {
final DatastoreLockContext context = createContext(USER, DatastoreLockContextDescriptions.MAINTENANCE);
final DatastoreLockTarget target1 = new DatastoreLockTarget("snomedStore", "MAIN");
final DatastoreLockTarget target2 = new DatastoreLockTarget("loincStore", "MAIN");
manager.lock(context, TIMEOUT, target1, target2);
checkIfLockExists(context, true, target1, target2);
manager.unlockAll();
checkIfLockExists(context, false, target1, target2);
}
use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget in project snow-owl by b2ihealthcare.
the class RepositoryRestService method unlockGlobal.
@Operation(summary = "Unlock all repositories", description = "Releases a previously acquired global lock.")
@ApiResponses({ @ApiResponse(responseCode = "204", description = "Unlock successful"), @ApiResponse(responseCode = "400", description = "Unspecified unlock-related issue") })
@ResponseStatus(HttpStatus.NO_CONTENT)
@PostMapping("/unlock")
public void unlockGlobal() {
final DatastoreLockContext context = new DatastoreLockContext(User.SYSTEM.getUsername(), DatastoreLockContextDescriptions.CREATE_BACKUP);
final DatastoreLockTarget target = DatastoreLockTarget.ALL;
doUnlock(context, target);
}
use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget in project snow-owl by b2ihealthcare.
the class DefaultOperationLockManager method canContextLockTargets.
@OverridingMethodsMustInvokeSuper
protected void canContextLockTargets(final DatastoreLockContext context, final Iterable<DatastoreLockTarget> targets, final Map<DatastoreLockTarget, DatastoreLockContext> alreadyLockedTargets) throws LockedException {
if (!isDisposed()) {
for (final DatastoreLockTarget newTarget : targets) {
for (final IOperationLock existingLock : getExistingLocks()) {
if (existingLock.targetConflicts(newTarget) && !canContextLock(context, existingLock)) {
alreadyLockedTargets.put(newTarget, existingLock.getContext());
}
}
}
} else {
final DatastoreLockContext disposedContext = createLockContext(User.SYSTEM.getUsername(), DatastoreLockContextDescriptions.DISPOSE_LOCK_MANAGER, null);
for (final DatastoreLockTarget target : targets) {
alreadyLockedTargets.put(target, disposedContext);
}
throwLockedException(ACQUIRE_FAILED_MESSAGE, context, alreadyLockedTargets);
}
}
use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget in project snow-owl by b2ihealthcare.
the class DefaultOperationLockManager method lock.
@Override
public void lock(final DatastoreLockContext context, final long timeoutMillis, final Iterable<DatastoreLockTarget> targets) throws LockedException {
final Map<DatastoreLockTarget, DatastoreLockContext> alreadyLockedTargets = Maps.newHashMap();
final long startTimeMillis = getCurrentTimeMillis();
try {
synchronized (syncObject) {
while (true) {
alreadyLockedTargets.clear();
canContextLockTargets(context, targets, alreadyLockedTargets);
if (alreadyLockedTargets.isEmpty()) {
for (final DatastoreLockTarget newTarget : targets) {
final IOperationLock existingLock = getOrCreateLock(context, newTarget);
fireTargetAcquired(existingLock.getTarget(), context);
}
syncObject.notifyAll();
return;
}
if (NO_TIMEOUT == timeoutMillis) {
syncObject.wait();
} else {
final long remainingTimeoutMillis = timeoutMillis - (getCurrentTimeMillis() - startTimeMillis);
if (remainingTimeoutMillis < 1L) {
throwLockedException(ACQUIRE_FAILED_MESSAGE, context, alreadyLockedTargets);
} else {
syncObject.wait(remainingTimeoutMillis);
}
}
}
}
} catch (InterruptedException e) {
throw new SnowowlRuntimeException(e);
}
}
use of com.b2international.snowowl.core.internal.locks.DatastoreLockTarget in project snow-owl by b2ihealthcare.
the class LocksCommand method parseLockTarget.
private static DatastoreLockTarget parseLockTarget(final String lockTargetOrAll) {
if (ALL.equalsIgnoreCase(lockTargetOrAll)) {
return DatastoreLockTarget.ALL;
}
final String repositoryId;
final String path;
String[] parts = lockTargetOrAll.split(":");
if (parts.length == 2) {
repositoryId = parts[0];
path = parts[1];
} else if (parts.length == 1) {
repositoryId = parts[0];
path = null;
} else {
return null;
}
final RepositoryManager repositoryManager = ApplicationContext.getInstance().getService(RepositoryManager.class);
final Repository repository = repositoryManager.get(repositoryId);
if (null == repository) {
return null;
}
if (Strings.isNullOrEmpty(path)) {
return new DatastoreLockTarget(repositoryId, null);
}
final IBranchPath branchPath = BranchPathUtils.createPath(path);
// assuming active connection manager service here
RevisionBranch branch = repository.service(BaseRevisionBranching.class).getBranch(path);
if (null == branch) {
return null;
}
return new DatastoreLockTarget(repositoryId, branchPath.getPath());
}
Aggregations