use of org.openforis.collect.model.RecordLock in project collect by openforis.
the class RecordLockManager method checkIsLocked.
public synchronized boolean checkIsLocked(int recordId, User user, String sessionId) throws RecordUnlockedException {
RecordLock lock = getLock(recordId);
String lockUserName = null;
if (lock != null) {
String lockSessionId = lock.getSessionId();
int lockRecordId = lock.getRecordId();
User lUser = lock.getUser();
if (recordId == lockRecordId && (lUser == user || lUser.getId().equals(user.getId())) && lockSessionId.equals(sessionId)) {
lock.keepAlive();
return true;
} else {
User lockUser = lock.getUser();
lockUserName = lockUser.getUsername();
}
}
throw new RecordUnlockedException(lockUserName);
}
use of org.openforis.collect.model.RecordLock in project collect by openforis.
the class RecordLockManager method clearInactiveLocks.
private synchronized void clearInactiveLocks() {
Set<Entry<Integer, RecordLock>> entrySet = locks.entrySet();
Iterator<Entry<Integer, RecordLock>> iterator = entrySet.iterator();
while (iterator.hasNext()) {
Entry<Integer, RecordLock> entry = iterator.next();
RecordLock lock = entry.getValue();
if (!lock.isActive()) {
iterator.remove();
}
}
}
Aggregations