mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 06:07:57 +01:00
Improve lock code.
This commit is contained in:
parent
a9d091a187
commit
92dd4a7014
@ -7,6 +7,7 @@ import com.wisemapping.model.User;
|
|||||||
import com.wisemapping.security.Utils;
|
import com.wisemapping.security.Utils;
|
||||||
import com.wisemapping.service.LockManager;
|
import com.wisemapping.service.LockManager;
|
||||||
import com.wisemapping.service.MindmapService;
|
import com.wisemapping.service.MindmapService;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||||
@ -16,6 +17,7 @@ import javax.servlet.http.HttpSessionEvent;
|
|||||||
import javax.servlet.http.HttpSessionListener;
|
import javax.servlet.http.HttpSessionListener;
|
||||||
|
|
||||||
public class UnlockOnExpireListener implements HttpSessionListener {
|
public class UnlockOnExpireListener implements HttpSessionListener {
|
||||||
|
private static final Logger logger = Logger.getLogger(UnlockOnExpireListener.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sessionCreated(@NotNull HttpSessionEvent event) {
|
public void sessionCreated(@NotNull HttpSessionEvent event) {
|
||||||
@ -34,10 +36,8 @@ public class UnlockOnExpireListener implements HttpSessionListener {
|
|||||||
if (user != null) {
|
if (user != null) {
|
||||||
try {
|
try {
|
||||||
lockManager.unlockAll(user);
|
lockManager.unlockAll(user);
|
||||||
} catch (LockException e) {
|
} catch (LockException | AccessDeniedSecurityException e) {
|
||||||
e.printStackTrace();
|
logger.error(e);
|
||||||
} catch (AccessDeniedSecurityException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
* - Y grabo con la misma sessions y el timestap ok.
|
* - Y grabo con la misma sessions y el timestap ok.
|
||||||
* - Y grabo con la misma session y el timestap esta mal
|
* - Y grabo con la misma session y el timestap esta mal
|
||||||
* - Y grabo con distinta sessions
|
* - Y grabo con distinta sessions
|
||||||
* -
|
|
||||||
* - Usuario pierde el lock, pero intenta grabar camio
|
* - Usuario pierde el lock, pero intenta grabar camio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -150,25 +149,20 @@ class LockManagerImpl implements LockManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public LockManagerImpl() {
|
public LockManagerImpl() {
|
||||||
lockInfoByMapId = new ConcurrentHashMap<Integer, LockInfo>();
|
lockInfoByMapId = new ConcurrentHashMap<>();
|
||||||
expirationTimer.schedule(new TimerTask() {
|
expirationTimer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
logger.debug("Lock expiration scheduler started. Current locks:" + lockInfoByMapId.keySet());
|
logger.debug("Lock expiration scheduler started. Current locks:" + lockInfoByMapId.keySet());
|
||||||
|
|
||||||
final List<Integer> toRemove = new ArrayList<Integer>();
|
// Search for expired sessions and remove them ....
|
||||||
final Set<Integer> mapIds = lockInfoByMapId.keySet();
|
lockInfoByMapId.
|
||||||
for (Integer mapId : mapIds) {
|
keySet().
|
||||||
final LockInfo lockInfo = lockInfoByMapId.get(mapId);
|
stream().
|
||||||
if (lockInfo.isExpired()) {
|
filter(mapId -> lockInfoByMapId.get(mapId).isExpired()).
|
||||||
toRemove.add(mapId);
|
forEach(mapId -> unlock(mapId));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Integer mapId : toRemove) {
|
|
||||||
unlock(mapId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, ONE_MINUTE_MILLISECONDS, ONE_MINUTE_MILLISECONDS);
|
}, ONE_MINUTE_MILLISECONDS, ONE_MINUTE_MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user