|
|
|
@ -51,7 +51,7 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
private final RedissonSessionManager redissonManager;
|
|
|
|
|
private final Map<String, Object> attrs;
|
|
|
|
|
private RMap<String, Object> map;
|
|
|
|
|
private RTopic topic;
|
|
|
|
|
private final RTopic topic;
|
|
|
|
|
private final RedissonSessionManager.ReadMode readMode;
|
|
|
|
|
private final UpdateMode updateMode;
|
|
|
|
|
|
|
|
|
@ -60,6 +60,7 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
this.redissonManager = manager;
|
|
|
|
|
this.readMode = readMode;
|
|
|
|
|
this.updateMode = updateMode;
|
|
|
|
|
this.topic = redissonManager.getTopic();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Field attr = StandardSession.class.getDeclaredField("attributes");
|
|
|
|
@ -80,13 +81,6 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
return super.getAttribute(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setId(String id, boolean notify) {
|
|
|
|
|
super.setId(id, notify);
|
|
|
|
|
map = redissonManager.getMap(id);
|
|
|
|
|
topic = redissonManager.getTopic();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void delete() {
|
|
|
|
|
map.delete();
|
|
|
|
|
if (readMode == ReadMode.MEMORY) {
|
|
|
|
@ -123,12 +117,16 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
if (readMode == ReadMode.MEMORY) {
|
|
|
|
|
topic.publish(createPutAllMessage(newMap));
|
|
|
|
|
}
|
|
|
|
|
if (getMaxInactiveInterval() >= 0) {
|
|
|
|
|
map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
expireSession();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void expireSession() {
|
|
|
|
|
if (maxInactiveInterval >= 0) {
|
|
|
|
|
map.expire(maxInactiveInterval + 60, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected AttributesPutAllMessage createPutAllMessage(Map<String, Object> newMap) {
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
for (Entry<String, Object> entry : newMap.entrySet()) {
|
|
|
|
@ -143,9 +141,7 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
|
|
|
|
|
if (map != null) {
|
|
|
|
|
fastPut(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval);
|
|
|
|
|
if (maxInactiveInterval >= 0) {
|
|
|
|
|
map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
expireSession();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -183,7 +179,7 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
boolean oldValue = isNew;
|
|
|
|
|
super.endAccess();
|
|
|
|
|
|
|
|
|
|
if (isNew != oldValue) {
|
|
|
|
|
if (isNew != oldValue && map != null) {
|
|
|
|
|
fastPut(IS_NEW_ATTR, isNew);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -218,6 +214,10 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
|
if (map == null) {
|
|
|
|
|
map = redissonManager.getMap(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, Object> newMap = new HashMap<String, Object>();
|
|
|
|
|
newMap.put(CREATION_TIME_ATTR, creationTime);
|
|
|
|
|
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
|
|
|
|
@ -236,10 +236,7 @@ public class RedissonSession extends StandardSession {
|
|
|
|
|
if (readMode == ReadMode.MEMORY) {
|
|
|
|
|
topic.publish(createPutAllMessage(newMap));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (maxInactiveInterval >= 0) {
|
|
|
|
|
map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
expireSession();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void load(Map<String, Object> attrs) {
|
|
|
|
|