final String asset = OresHelper.createStringRepresenting(ores, locksubkey);
LockResult res = syncer.doInSync(ores, new SyncerCallback<LockResult>(){
public LockResult execute() {
ClusterLockManager cm = ClusterLockManager.getInstance();
LockResultImpl lres;
LockImpl li = cm.findLock(asset);
if (li == null) { // fine, we can lock it
li = cm.createLockImpl(asset, requestor);
cm.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;
}});