Fix more lock issues.

This commit is contained in:
Paulo Gustavo Veiga 2012-11-13 21:01:04 -03:00
parent 71762ff629
commit b1172f16cc
6 changed files with 23 additions and 19 deletions

View File

@ -43,8 +43,8 @@ mindplot.RESTPersistenceManager = new Class({
var persistence = this;
var query = "minor=" + !saveHistory;
query = query + (this.timestamp ? "&timestamp=" + this.timestamp : "");
query = query + (this.session ? "&session=" + this.session : "");
query = query + "&timestamp=" + this.timestamp;
query = query + "&session=" + this.session;
if (!persistence.onSave) {

View File

@ -169,7 +169,7 @@ public class MindmapController extends BaseController {
// Update edition timeout ...
final LockManager lockManager = mindmapService.getLockManager();
final LockInfo lockInfo = lockManager.updateExpirationTimeout(mindmap, user, session);
final LockInfo lockInfo = lockManager.updateExpirationTimeout(mindmap, user);
return lockInfo.getTimestamp();
}
@ -192,11 +192,10 @@ public class MindmapController extends BaseController {
throw new SessionExpiredException(lastEditor);
}
} else if (outdated) {
throw new MultipleSessionsOpenException("Sessions:" + session + ":" + lockInfo.getSession() + "Timestamp: " + timestamp + ": " + lockInfo.getTimestamp());
throw new MultipleSessionsOpenException("Sessions:" + session + ":" + lockInfo.getSession() + ",Timestamp: " + timestamp + ": " + lockInfo.getTimestamp());
}
} else {
throw new SessionExpiredException(lockInfo.getUser());
}
}

View File

@ -36,6 +36,7 @@ public class LockInfo {
this.user = user;
this.updateTimeout();
this.updateTimestamp(mindmap);
this.session = session;
}
public User getUser() {

View File

@ -30,13 +30,15 @@ public interface LockManager {
LockInfo getLockInfo(@NotNull Mindmap mindmap);
LockInfo updateExpirationTimeout(@NotNull Mindmap mindmap, @NotNull User user,long session);
LockInfo updateExpirationTimeout(@NotNull Mindmap mindmap, @NotNull User user);
void unlock(@NotNull Mindmap mindmap, @NotNull User user) throws LockException, AccessDeniedSecurityException;
boolean isLockedBy(@NotNull Mindmap mindmap, @NotNull User collaborator);
@NotNull
LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user, long session) throws WiseMappingException;
long generateSession();
@NotNull
LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user) throws WiseMappingException;
}

View File

@ -63,7 +63,7 @@ class LockManagerImpl implements LockManager {
}
@Override
public LockInfo updateExpirationTimeout(@NotNull Mindmap mindmap, @NotNull User user, long session) {
public LockInfo updateExpirationTimeout(@NotNull Mindmap mindmap, @NotNull User user) {
if (!this.isLocked(mindmap)) {
throw new IllegalStateException("Lock lost for map. No update possible.");
}
@ -74,9 +74,8 @@ class LockManagerImpl implements LockManager {
}
result.updateTimeout();
result.setSession(session);
result.updateTimestamp(mindmap);
// logger.debug("Timeout updated for:" + mindmap.getId());
logger.debug("Timeout updated for:" + mindmap.getId());
return result;
}
@ -108,6 +107,13 @@ class LockManagerImpl implements LockManager {
return result;
}
@Override
@NotNull
public LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user) throws WiseMappingException {
return this.lock(mindmap, user, System.nanoTime());
}
@Override
@NotNull
public LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user, long session) throws WiseMappingException {
@ -123,7 +129,8 @@ class LockManagerImpl implements LockManager {
if (result != null) {
// Update timeout only...
logger.debug("Update timestamp:" + mindmap.getId());
updateExpirationTimeout(mindmap, user, session);
updateExpirationTimeout(mindmap, user);
result.setSession(session);
} else {
logger.debug("Lock map id:" + mindmap.getId());
result = new LockInfo(user, mindmap, session);
@ -132,11 +139,6 @@ class LockManagerImpl implements LockManager {
return result;
}
@Override
public long generateSession() {
return System.nanoTime();
}
public LockManagerImpl() {
lockInfoByMapId = new ConcurrentHashMap<Integer, LockInfo>();
expirationTimer.schedule(new TimerTask() {

View File

@ -46,6 +46,7 @@ import java.util.Locale;
public class MindmapController {
public static final String LOCK_SESSION_ATTRIBUTE = "lockSession";
@Qualifier("mindmapService")
@Autowired
private MindmapService mindmapService;
@ -160,10 +161,9 @@ public class MindmapController {
readOnlyMode = true;
model.addAttribute("mindmapLocked",true);
} else {
final long session = lockManager.generateSession();
final LockInfo lock = lockManager.lock(mindmap, collaborator, session);
final LockInfo lock = lockManager.lock(mindmap, collaborator);
model.addAttribute("lockTimestamp", lock.getTimestamp());
model.addAttribute("lockSession", session);
model.addAttribute(LOCK_SESSION_ATTRIBUTE, lock.getSession());
}
model.addAttribute("lockInfo", lockManager.getLockInfo(mindmap));
}