|
|
|
@ -25,6 +25,7 @@ import java.util.HashSet;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import org.apache.catalina.session.StandardSession;
|
|
|
|
@ -59,6 +60,8 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
private final RedissonSessionManager.ReadMode readMode;
|
|
|
|
|
private final UpdateMode updateMode;
|
|
|
|
|
|
|
|
|
|
private Set<String> removedAttributes;
|
|
|
|
|
|
|
|
|
|
public RedissonSession(RedissonSessionManager manager, RedissonSessionManager.ReadMode readMode, UpdateMode updateMode) {
|
|
|
|
|
super(manager);
|
|
|
|
|
this.redissonManager = manager;
|
|
|
|
@ -66,6 +69,10 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
this.updateMode = updateMode;
|
|
|
|
|
this.topic = redissonManager.getTopic();
|
|
|
|
|
|
|
|
|
|
if (updateMode == UpdateMode.AFTER_REQUEST) {
|
|
|
|
|
removedAttributes = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Field attr = StandardSession.class.getDeclaredField("attributes");
|
|
|
|
|
attrs = (Map<String, Object>) attr.get(this);
|
|
|
|
@ -257,6 +264,9 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
if (updateMode == UpdateMode.DEFAULT && map != null && value != null) {
|
|
|
|
|
fastPut(name, value);
|
|
|
|
|
}
|
|
|
|
|
if (updateMode == UpdateMode.AFTER_REQUEST) {
|
|
|
|
|
removedAttributes.remove(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void superRemoveAttributeInternal(String name, boolean notify) {
|
|
|
|
@ -270,9 +280,12 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
if (updateMode == UpdateMode.DEFAULT && map != null) {
|
|
|
|
|
map.fastRemove(name);
|
|
|
|
|
if (readMode == ReadMode.MEMORY) {
|
|
|
|
|
topic.publish(new AttributeRemoveMessage(redissonManager.getNodeId(), getId(), name));
|
|
|
|
|
topic.publish(new AttributeRemoveMessage(redissonManager.getNodeId(), getId(), new HashSet<String>(Arrays.asList(name))));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (updateMode == UpdateMode.AFTER_REQUEST) {
|
|
|
|
|
removedAttributes.add(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
@ -295,9 +308,18 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
map.putAll(newMap);
|
|
|
|
|
map.fastRemove(removedAttributes.toArray(new String[removedAttributes.size()]));
|
|
|
|
|
|
|
|
|
|
if (readMode == ReadMode.MEMORY) {
|
|
|
|
|
topic.publish(createPutAllMessage(newMap));
|
|
|
|
|
|
|
|
|
|
if (updateMode == UpdateMode.AFTER_REQUEST) {
|
|
|
|
|
if (!removedAttributes.isEmpty()) {
|
|
|
|
|
topic.publish(new AttributeRemoveMessage(redissonManager.getNodeId(), getId(), removedAttributes));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
removedAttributes.clear();
|
|
|
|
|
|
|
|
|
|
expireSession();
|
|
|
|
|
}
|
|
|
|
|