refactoring

pull/1821/head
Nikita 7 years ago
parent 24146f776b
commit c6269509c7

@ -16,9 +16,12 @@
package org.redisson.tomcat; package org.redisson.tomcat;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.catalina.session.StandardSession; import org.apache.catalina.session.StandardSession;
@ -35,6 +38,16 @@ import org.redisson.tomcat.RedissonSessionManager.UpdateMode;
*/ */
public class RedissonSession extends StandardSession { public class RedissonSession extends StandardSession {
private static final String IS_NEW_ATTR = "session:isNew";
private static final String IS_VALID_ATTR = "session:isValid";
private static final String THIS_ACCESSED_TIME_ATTR = "session:thisAccessedTime";
private static final String MAX_INACTIVE_INTERVAL_ATTR = "session:maxInactiveInterval";
private static final String LAST_ACCESSED_TIME_ATTR = "session:lastAccessedTime";
private static final String CREATION_TIME_ATTR = "session:creationTime";
public static final Set<String> ATTRS = new HashSet<String>(Arrays.asList(IS_NEW_ATTR, IS_VALID_ATTR,
THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR));
private final RedissonSessionManager redissonManager; private final RedissonSessionManager redissonManager;
private final Map<String, Object> attrs; private final Map<String, Object> attrs;
private RMap<String, Object> map; private RMap<String, Object> map;
@ -88,9 +101,9 @@ public class RedissonSession extends StandardSession {
if (map != null) { if (map != null) {
Map<String, Object> newMap = new HashMap<String, Object>(3); Map<String, Object> newMap = new HashMap<String, Object>(3);
newMap.put("session:creationTime", creationTime); newMap.put(CREATION_TIME_ATTR, creationTime);
newMap.put("session:lastAccessedTime", lastAccessedTime); newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put("session:thisAccessedTime", thisAccessedTime); newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap); map.putAll(newMap);
if (readMode == ReadMode.MEMORY) { if (readMode == ReadMode.MEMORY) {
topic.publish(createPutAllMessage(newMap)); topic.publish(createPutAllMessage(newMap));
@ -104,8 +117,8 @@ public class RedissonSession extends StandardSession {
if (map != null) { if (map != null) {
Map<String, Object> newMap = new HashMap<String, Object>(2); Map<String, Object> newMap = new HashMap<String, Object>(2);
newMap.put("session:lastAccessedTime", lastAccessedTime); newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put("session:thisAccessedTime", thisAccessedTime); newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap); map.putAll(newMap);
if (readMode == ReadMode.MEMORY) { if (readMode == ReadMode.MEMORY) {
topic.publish(createPutAllMessage(newMap)); topic.publish(createPutAllMessage(newMap));
@ -115,7 +128,7 @@ public class RedissonSession extends StandardSession {
} }
} }
} }
protected AttributesPutAllMessage createPutAllMessage(Map<String, Object> newMap) { protected AttributesPutAllMessage createPutAllMessage(Map<String, Object> newMap) {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
for (Entry<String, Object> entry : newMap.entrySet()) { for (Entry<String, Object> entry : newMap.entrySet()) {
@ -129,13 +142,13 @@ public class RedissonSession extends StandardSession {
super.setMaxInactiveInterval(interval); super.setMaxInactiveInterval(interval);
if (map != null) { if (map != null) {
fastPut("session:maxInactiveInterval", maxInactiveInterval); fastPut(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval);
if (maxInactiveInterval >= 0) { if (maxInactiveInterval >= 0) {
map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS); map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS);
} }
} }
} }
private void fastPut(String name, Object value) { private void fastPut(String name, Object value) {
map.fastPut(name, value); map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) { if (readMode == ReadMode.MEMORY) {
@ -151,8 +164,8 @@ public class RedissonSession extends StandardSession {
if (!isValid && !map.isExists()) { if (!isValid && !map.isExists()) {
return; return;
} }
fastPut("session:isValid", isValid); fastPut(IS_VALID_ATTR, isValid);
} }
} }
@ -161,7 +174,7 @@ public class RedissonSession extends StandardSession {
super.setNew(isNew); super.setNew(isNew);
if (map != null) { if (map != null) {
fastPut("session:isNew", isNew); fastPut(IS_NEW_ATTR, isNew);
} }
} }
@ -171,7 +184,7 @@ public class RedissonSession extends StandardSession {
super.endAccess(); super.endAccess();
if (isNew != oldValue) { if (isNew != oldValue) {
fastPut("session:isNew", isNew); fastPut(IS_NEW_ATTR, isNew);
} }
} }
@ -206,12 +219,12 @@ public class RedissonSession extends StandardSession {
public void save() { public void save() {
Map<String, Object> newMap = new HashMap<String, Object>(); Map<String, Object> newMap = new HashMap<String, Object>();
newMap.put("session:creationTime", creationTime); newMap.put(CREATION_TIME_ATTR, creationTime);
newMap.put("session:lastAccessedTime", lastAccessedTime); newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put("session:thisAccessedTime", thisAccessedTime); newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
newMap.put("session:maxInactiveInterval", maxInactiveInterval); newMap.put(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval);
newMap.put("session:isValid", isValid); newMap.put(IS_VALID_ATTR, isValid);
newMap.put("session:isNew", isNew); newMap.put(IS_NEW_ATTR, isNew);
if (attrs != null) { if (attrs != null) {
for (Entry<String, Object> entry : attrs.entrySet()) { for (Entry<String, Object> entry : attrs.entrySet()) {
@ -230,27 +243,27 @@ public class RedissonSession extends StandardSession {
} }
public void load(Map<String, Object> attrs) { public void load(Map<String, Object> attrs) {
Long creationTime = (Long) attrs.remove("session:creationTime"); Long creationTime = (Long) attrs.remove(CREATION_TIME_ATTR);
if (creationTime != null) { if (creationTime != null) {
this.creationTime = creationTime; this.creationTime = creationTime;
} }
Long lastAccessedTime = (Long) attrs.remove("session:lastAccessedTime"); Long lastAccessedTime = (Long) attrs.remove(LAST_ACCESSED_TIME_ATTR);
if (lastAccessedTime != null) { if (lastAccessedTime != null) {
this.lastAccessedTime = lastAccessedTime; this.lastAccessedTime = lastAccessedTime;
} }
Integer maxInactiveInterval = (Integer) attrs.remove("session:maxInactiveInterval"); Integer maxInactiveInterval = (Integer) attrs.remove(MAX_INACTIVE_INTERVAL_ATTR);
if (maxInactiveInterval != null) { if (maxInactiveInterval != null) {
this.maxInactiveInterval = maxInactiveInterval; this.maxInactiveInterval = maxInactiveInterval;
} }
Long thisAccessedTime = (Long) attrs.remove("session:thisAccessedTime"); Long thisAccessedTime = (Long) attrs.remove(THIS_ACCESSED_TIME_ATTR);
if (thisAccessedTime != null) { if (thisAccessedTime != null) {
this.thisAccessedTime = thisAccessedTime; this.thisAccessedTime = thisAccessedTime;
} }
Boolean isValid = (Boolean) attrs.remove("session:isValid"); Boolean isValid = (Boolean) attrs.remove(IS_VALID_ATTR);
if (isValid != null) { if (isValid != null) {
this.isValid = isValid; this.isValid = isValid;
} }
Boolean isNew = (Boolean) attrs.remove("session:isNew"); Boolean isNew = (Boolean) attrs.remove(IS_NEW_ATTR);
if (isNew != null) { if (isNew != null) {
this.isNew = isNew; this.isNew = isNew;
} }

@ -17,6 +17,7 @@ package org.redisson.tomcat;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -51,7 +52,7 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
public enum UpdateMode {DEFAULT, AFTER_REQUEST} public enum UpdateMode {DEFAULT, AFTER_REQUEST}
private final Log log = LogFactory.getLog(RedissonSessionManager.class); private final Log log = LogFactory.getLog(RedissonSessionManager.class);
protected LifecycleSupport lifecycle = new LifecycleSupport(this); protected LifecycleSupport lifecycle = new LifecycleSupport(this);
private RedissonClient redisson; private RedissonClient redisson;
@ -59,7 +60,7 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
private ReadMode readMode = ReadMode.MEMORY; private ReadMode readMode = ReadMode.MEMORY;
private UpdateMode updateMode = UpdateMode.DEFAULT; private UpdateMode updateMode = UpdateMode.DEFAULT;
private String keyPrefix = ""; private String keyPrefix = "";
public String getUpdateMode() { public String getUpdateMode() {
return updateMode.toString(); return updateMode.toString();
} }
@ -75,7 +76,7 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
public void setReadMode(String readMode) { public void setReadMode(String readMode) {
this.readMode = ReadMode.valueOf(readMode); this.readMode = ReadMode.valueOf(readMode);
} }
public void setConfigPath(String configPath) { public void setConfigPath(String configPath) {
this.configPath = configPath; this.configPath = configPath;
} }
@ -96,7 +97,7 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
public int getRejectedSessions() { public int getRejectedSessions() {
return 0; return 0;
} }
@Override @Override
public void load() throws ClassNotFoundException, IOException { public void load() throws ClassNotFoundException, IOException {
} }
@ -149,7 +150,7 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
final String name = keyPrefix + separator + "redisson:tomcat_session:" + sessionId; final String name = keyPrefix + separator + "redisson:tomcat_session:" + sessionId;
return redisson.getMap(name); return redisson.getMap(name);
} }
public RTopic<AttributeMessage> getTopic() { public RTopic<AttributeMessage> getTopic() {
return redisson.getTopic("redisson:tomcat_session_updates:" + container.getName()); return redisson.getTopic("redisson:tomcat_session_updates:" + container.getName());
} }
@ -157,22 +158,30 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
@Override @Override
public Session findSession(String id) throws IOException { public Session findSession(String id) throws IOException {
Session result = super.findSession(id); Session result = super.findSession(id);
if (result == null && id != null) { if (result == null) {
Map<String, Object> attrs = getMap(id).readAllMap(); if (id != null) {
Map<String, Object> attrs;
if (attrs.isEmpty() || !Boolean.valueOf(String.valueOf(attrs.get("session:isValid")))) { if (readMode == ReadMode.MEMORY) {
log.info("Session " + id + " can't be found"); attrs = getMap(id).readAllMap();
return null; } else {
attrs = getMap(id).getAll(RedissonSession.ATTRS);
}
if (attrs.isEmpty() || !Boolean.valueOf(String.valueOf(attrs.get("session:isValid")))) {
log.info("Session " + id + " can't be found");
return null;
}
RedissonSession session = (RedissonSession) createEmptySession();
session.setId(id);
session.setManager(this);
session.load(attrs);
session.access();
session.endAccess();
return session;
} }
return null;
RedissonSession session = (RedissonSession) createEmptySession();
session.setId(id);
session.setManager(this);
session.load(attrs);
session.access();
session.endAccess();
return session;
} }
result.access(); result.access();
@ -246,7 +255,7 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
lifecycle.fireLifecycleEvent(START_EVENT, null); lifecycle.fireLifecycleEvent(START_EVENT, null);
} }
protected RedissonClient buildClient() throws LifecycleException { protected RedissonClient buildClient() throws LifecycleException {
Config config = null; Config config = null;
try { try {
@ -260,7 +269,7 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
throw new LifecycleException("Can't parse yaml config " + configPath, e1); throw new LifecycleException("Can't parse yaml config " + configPath, e1);
} }
} }
try { try {
try { try {
Config c = new Config(config); Config c = new Config(config);
@ -289,7 +298,7 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
lifecycle.fireLifecycleEvent(STOP_EVENT, null); lifecycle.fireLifecycleEvent(STOP_EVENT, null);
} }
public void store(HttpSession session) throws IOException { public void store(HttpSession session) throws IOException {
if (session == null) { if (session == null) {
return; return;
@ -302,5 +311,5 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
} }
} }
} }
} }

@ -16,9 +16,12 @@
package org.redisson.tomcat; package org.redisson.tomcat;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.catalina.session.StandardSession; import org.apache.catalina.session.StandardSession;
@ -35,6 +38,16 @@ import org.redisson.tomcat.RedissonSessionManager.UpdateMode;
*/ */
public class RedissonSession extends StandardSession { public class RedissonSession extends StandardSession {
private static final String IS_NEW_ATTR = "session:isNew";
private static final String IS_VALID_ATTR = "session:isValid";
private static final String THIS_ACCESSED_TIME_ATTR = "session:thisAccessedTime";
private static final String MAX_INACTIVE_INTERVAL_ATTR = "session:maxInactiveInterval";
private static final String LAST_ACCESSED_TIME_ATTR = "session:lastAccessedTime";
private static final String CREATION_TIME_ATTR = "session:creationTime";
public static final Set<String> ATTRS = new HashSet<String>(Arrays.asList(IS_NEW_ATTR, IS_VALID_ATTR,
THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR));
private final RedissonSessionManager redissonManager; private final RedissonSessionManager redissonManager;
private final Map<String, Object> attrs; private final Map<String, Object> attrs;
private RMap<String, Object> map; private RMap<String, Object> map;
@ -88,9 +101,9 @@ public class RedissonSession extends StandardSession {
if (map != null) { if (map != null) {
Map<String, Object> newMap = new HashMap<String, Object>(3); Map<String, Object> newMap = new HashMap<String, Object>(3);
newMap.put("session:creationTime", creationTime); newMap.put(CREATION_TIME_ATTR, creationTime);
newMap.put("session:lastAccessedTime", lastAccessedTime); newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put("session:thisAccessedTime", thisAccessedTime); newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap); map.putAll(newMap);
if (readMode == ReadMode.MEMORY) { if (readMode == ReadMode.MEMORY) {
topic.publish(createPutAllMessage(newMap)); topic.publish(createPutAllMessage(newMap));
@ -104,8 +117,8 @@ public class RedissonSession extends StandardSession {
if (map != null) { if (map != null) {
Map<String, Object> newMap = new HashMap<String, Object>(2); Map<String, Object> newMap = new HashMap<String, Object>(2);
newMap.put("session:lastAccessedTime", lastAccessedTime); newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put("session:thisAccessedTime", thisAccessedTime); newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap); map.putAll(newMap);
if (readMode == ReadMode.MEMORY) { if (readMode == ReadMode.MEMORY) {
topic.publish(createPutAllMessage(newMap)); topic.publish(createPutAllMessage(newMap));
@ -129,7 +142,7 @@ public class RedissonSession extends StandardSession {
super.setMaxInactiveInterval(interval); super.setMaxInactiveInterval(interval);
if (map != null) { if (map != null) {
fastPut("session:maxInactiveInterval", maxInactiveInterval); fastPut(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval);
if (maxInactiveInterval >= 0) { if (maxInactiveInterval >= 0) {
map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS); map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS);
} }
@ -152,7 +165,7 @@ public class RedissonSession extends StandardSession {
return; return;
} }
fastPut("session:isValid", isValid); fastPut(IS_VALID_ATTR, isValid);
} }
} }
@ -161,7 +174,7 @@ public class RedissonSession extends StandardSession {
super.setNew(isNew); super.setNew(isNew);
if (map != null) { if (map != null) {
fastPut("session:isNew", isNew); fastPut(IS_NEW_ATTR, isNew);
} }
} }
@ -171,7 +184,7 @@ public class RedissonSession extends StandardSession {
super.endAccess(); super.endAccess();
if (isNew != oldValue) { if (isNew != oldValue) {
fastPut("session:isNew", isNew); fastPut(IS_NEW_ATTR, isNew);
} }
} }
@ -206,12 +219,12 @@ public class RedissonSession extends StandardSession {
public void save() { public void save() {
Map<String, Object> newMap = new HashMap<String, Object>(); Map<String, Object> newMap = new HashMap<String, Object>();
newMap.put("session:creationTime", creationTime); newMap.put(CREATION_TIME_ATTR, creationTime);
newMap.put("session:lastAccessedTime", lastAccessedTime); newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put("session:thisAccessedTime", thisAccessedTime); newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
newMap.put("session:maxInactiveInterval", maxInactiveInterval); newMap.put(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval);
newMap.put("session:isValid", isValid); newMap.put(IS_VALID_ATTR, isValid);
newMap.put("session:isNew", isNew); newMap.put(IS_NEW_ATTR, isNew);
if (attrs != null) { if (attrs != null) {
for (Entry<String, Object> entry : attrs.entrySet()) { for (Entry<String, Object> entry : attrs.entrySet()) {
@ -230,27 +243,27 @@ public class RedissonSession extends StandardSession {
} }
public void load(Map<String, Object> attrs) { public void load(Map<String, Object> attrs) {
Long creationTime = (Long) attrs.remove("session:creationTime"); Long creationTime = (Long) attrs.remove(CREATION_TIME_ATTR);
if (creationTime != null) { if (creationTime != null) {
this.creationTime = creationTime; this.creationTime = creationTime;
} }
Long lastAccessedTime = (Long) attrs.remove("session:lastAccessedTime"); Long lastAccessedTime = (Long) attrs.remove(LAST_ACCESSED_TIME_ATTR);
if (lastAccessedTime != null) { if (lastAccessedTime != null) {
this.lastAccessedTime = lastAccessedTime; this.lastAccessedTime = lastAccessedTime;
} }
Integer maxInactiveInterval = (Integer) attrs.remove("session:maxInactiveInterval"); Integer maxInactiveInterval = (Integer) attrs.remove(MAX_INACTIVE_INTERVAL_ATTR);
if (maxInactiveInterval != null) { if (maxInactiveInterval != null) {
this.maxInactiveInterval = maxInactiveInterval; this.maxInactiveInterval = maxInactiveInterval;
} }
Long thisAccessedTime = (Long) attrs.remove("session:thisAccessedTime"); Long thisAccessedTime = (Long) attrs.remove(THIS_ACCESSED_TIME_ATTR);
if (thisAccessedTime != null) { if (thisAccessedTime != null) {
this.thisAccessedTime = thisAccessedTime; this.thisAccessedTime = thisAccessedTime;
} }
Boolean isValid = (Boolean) attrs.remove("session:isValid"); Boolean isValid = (Boolean) attrs.remove(IS_VALID_ATTR);
if (isValid != null) { if (isValid != null) {
this.isValid = isValid; this.isValid = isValid;
} }
Boolean isNew = (Boolean) attrs.remove("session:isNew"); Boolean isNew = (Boolean) attrs.remove(IS_NEW_ATTR);
if (isNew != null) { if (isNew != null) {
this.isNew = isNew; this.isNew = isNew;
} }

@ -17,6 +17,7 @@ package org.redisson.tomcat;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -128,7 +129,7 @@ public class RedissonSessionManager extends ManagerBase {
final String name = keyPrefix + separator + "redisson:tomcat_session:" + sessionId; final String name = keyPrefix + separator + "redisson:tomcat_session:" + sessionId;
return redisson.getMap(name); return redisson.getMap(name);
} }
public RTopic<AttributeMessage> getTopic() { public RTopic<AttributeMessage> getTopic() {
return redisson.getTopic("redisson:tomcat_session_updates:" + container.getName()); return redisson.getTopic("redisson:tomcat_session_updates:" + container.getName());
} }
@ -136,22 +137,30 @@ public class RedissonSessionManager extends ManagerBase {
@Override @Override
public Session findSession(String id) throws IOException { public Session findSession(String id) throws IOException {
Session result = super.findSession(id); Session result = super.findSession(id);
if (result == null && id != null) { if (result == null) {
Map<String, Object> attrs = getMap(id).readAllMap(); if (id != null) {
Map<String, Object> attrs = new HashMap<String, Object>();
if (attrs.isEmpty() || !Boolean.valueOf(String.valueOf(attrs.get("session:isValid")))) { if (readMode == ReadMode.MEMORY) {
log.info("Session " + id + " can't be found"); attrs = getMap(id).readAllMap();
return null; } else {
attrs = getMap(id).getAll(RedissonSession.ATTRS);
}
if (attrs.isEmpty() || !Boolean.valueOf(String.valueOf(attrs.get("session:isValid")))) {
log.info("Session " + id + " can't be found");
return null;
}
RedissonSession session = (RedissonSession) createEmptySession();
session.setId(id);
session.setManager(this);
session.load(attrs);
session.access();
session.endAccess();
return session;
} }
return null;
RedissonSession session = (RedissonSession) createEmptySession();
session.setId(id);
session.setManager(this);
session.load(attrs);
session.access();
session.endAccess();
return session;
} }
result.access(); result.access();
@ -186,7 +195,7 @@ public class RedissonSessionManager extends ManagerBase {
if (updateMode == UpdateMode.AFTER_REQUEST) { if (updateMode == UpdateMode.AFTER_REQUEST) {
getEngine().getPipeline().addValve(new UpdateValve(this)); getEngine().getPipeline().addValve(new UpdateValve(this));
} }
if (readMode == ReadMode.MEMORY) { if (readMode == ReadMode.MEMORY) {
RTopic<AttributeMessage> updatesTopic = getTopic(); RTopic<AttributeMessage> updatesTopic = getTopic();
updatesTopic.addListener(new MessageListener<AttributeMessage>() { updatesTopic.addListener(new MessageListener<AttributeMessage>() {

@ -16,9 +16,12 @@
package org.redisson.tomcat; package org.redisson.tomcat;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.catalina.session.StandardSession; import org.apache.catalina.session.StandardSession;
@ -35,6 +38,16 @@ import org.redisson.tomcat.RedissonSessionManager.UpdateMode;
*/ */
public class RedissonSession extends StandardSession { public class RedissonSession extends StandardSession {
private static final String IS_NEW_ATTR = "session:isNew";
private static final String IS_VALID_ATTR = "session:isValid";
private static final String THIS_ACCESSED_TIME_ATTR = "session:thisAccessedTime";
private static final String MAX_INACTIVE_INTERVAL_ATTR = "session:maxInactiveInterval";
private static final String LAST_ACCESSED_TIME_ATTR = "session:lastAccessedTime";
private static final String CREATION_TIME_ATTR = "session:creationTime";
public static final Set<String> ATTRS = new HashSet<String>(Arrays.asList(IS_NEW_ATTR, IS_VALID_ATTR,
THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR));
private final RedissonSessionManager redissonManager; private final RedissonSessionManager redissonManager;
private final Map<String, Object> attrs; private final Map<String, Object> attrs;
private RMap<String, Object> map; private RMap<String, Object> map;
@ -88,9 +101,9 @@ public class RedissonSession extends StandardSession {
if (map != null) { if (map != null) {
Map<String, Object> newMap = new HashMap<String, Object>(3); Map<String, Object> newMap = new HashMap<String, Object>(3);
newMap.put("session:creationTime", creationTime); newMap.put(CREATION_TIME_ATTR, creationTime);
newMap.put("session:lastAccessedTime", lastAccessedTime); newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put("session:thisAccessedTime", thisAccessedTime); newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap); map.putAll(newMap);
if (readMode == ReadMode.MEMORY) { if (readMode == ReadMode.MEMORY) {
topic.publish(createPutAllMessage(newMap)); topic.publish(createPutAllMessage(newMap));
@ -104,8 +117,8 @@ public class RedissonSession extends StandardSession {
if (map != null) { if (map != null) {
Map<String, Object> newMap = new HashMap<String, Object>(2); Map<String, Object> newMap = new HashMap<String, Object>(2);
newMap.put("session:lastAccessedTime", lastAccessedTime); newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put("session:thisAccessedTime", thisAccessedTime); newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap); map.putAll(newMap);
if (readMode == ReadMode.MEMORY) { if (readMode == ReadMode.MEMORY) {
topic.publish(createPutAllMessage(newMap)); topic.publish(createPutAllMessage(newMap));
@ -115,7 +128,7 @@ public class RedissonSession extends StandardSession {
} }
} }
} }
protected AttributesPutAllMessage createPutAllMessage(Map<String, Object> newMap) { protected AttributesPutAllMessage createPutAllMessage(Map<String, Object> newMap) {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
for (Entry<String, Object> entry : newMap.entrySet()) { for (Entry<String, Object> entry : newMap.entrySet()) {
@ -129,7 +142,7 @@ public class RedissonSession extends StandardSession {
super.setMaxInactiveInterval(interval); super.setMaxInactiveInterval(interval);
if (map != null) { if (map != null) {
fastPut("session:maxInactiveInterval", maxInactiveInterval); fastPut(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval);
if (maxInactiveInterval >= 0) { if (maxInactiveInterval >= 0) {
map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS); map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS);
} }
@ -152,7 +165,7 @@ public class RedissonSession extends StandardSession {
return; return;
} }
fastPut("session:isValid", isValid); fastPut(IS_VALID_ATTR, isValid);
} }
} }
@ -161,7 +174,7 @@ public class RedissonSession extends StandardSession {
super.setNew(isNew); super.setNew(isNew);
if (map != null) { if (map != null) {
fastPut("session:isNew", isNew); fastPut(IS_NEW_ATTR, isNew);
} }
} }
@ -171,7 +184,7 @@ public class RedissonSession extends StandardSession {
super.endAccess(); super.endAccess();
if (isNew != oldValue) { if (isNew != oldValue) {
fastPut("session:isNew", isNew); fastPut(IS_NEW_ATTR, isNew);
} }
} }
@ -206,12 +219,12 @@ public class RedissonSession extends StandardSession {
public void save() { public void save() {
Map<String, Object> newMap = new HashMap<String, Object>(); Map<String, Object> newMap = new HashMap<String, Object>();
newMap.put("session:creationTime", creationTime); newMap.put(CREATION_TIME_ATTR, creationTime);
newMap.put("session:lastAccessedTime", lastAccessedTime); newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put("session:thisAccessedTime", thisAccessedTime); newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
newMap.put("session:maxInactiveInterval", maxInactiveInterval); newMap.put(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval);
newMap.put("session:isValid", isValid); newMap.put(IS_VALID_ATTR, isValid);
newMap.put("session:isNew", isNew); newMap.put(IS_NEW_ATTR, isNew);
if (attrs != null) { if (attrs != null) {
for (Entry<String, Object> entry : attrs.entrySet()) { for (Entry<String, Object> entry : attrs.entrySet()) {
@ -230,27 +243,27 @@ public class RedissonSession extends StandardSession {
} }
public void load(Map<String, Object> attrs) { public void load(Map<String, Object> attrs) {
Long creationTime = (Long) attrs.remove("session:creationTime"); Long creationTime = (Long) attrs.remove(CREATION_TIME_ATTR);
if (creationTime != null) { if (creationTime != null) {
this.creationTime = creationTime; this.creationTime = creationTime;
} }
Long lastAccessedTime = (Long) attrs.remove("session:lastAccessedTime"); Long lastAccessedTime = (Long) attrs.remove(LAST_ACCESSED_TIME_ATTR);
if (lastAccessedTime != null) { if (lastAccessedTime != null) {
this.lastAccessedTime = lastAccessedTime; this.lastAccessedTime = lastAccessedTime;
} }
Integer maxInactiveInterval = (Integer) attrs.remove("session:maxInactiveInterval"); Integer maxInactiveInterval = (Integer) attrs.remove(MAX_INACTIVE_INTERVAL_ATTR);
if (maxInactiveInterval != null) { if (maxInactiveInterval != null) {
this.maxInactiveInterval = maxInactiveInterval; this.maxInactiveInterval = maxInactiveInterval;
} }
Long thisAccessedTime = (Long) attrs.remove("session:thisAccessedTime"); Long thisAccessedTime = (Long) attrs.remove(THIS_ACCESSED_TIME_ATTR);
if (thisAccessedTime != null) { if (thisAccessedTime != null) {
this.thisAccessedTime = thisAccessedTime; this.thisAccessedTime = thisAccessedTime;
} }
Boolean isValid = (Boolean) attrs.remove("session:isValid"); Boolean isValid = (Boolean) attrs.remove(IS_VALID_ATTR);
if (isValid != null) { if (isValid != null) {
this.isValid = isValid; this.isValid = isValid;
} }
Boolean isNew = (Boolean) attrs.remove("session:isNew"); Boolean isNew = (Boolean) attrs.remove(IS_NEW_ATTR);
if (isNew != null) { if (isNew != null) {
this.isNew = isNew; this.isNew = isNew;
} }

@ -17,6 +17,7 @@ package org.redisson.tomcat;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -36,9 +37,6 @@ import org.redisson.api.listener.MessageListener;
import org.redisson.client.codec.Codec; import org.redisson.client.codec.Codec;
import org.redisson.config.Config; import org.redisson.config.Config;
import io.netty.buffer.ByteBufUtil;
import io.netty.util.internal.PlatformDependent;
/** /**
* Redisson Session Manager for Apache Tomcat * Redisson Session Manager for Apache Tomcat
* *
@ -59,16 +57,7 @@ public class RedissonSessionManager extends ManagerBase {
private UpdateMode updateMode = UpdateMode.DEFAULT; private UpdateMode updateMode = UpdateMode.DEFAULT;
private String keyPrefix = ""; private String keyPrefix = "";
private final String id = ByteBufUtil.hexDump(generateId());
protected static byte[] generateId() {
byte[] id = new byte[16];
// TODO JDK UPGRADE replace to native ThreadLocalRandom
PlatformDependent.threadLocalRandom().nextBytes(id);
return id;
}
public String getUpdateMode() { public String getUpdateMode() {
return updateMode.toString(); return updateMode.toString();
} }
@ -139,7 +128,7 @@ public class RedissonSessionManager extends ManagerBase {
final String name = keyPrefix + separator + "redisson:tomcat_session:" + sessionId; final String name = keyPrefix + separator + "redisson:tomcat_session:" + sessionId;
return redisson.getMap(name); return redisson.getMap(name);
} }
public RTopic<AttributeMessage> getTopic() { public RTopic<AttributeMessage> getTopic() {
return redisson.getTopic("redisson:tomcat_session_updates:" + getContext().getName()); return redisson.getTopic("redisson:tomcat_session_updates:" + getContext().getName());
} }
@ -147,22 +136,30 @@ public class RedissonSessionManager extends ManagerBase {
@Override @Override
public Session findSession(String id) throws IOException { public Session findSession(String id) throws IOException {
Session result = super.findSession(id); Session result = super.findSession(id);
if (result == null && id != null) { if (result == null) {
Map<String, Object> attrs = getMap(id).readAllMap(); if (id != null) {
Map<String, Object> attrs = new HashMap<String, Object>();
if (attrs.isEmpty() || !Boolean.valueOf(String.valueOf(attrs.get("session:isValid")))) { if (readMode == ReadMode.MEMORY) {
log.info("Session " + id + " can't be found"); attrs = getMap(id).readAllMap();
return null; } else {
attrs = getMap(id).getAll(RedissonSession.ATTRS);
}
if (attrs.isEmpty() || !Boolean.valueOf(String.valueOf(attrs.get("session:isValid")))) {
log.info("Session " + id + " can't be found");
return null;
}
RedissonSession session = (RedissonSession) createEmptySession();
session.setId(id);
session.setManager(this);
session.load(attrs);
session.access();
session.endAccess();
return session;
} }
return null;
RedissonSession session = (RedissonSession) createEmptySession();
session.setId(id);
session.setManager(this);
session.load(attrs);
session.access();
session.endAccess();
return session;
} }
result.access(); result.access();
@ -197,7 +194,7 @@ public class RedissonSessionManager extends ManagerBase {
if (updateMode == UpdateMode.AFTER_REQUEST) { if (updateMode == UpdateMode.AFTER_REQUEST) {
getEngine().getPipeline().addValve(new UpdateValve(this)); getEngine().getPipeline().addValve(new UpdateValve(this));
} }
if (readMode == ReadMode.MEMORY) { if (readMode == ReadMode.MEMORY) {
RTopic<AttributeMessage> updatesTopic = getTopic(); RTopic<AttributeMessage> updatesTopic = getTopic();
updatesTopic.addListener(new MessageListener<AttributeMessage>() { updatesTopic.addListener(new MessageListener<AttributeMessage>() {
@ -292,9 +289,9 @@ public class RedissonSessionManager extends ManagerBase {
if (updateMode == UpdateMode.AFTER_REQUEST) { if (updateMode == UpdateMode.AFTER_REQUEST) {
RedissonSession sess = (RedissonSession) super.findSession(session.getId()); RedissonSession sess = (RedissonSession) super.findSession(session.getId());
if (sess != null) { if (sess != null) {
sess.save(); sess.save();
}
} }
} }
}
} }

@ -16,9 +16,12 @@
package org.redisson.tomcat; package org.redisson.tomcat;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.catalina.session.StandardSession; import org.apache.catalina.session.StandardSession;
@ -35,6 +38,16 @@ import org.redisson.tomcat.RedissonSessionManager.UpdateMode;
*/ */
public class RedissonSession extends StandardSession { public class RedissonSession extends StandardSession {
private static final String IS_NEW_ATTR = "session:isNew";
private static final String IS_VALID_ATTR = "session:isValid";
private static final String THIS_ACCESSED_TIME_ATTR = "session:thisAccessedTime";
private static final String MAX_INACTIVE_INTERVAL_ATTR = "session:maxInactiveInterval";
private static final String LAST_ACCESSED_TIME_ATTR = "session:lastAccessedTime";
private static final String CREATION_TIME_ATTR = "session:creationTime";
public static final Set<String> ATTRS = new HashSet<String>(Arrays.asList(IS_NEW_ATTR, IS_VALID_ATTR,
THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR));
private final RedissonSessionManager redissonManager; private final RedissonSessionManager redissonManager;
private final Map<String, Object> attrs; private final Map<String, Object> attrs;
private RMap<String, Object> map; private RMap<String, Object> map;
@ -88,9 +101,9 @@ public class RedissonSession extends StandardSession {
if (map != null) { if (map != null) {
Map<String, Object> newMap = new HashMap<String, Object>(3); Map<String, Object> newMap = new HashMap<String, Object>(3);
newMap.put("session:creationTime", creationTime); newMap.put(CREATION_TIME_ATTR, creationTime);
newMap.put("session:lastAccessedTime", lastAccessedTime); newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put("session:thisAccessedTime", thisAccessedTime); newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap); map.putAll(newMap);
if (readMode == ReadMode.MEMORY) { if (readMode == ReadMode.MEMORY) {
topic.publish(createPutAllMessage(newMap)); topic.publish(createPutAllMessage(newMap));
@ -104,8 +117,8 @@ public class RedissonSession extends StandardSession {
if (map != null) { if (map != null) {
Map<String, Object> newMap = new HashMap<String, Object>(2); Map<String, Object> newMap = new HashMap<String, Object>(2);
newMap.put("session:lastAccessedTime", lastAccessedTime); newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put("session:thisAccessedTime", thisAccessedTime); newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap); map.putAll(newMap);
if (readMode == ReadMode.MEMORY) { if (readMode == ReadMode.MEMORY) {
topic.publish(createPutAllMessage(newMap)); topic.publish(createPutAllMessage(newMap));
@ -115,7 +128,7 @@ public class RedissonSession extends StandardSession {
} }
} }
} }
protected AttributesPutAllMessage createPutAllMessage(Map<String, Object> newMap) { protected AttributesPutAllMessage createPutAllMessage(Map<String, Object> newMap) {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
for (Entry<String, Object> entry : newMap.entrySet()) { for (Entry<String, Object> entry : newMap.entrySet()) {
@ -129,7 +142,7 @@ public class RedissonSession extends StandardSession {
super.setMaxInactiveInterval(interval); super.setMaxInactiveInterval(interval);
if (map != null) { if (map != null) {
fastPut("session:maxInactiveInterval", maxInactiveInterval); fastPut(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval);
if (maxInactiveInterval >= 0) { if (maxInactiveInterval >= 0) {
map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS); map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS);
} }
@ -152,7 +165,7 @@ public class RedissonSession extends StandardSession {
return; return;
} }
fastPut("session:isValid", isValid); fastPut(IS_VALID_ATTR, isValid);
} }
} }
@ -161,7 +174,7 @@ public class RedissonSession extends StandardSession {
super.setNew(isNew); super.setNew(isNew);
if (map != null) { if (map != null) {
fastPut("session:isNew", isNew); fastPut(IS_NEW_ATTR, isNew);
} }
} }
@ -171,7 +184,7 @@ public class RedissonSession extends StandardSession {
super.endAccess(); super.endAccess();
if (isNew != oldValue) { if (isNew != oldValue) {
fastPut("session:isNew", isNew); fastPut(IS_NEW_ATTR, isNew);
} }
} }
@ -206,12 +219,12 @@ public class RedissonSession extends StandardSession {
public void save() { public void save() {
Map<String, Object> newMap = new HashMap<String, Object>(); Map<String, Object> newMap = new HashMap<String, Object>();
newMap.put("session:creationTime", creationTime); newMap.put(CREATION_TIME_ATTR, creationTime);
newMap.put("session:lastAccessedTime", lastAccessedTime); newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put("session:thisAccessedTime", thisAccessedTime); newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
newMap.put("session:maxInactiveInterval", maxInactiveInterval); newMap.put(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval);
newMap.put("session:isValid", isValid); newMap.put(IS_VALID_ATTR, isValid);
newMap.put("session:isNew", isNew); newMap.put(IS_NEW_ATTR, isNew);
if (attrs != null) { if (attrs != null) {
for (Entry<String, Object> entry : attrs.entrySet()) { for (Entry<String, Object> entry : attrs.entrySet()) {
@ -230,27 +243,27 @@ public class RedissonSession extends StandardSession {
} }
public void load(Map<String, Object> attrs) { public void load(Map<String, Object> attrs) {
Long creationTime = (Long) attrs.remove("session:creationTime"); Long creationTime = (Long) attrs.remove(CREATION_TIME_ATTR);
if (creationTime != null) { if (creationTime != null) {
this.creationTime = creationTime; this.creationTime = creationTime;
} }
Long lastAccessedTime = (Long) attrs.remove("session:lastAccessedTime"); Long lastAccessedTime = (Long) attrs.remove(LAST_ACCESSED_TIME_ATTR);
if (lastAccessedTime != null) { if (lastAccessedTime != null) {
this.lastAccessedTime = lastAccessedTime; this.lastAccessedTime = lastAccessedTime;
} }
Integer maxInactiveInterval = (Integer) attrs.remove("session:maxInactiveInterval"); Integer maxInactiveInterval = (Integer) attrs.remove(MAX_INACTIVE_INTERVAL_ATTR);
if (maxInactiveInterval != null) { if (maxInactiveInterval != null) {
this.maxInactiveInterval = maxInactiveInterval; this.maxInactiveInterval = maxInactiveInterval;
} }
Long thisAccessedTime = (Long) attrs.remove("session:thisAccessedTime"); Long thisAccessedTime = (Long) attrs.remove(THIS_ACCESSED_TIME_ATTR);
if (thisAccessedTime != null) { if (thisAccessedTime != null) {
this.thisAccessedTime = thisAccessedTime; this.thisAccessedTime = thisAccessedTime;
} }
Boolean isValid = (Boolean) attrs.remove("session:isValid"); Boolean isValid = (Boolean) attrs.remove(IS_VALID_ATTR);
if (isValid != null) { if (isValid != null) {
this.isValid = isValid; this.isValid = isValid;
} }
Boolean isNew = (Boolean) attrs.remove("session:isNew"); Boolean isNew = (Boolean) attrs.remove(IS_NEW_ATTR);
if (isNew != null) { if (isNew != null) {
this.isNew = isNew; this.isNew = isNew;
} }

@ -17,6 +17,7 @@ package org.redisson.tomcat;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -36,9 +37,6 @@ import org.redisson.api.listener.MessageListener;
import org.redisson.client.codec.Codec; import org.redisson.client.codec.Codec;
import org.redisson.config.Config; import org.redisson.config.Config;
import io.netty.buffer.ByteBufUtil;
import io.netty.util.internal.PlatformDependent;
/** /**
* Redisson Session Manager for Apache Tomcat * Redisson Session Manager for Apache Tomcat
* *
@ -59,16 +57,7 @@ public class RedissonSessionManager extends ManagerBase {
private UpdateMode updateMode = UpdateMode.DEFAULT; private UpdateMode updateMode = UpdateMode.DEFAULT;
private String keyPrefix = ""; private String keyPrefix = "";
private final String id = ByteBufUtil.hexDump(generateId());
protected static byte[] generateId() {
byte[] id = new byte[16];
// TODO JDK UPGRADE replace to native ThreadLocalRandom
PlatformDependent.threadLocalRandom().nextBytes(id);
return id;
}
public String getUpdateMode() { public String getUpdateMode() {
return updateMode.toString(); return updateMode.toString();
} }
@ -139,7 +128,7 @@ public class RedissonSessionManager extends ManagerBase {
final String name = keyPrefix + separator + "redisson:tomcat_session:" + sessionId; final String name = keyPrefix + separator + "redisson:tomcat_session:" + sessionId;
return redisson.getMap(name); return redisson.getMap(name);
} }
public RTopic<AttributeMessage> getTopic() { public RTopic<AttributeMessage> getTopic() {
return redisson.getTopic("redisson:tomcat_session_updates:" + getContext().getName()); return redisson.getTopic("redisson:tomcat_session_updates:" + getContext().getName());
} }
@ -147,22 +136,30 @@ public class RedissonSessionManager extends ManagerBase {
@Override @Override
public Session findSession(String id) throws IOException { public Session findSession(String id) throws IOException {
Session result = super.findSession(id); Session result = super.findSession(id);
if (result == null && id != null) { if (result == null) {
Map<String, Object> attrs = getMap(id).readAllMap(); if (id != null) {
Map<String, Object> attrs = new HashMap<String, Object>();
if (attrs.isEmpty() || !Boolean.valueOf(String.valueOf(attrs.get("session:isValid")))) { if (readMode == ReadMode.MEMORY) {
log.info("Session " + id + " can't be found"); attrs = getMap(id).readAllMap();
return null; } else {
attrs = getMap(id).getAll(RedissonSession.ATTRS);
}
if (attrs.isEmpty() || !Boolean.valueOf(String.valueOf(attrs.get("session:isValid")))) {
log.info("Session " + id + " can't be found");
return null;
}
RedissonSession session = (RedissonSession) createEmptySession();
session.setId(id);
session.setManager(this);
session.load(attrs);
session.access();
session.endAccess();
return session;
} }
return null;
RedissonSession session = (RedissonSession) createEmptySession();
session.setId(id);
session.setManager(this);
session.load(attrs);
session.access();
session.endAccess();
return session;
} }
result.access(); result.access();
@ -197,7 +194,7 @@ public class RedissonSessionManager extends ManagerBase {
if (updateMode == UpdateMode.AFTER_REQUEST) { if (updateMode == UpdateMode.AFTER_REQUEST) {
getEngine().getPipeline().addValve(new UpdateValve(this)); getEngine().getPipeline().addValve(new UpdateValve(this));
} }
if (readMode == ReadMode.MEMORY) { if (readMode == ReadMode.MEMORY) {
RTopic<AttributeMessage> updatesTopic = getTopic(); RTopic<AttributeMessage> updatesTopic = getTopic();
updatesTopic.addListener(new MessageListener<AttributeMessage>() { updatesTopic.addListener(new MessageListener<AttributeMessage>() {
@ -292,9 +289,9 @@ public class RedissonSessionManager extends ManagerBase {
if (updateMode == UpdateMode.AFTER_REQUEST) { if (updateMode == UpdateMode.AFTER_REQUEST) {
RedissonSession sess = (RedissonSession) super.findSession(session.getId()); RedissonSession sess = (RedissonSession) super.findSession(session.getId());
if (sess != null) { if (sess != null) {
sess.save(); sess.save();
}
} }
} }
}
} }

Loading…
Cancel
Save