Search in sources :

Example 6 with LockEntry

use of org.olat.core.util.coordinate.LockEntry in project openolat by klemens.

the class ClusterLocker method adminOnlyGetLockEntries.

public List<LockEntry> adminOnlyGetLockEntries() {
    List<LockImpl> li = clusterLockManager.getAllLocks();
    List<LockEntry> res = new ArrayList<LockEntry>(li.size());
    for (LockImpl impl : li) {
        res.add(new LockEntry(impl.getAsset(), impl.getCreationDate().getTime(), impl.getOwner()));
    }
    return res;
}
Also used : LockEntry(org.olat.core.util.coordinate.LockEntry) ArrayList(java.util.ArrayList)

Example 7 with LockEntry

use of org.olat.core.util.coordinate.LockEntry in project OpenOLAT by OpenOLAT.

the class ClusterLocker method adminOnlyGetLockEntries.

public List<LockEntry> adminOnlyGetLockEntries() {
    List<LockImpl> li = clusterLockManager.getAllLocks();
    List<LockEntry> res = new ArrayList<LockEntry>(li.size());
    for (LockImpl impl : li) {
        res.add(new LockEntry(impl.getAsset(), impl.getCreationDate().getTime(), impl.getOwner()));
    }
    return res;
}
Also used : LockEntry(org.olat.core.util.coordinate.LockEntry) ArrayList(java.util.ArrayList)

Example 8 with LockEntry

use of org.olat.core.util.coordinate.LockEntry 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)8 ArrayList (java.util.ArrayList)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 LockResult (org.olat.core.util.coordinate.LockResult)4 Test (org.junit.Test)2 TableEvent (org.olat.core.gui.components.table.TableEvent)2 Identity (org.olat.core.id.Identity)2 LockRemovedEvent (org.olat.core.util.coordinate.LockRemovedEvent)2 LockResultImpl (org.olat.core.util.coordinate.LockResultImpl)2 Locker (org.olat.core.util.coordinate.Locker)2 MultiUserEvent (org.olat.core.util.event.MultiUserEvent)2