repair redis session expire time unit bug

pull/1/head
wangdongxun 2016-09-22 19:57:20 +08:00
parent 3740cf404c
commit 750478baa3
2 changed files with 24 additions and 11 deletions

View File

@ -50,6 +50,7 @@ public class RequestSessionCacheFactory
resourceStream = null; resourceStream = null;
properties = new Properties(); properties = new Properties();
File file = new File(System.getProperty("catalina.base").concat(File.separator).concat("conf").concat(File.separator).concat(RedisConstants.REDIS_DATA_CACHE_PROPERTIES_FILE)); File file = new File(System.getProperty("catalina.base").concat(File.separator).concat("conf").concat(File.separator).concat(RedisConstants.REDIS_DATA_CACHE_PROPERTIES_FILE));
log.info("redis properties:"+file.getPath().toString());
if (file.exists()) { if (file.exists()) {
resourceStream = new FileInputStream(file); resourceStream = new FileInputStream(file);
} }

View File

@ -133,8 +133,8 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
} catch (Exception e) { } catch (Exception e) {
log.error("Error while initializing serializer/rediscache", e); log.error("Error while initializing serializer/rediscache", e);
} }
log.info("The sessions will expire after " + (getContext().getSessionTimeout() * 60) + " seconds"); // log.info("The sessions will expire after " + (getContext().getSessionTimeout() * 60) + " seconds");
getContext().setDistributable(true); // getContext().setDistributable(true);
} }
@Override @Override
@ -162,7 +162,7 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
customSession.setNew(true); customSession.setNew(true);
customSession.setValid(true); customSession.setValid(true);
customSession.setCreationTime(System.currentTimeMillis()); customSession.setCreationTime(System.currentTimeMillis());
customSession.setMaxInactiveInterval((getContext().getSessionTimeout() * 60)); // customSession.setMaxInactiveInterval((getContext().getSessionTimeout() * 60));
customSession.setId(sessionId); customSession.setId(sessionId);
customSession.tellNew(); customSession.tellNew();
} }
@ -229,7 +229,9 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
@Override @Override
public void remove(Session session, boolean update) { public void remove(Session session, boolean update) {
requestSessionCacheUtils.deleteKey(session.getId()); // expire after 10 seconds
requestSessionCacheUtils.expire(session.getId(),10);
// requestSessionCacheUtils.deleteKey(session.getId());
} }
@Override @Override
@ -262,7 +264,7 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
serializer.deserializeSessionData(data, customSession, metadata); serializer.deserializeSessionData(data, customSession, metadata);
customSession.setId(id); customSession.setId(id);
customSession.setNew(false); customSession.setNew(false);
customSession.setMaxInactiveInterval((getContext().getSessionTimeout() * 60)); // customSession.setMaxInactiveInterval((getContext().getSessionTimeout() * 60));
customSession.access(); customSession.access();
customSession.setValid(true); customSession.setValid(true);
customSession.resetDirtyTracking(); customSession.resetDirtyTracking();
@ -296,8 +298,16 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
currentSessionSerializationMetadata.set(updatedSerializationMetadata); currentSessionSerializationMetadata.set(updatedSerializationMetadata);
currentSessionIsPersisted.set(true); currentSessionIsPersisted.set(true);
} }
log.trace("Setting expire timeout on session [" + customSession.getId() + "] to " + (getContext().getSessionTimeout() * 60)); //time uite seconds
requestSessionCacheUtils.expire(customSession.getId(), (getContext().getSessionTimeout() * 60)); int timeOut=session.getMaxInactiveInterval();
if(timeOut<1){
timeOut=-1;
}
// log.trace("Setting expire timeout on session [" + customSession.getId() + "] to " + (getContext().getSessionTimeout() * 60));
// requestSessionCacheUtils.expire(customSession.getId(), (getContext().getSessionTimeout() * 60));
log.trace("Setting expire timeout on session [" + customSession.getId() + "] to " + timeOut+"seconds");
requestSessionCacheUtils.expire(customSession.getId(), timeOut);
} catch (IOException e) { } catch (IOException e) {
log.error("Error occured while storing the session object into redis", e); log.error("Error occured while storing the session object into redis", e);
} }
@ -332,10 +342,12 @@ public class RequestSessionManager extends ManagerBase implements Lifecycle
*/ */
private void initializeSessionSerializer() throws Exception { private void initializeSessionSerializer() throws Exception {
serializer = new SessionDataSerializer(); serializer = new SessionDataSerializer();
Loader loader = null; // Loader loader = null;
if (getContext() != null) { //
loader = getContext().getLoader(); // if (getContext() != null) {
} // loader = getContext().getLoader();
// }
Loader loader =this.getContainer().getLoader();
ClassLoader classLoader = null; ClassLoader classLoader = null;
if (loader != null) { if (loader != null) {
classLoader = loader.getClassLoader(); classLoader = loader.getClassLoader();