Merge 918ca2e8b1
into 897b15ac10
commit
c9a616b908
14
pom.xml
14
pom.xml
|
@ -43,5 +43,19 @@
|
||||||
<artifactId>commons-logging</artifactId>
|
<artifactId>commons-logging</artifactId>
|
||||||
<version>1.2</version>
|
<version>1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--tomcat lib-->
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat</groupId>
|
||||||
|
<artifactId>tomcat-catalina</artifactId>
|
||||||
|
<version>7.0.42</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-servlet-api -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat</groupId>
|
||||||
|
<artifactId>tomcat-servlet-api</artifactId>
|
||||||
|
<version>7.0.42</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -40,3 +40,8 @@ Steps to be done,
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
* The Redis session manager supports, both single redis master and redis cluster based on the redis.properties configuration.
|
* The Redis session manager supports, both single redis master and redis cluster based on the redis.properties configuration.
|
||||||
|
|
||||||
|
modify explain:
|
||||||
|
* add redis select database
|
||||||
|
* repair redis session time unit bug,timeout=session.getMaxInactiveInterval(),unit =seconds
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,6 @@
|
||||||
redis.hosts=127.0.0.1:6379
|
redis.hosts=127.0.0.1:6379
|
||||||
# Redis Password
|
# Redis Password
|
||||||
redis.password=
|
redis.password=
|
||||||
|
redis.db=0
|
||||||
# set true to enable redis cluster mode
|
# set true to enable redis cluster mode
|
||||||
redis.cluster.enabled=false
|
redis.cluster.enabled=false
|
|
@ -57,6 +57,7 @@ public class RedisManager
|
||||||
poolConfig.setNumTestsPerEvictionRun(testNumPerEviction);
|
poolConfig.setNumTestsPerEvictionRun(testNumPerEviction);
|
||||||
long timeBetweenEviction = Long.parseLong(properties.getProperty(RedisConstants.TIME_BETWEENEVICTION, RedisConstants.DEFAULT_TIME_BETWEENEVICTION_VALUE));
|
long timeBetweenEviction = Long.parseLong(properties.getProperty(RedisConstants.TIME_BETWEENEVICTION, RedisConstants.DEFAULT_TIME_BETWEENEVICTION_VALUE));
|
||||||
poolConfig.setTimeBetweenEvictionRunsMillis(timeBetweenEviction);
|
poolConfig.setTimeBetweenEvictionRunsMillis(timeBetweenEviction);
|
||||||
|
int database = Integer.parseInt(properties.getProperty(RedisConstants.DATABASE, "0"));
|
||||||
String hosts = properties.getProperty(RedisConstants.HOSTS, Protocol.DEFAULT_HOST.concat(":").concat(String.valueOf(Protocol.DEFAULT_PORT)));
|
String hosts = properties.getProperty(RedisConstants.HOSTS, Protocol.DEFAULT_HOST.concat(":").concat(String.valueOf(Protocol.DEFAULT_PORT)));
|
||||||
String host = null;
|
String host = null;
|
||||||
int port = 0;
|
int port = 0;
|
||||||
|
@ -74,8 +75,10 @@ public class RedisManager
|
||||||
if (password == null || password == "" || password.isEmpty()) {
|
if (password == null || password == "" || password.isEmpty()) {
|
||||||
pool = new JedisPool(poolConfig, host, port);
|
pool = new JedisPool(poolConfig, host, port);
|
||||||
} else {
|
} else {
|
||||||
pool = new JedisPool(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, password);
|
// pool = new JedisPool(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, password);
|
||||||
|
pool =new JedisPool(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT, password,database);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jedis getJedis() {
|
public Jedis getJedis() {
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class RedisConstants
|
||||||
public static final String TIME_BETWEENEVICTION = "redis.time.betweenEviction";
|
public static final String TIME_BETWEENEVICTION = "redis.time.betweenEviction";
|
||||||
public static final String HOSTS = "redis.hosts";
|
public static final String HOSTS = "redis.hosts";
|
||||||
public static final String PASSWORD = "redis.password";
|
public static final String PASSWORD = "redis.password";
|
||||||
|
public static final String DATABASE = "redis.db";
|
||||||
public static final String IS_CLUSTER_ENABLED = "redis.cluster.enabled";
|
public static final String IS_CLUSTER_ENABLED = "redis.cluster.enabled";
|
||||||
|
|
||||||
// Redis property default values
|
// Redis property default values
|
||||||
|
|
|
@ -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=1800;
|
||||||
|
}
|
||||||
|
// 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();
|
||||||
|
|
Loading…
Reference in New Issue