use of org.olat.core.util.coordinate.LockResultImpl in project OpenOLAT by OpenOLAT.
the class ClusterLocker method acquireLock.
@Override
public LockResult acquireLock(final OLATResourceable ores, final Identity requestor, final String locksubkey) {
final String asset = OresHelper.createStringRepresenting(ores, locksubkey);
LockResult res = syncer.doInSync(ores, new SyncerCallback<LockResult>() {
@Override
public LockResult execute() {
LockResultImpl lres;
LockImpl li = clusterLockManager.findLock(asset);
if (li == null) {
// fine, we can lock it
li = clusterLockManager.createLockImpl(asset, requestor);
clusterLockManager.saveLock(li);
LockEntry le = new LockEntry(li.getAsset(), li.getCreationDate().getTime(), li.getOwner());
lres = new LockResultImpl(true, le);
} else {
// already locked by a user.
// if that user is us, we can reacquire it
LockEntry le = new LockEntry(li.getAsset(), li.getCreationDate().getTime(), li.getOwner());
if (requestor.getName().equals(li.getOwner().getName())) {
// that's us -> success (asset, owner is the same, and we leave creationdate to when the lock was originally acquired, not when it was reacquired.
lres = new LockResultImpl(true, le);
} else {
lres = new LockResultImpl(false, le);
}
}
return lres;
}
});
return res;
}
use of org.olat.core.util.coordinate.LockResultImpl in project openolat by klemens.
the class ClusterLocker method acquireLock.
@Override
public LockResult acquireLock(final OLATResourceable ores, final Identity requestor, final String locksubkey) {
final String asset = OresHelper.createStringRepresenting(ores, locksubkey);
LockResult res = syncer.doInSync(ores, new SyncerCallback<LockResult>() {
@Override
public LockResult execute() {
LockResultImpl lres;
LockImpl li = clusterLockManager.findLock(asset);
if (li == null) {
// fine, we can lock it
li = clusterLockManager.createLockImpl(asset, requestor);
clusterLockManager.saveLock(li);
LockEntry le = new LockEntry(li.getAsset(), li.getCreationDate().getTime(), li.getOwner());
lres = new LockResultImpl(true, le);
} else {
// already locked by a user.
// if that user is us, we can reacquire it
LockEntry le = new LockEntry(li.getAsset(), li.getCreationDate().getTime(), li.getOwner());
if (requestor.getName().equals(li.getOwner().getName())) {
// that's us -> success (asset, owner is the same, and we leave creationdate to when the lock was originally acquired, not when it was reacquired.
lres = new LockResultImpl(true, le);
} else {
lres = new LockResultImpl(false, le);
}
}
return lres;
}
});
return res;
}
Aggregations