Search in sources :

Example 1 with LockResultImpl

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;
}
Also used : LockResultImpl(org.olat.core.util.coordinate.LockResultImpl) LockResult(org.olat.core.util.coordinate.LockResult) LockEntry(org.olat.core.util.coordinate.LockEntry)

Example 2 with LockResultImpl

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;
}
Also used : LockResultImpl(org.olat.core.util.coordinate.LockResultImpl) LockResult(org.olat.core.util.coordinate.LockResult) LockEntry(org.olat.core.util.coordinate.LockEntry)

Aggregations

LockEntry (org.olat.core.util.coordinate.LockEntry)2 LockResult (org.olat.core.util.coordinate.LockResult)2 LockResultImpl (org.olat.core.util.coordinate.LockResultImpl)2