mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 22:27:55 +01:00
Fix more lock issues.
This commit is contained in:
parent
71762ff629
commit
b1172f16cc
@ -43,8 +43,8 @@ mindplot.RESTPersistenceManager = new Class({
|
|||||||
|
|
||||||
var persistence = this;
|
var persistence = this;
|
||||||
var query = "minor=" + !saveHistory;
|
var query = "minor=" + !saveHistory;
|
||||||
query = query + (this.timestamp ? "×tamp=" + this.timestamp : "");
|
query = query + "×tamp=" + this.timestamp;
|
||||||
query = query + (this.session ? "&session=" + this.session : "");
|
query = query + "&session=" + this.session;
|
||||||
|
|
||||||
if (!persistence.onSave) {
|
if (!persistence.onSave) {
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ public class MindmapController extends BaseController {
|
|||||||
|
|
||||||
// Update edition timeout ...
|
// Update edition timeout ...
|
||||||
final LockManager lockManager = mindmapService.getLockManager();
|
final LockManager lockManager = mindmapService.getLockManager();
|
||||||
final LockInfo lockInfo = lockManager.updateExpirationTimeout(mindmap, user, session);
|
final LockInfo lockInfo = lockManager.updateExpirationTimeout(mindmap, user);
|
||||||
return lockInfo.getTimestamp();
|
return lockInfo.getTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,11 +192,10 @@ public class MindmapController extends BaseController {
|
|||||||
throw new SessionExpiredException(lastEditor);
|
throw new SessionExpiredException(lastEditor);
|
||||||
}
|
}
|
||||||
} else if (outdated) {
|
} 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 {
|
} else {
|
||||||
throw new SessionExpiredException(lockInfo.getUser());
|
throw new SessionExpiredException(lockInfo.getUser());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ public class LockInfo {
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
this.updateTimeout();
|
this.updateTimeout();
|
||||||
this.updateTimestamp(mindmap);
|
this.updateTimestamp(mindmap);
|
||||||
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser() {
|
public User getUser() {
|
||||||
|
@ -30,13 +30,15 @@ public interface LockManager {
|
|||||||
|
|
||||||
LockInfo getLockInfo(@NotNull Mindmap mindmap);
|
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;
|
void unlock(@NotNull Mindmap mindmap, @NotNull User user) throws LockException, AccessDeniedSecurityException;
|
||||||
|
|
||||||
boolean isLockedBy(@NotNull Mindmap mindmap, @NotNull User collaborator);
|
boolean isLockedBy(@NotNull Mindmap mindmap, @NotNull User collaborator);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user, long session) throws WiseMappingException;
|
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;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ class LockManagerImpl implements LockManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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)) {
|
if (!this.isLocked(mindmap)) {
|
||||||
throw new IllegalStateException("Lock lost for map. No update possible.");
|
throw new IllegalStateException("Lock lost for map. No update possible.");
|
||||||
}
|
}
|
||||||
@ -74,9 +74,8 @@ class LockManagerImpl implements LockManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result.updateTimeout();
|
result.updateTimeout();
|
||||||
result.setSession(session);
|
|
||||||
result.updateTimestamp(mindmap);
|
result.updateTimestamp(mindmap);
|
||||||
// logger.debug("Timeout updated for:" + mindmap.getId());
|
logger.debug("Timeout updated for:" + mindmap.getId());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +107,13 @@ class LockManagerImpl implements LockManager {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user) throws WiseMappingException {
|
||||||
|
return this.lock(mindmap, user, System.nanoTime());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user, long session) throws WiseMappingException {
|
public LockInfo lock(@NotNull Mindmap mindmap, @NotNull User user, long session) throws WiseMappingException {
|
||||||
@ -123,7 +129,8 @@ class LockManagerImpl implements LockManager {
|
|||||||
if (result != null) {
|
if (result != null) {
|
||||||
// Update timeout only...
|
// Update timeout only...
|
||||||
logger.debug("Update timestamp:" + mindmap.getId());
|
logger.debug("Update timestamp:" + mindmap.getId());
|
||||||
updateExpirationTimeout(mindmap, user, session);
|
updateExpirationTimeout(mindmap, user);
|
||||||
|
result.setSession(session);
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Lock map id:" + mindmap.getId());
|
logger.debug("Lock map id:" + mindmap.getId());
|
||||||
result = new LockInfo(user, mindmap, session);
|
result = new LockInfo(user, mindmap, session);
|
||||||
@ -132,11 +139,6 @@ class LockManagerImpl implements LockManager {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long generateSession() {
|
|
||||||
return System.nanoTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LockManagerImpl() {
|
public LockManagerImpl() {
|
||||||
lockInfoByMapId = new ConcurrentHashMap<Integer, LockInfo>();
|
lockInfoByMapId = new ConcurrentHashMap<Integer, LockInfo>();
|
||||||
expirationTimer.schedule(new TimerTask() {
|
expirationTimer.schedule(new TimerTask() {
|
||||||
|
@ -46,6 +46,7 @@ import java.util.Locale;
|
|||||||
public class MindmapController {
|
public class MindmapController {
|
||||||
|
|
||||||
|
|
||||||
|
public static final String LOCK_SESSION_ATTRIBUTE = "lockSession";
|
||||||
@Qualifier("mindmapService")
|
@Qualifier("mindmapService")
|
||||||
@Autowired
|
@Autowired
|
||||||
private MindmapService mindmapService;
|
private MindmapService mindmapService;
|
||||||
@ -160,10 +161,9 @@ public class MindmapController {
|
|||||||
readOnlyMode = true;
|
readOnlyMode = true;
|
||||||
model.addAttribute("mindmapLocked",true);
|
model.addAttribute("mindmapLocked",true);
|
||||||
} else {
|
} else {
|
||||||
final long session = lockManager.generateSession();
|
final LockInfo lock = lockManager.lock(mindmap, collaborator);
|
||||||
final LockInfo lock = lockManager.lock(mindmap, collaborator, session);
|
|
||||||
model.addAttribute("lockTimestamp", lock.getTimestamp());
|
model.addAttribute("lockTimestamp", lock.getTimestamp());
|
||||||
model.addAttribute("lockSession", session);
|
model.addAttribute(LOCK_SESSION_ATTRIBUTE, lock.getSession());
|
||||||
}
|
}
|
||||||
model.addAttribute("lockInfo", lockManager.getLockInfo(mindmap));
|
model.addAttribute("lockInfo", lockManager.getLockInfo(mindmap));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user