Bug fixes and added redis sentinel supportability changes.
parent
a95d5d9f5c
commit
92adf755ba
|
@ -14,7 +14,7 @@ Going forward, we no need to enable sticky session (JSESSIONID) in Load balancer
|
||||||
- Apache Tomcat 9
|
- Apache Tomcat 9
|
||||||
|
|
||||||
## Downloads:
|
## Downloads:
|
||||||
- [latest version (2.0.5)](https://github.com/ran-jit/tomcat-cluster-redis-session-manager/releases/tag/2.0.5)
|
- [latest version (3.0)](https://github.com/ran-jit/tomcat-cluster-redis-session-manager/releases/tag/3.0)
|
||||||
- [older versions](https://github.com/ran-jit/tomcat-cluster-redis-session-manager/wiki)
|
- [older versions](https://github.com/ran-jit/tomcat-cluster-redis-session-manager/wiki)
|
||||||
|
|
||||||
#### Pre-requisite:
|
#### Pre-requisite:
|
||||||
|
|
|
@ -73,10 +73,8 @@ public class Session extends StandardSession {
|
||||||
super.setAttribute(key, value);
|
super.setAttribute(key, value);
|
||||||
|
|
||||||
if ((value != null || oldValue != null)
|
if ((value != null || oldValue != null)
|
||||||
&& (value == null && oldValue != null || oldValue == null && value != null
|
&& (value == null && oldValue != null || oldValue == null && value != null || !value.getClass().isInstance(oldValue) || !value.equals(oldValue))) {
|
||||||
|| !value.getClass().isInstance(oldValue) || !value.equals(oldValue))) {
|
if (this.manager instanceof SessionManager && ((SessionManager) this.manager).getSaveOnChange()) {
|
||||||
if (this.manager instanceof SessionManager && ((SessionManager) this.manager)
|
|
||||||
.getSaveOnChange()) {
|
|
||||||
((SessionManager) this.manager).save(this, true);
|
((SessionManager) this.manager).save(this, true);
|
||||||
} else {
|
} else {
|
||||||
this.changedAttributes.put(key, value);
|
this.changedAttributes.put(key, value);
|
||||||
|
@ -100,8 +98,7 @@ public class Session extends StandardSession {
|
||||||
@Override
|
@Override
|
||||||
public void removeAttribute(String name) {
|
public void removeAttribute(String name) {
|
||||||
super.removeAttribute(name);
|
super.removeAttribute(name);
|
||||||
if (this.manager instanceof SessionManager && ((SessionManager) this.manager)
|
if (this.manager instanceof SessionManager && ((SessionManager) this.manager).getSaveOnChange()) {
|
||||||
.getSaveOnChange()) {
|
|
||||||
((SessionManager) this.manager).save(this, true);
|
((SessionManager) this.manager).save(this, true);
|
||||||
} else {
|
} else {
|
||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
|
|
|
@ -121,8 +121,7 @@ public class SessionManager extends ManagerBase implements Lifecycle {
|
||||||
@Override
|
@Override
|
||||||
public Session createSession(String sessionId) {
|
public Session createSession(String sessionId) {
|
||||||
if (sessionId != null) {
|
if (sessionId != null) {
|
||||||
sessionId =
|
sessionId = (this.dataCache.setnx(sessionId, SessionConstants.NULL_SESSION) == 0L) ? null : sessionId;
|
||||||
(this.dataCache.setnx(sessionId, SessionConstants.NULL_SESSION) == 0L) ? null : sessionId;
|
|
||||||
} else {
|
} else {
|
||||||
do {
|
do {
|
||||||
sessionId = generateSessionId();
|
sessionId = generateSessionId();
|
||||||
|
@ -168,8 +167,7 @@ public class SessionManager extends ManagerBase implements Lifecycle {
|
||||||
@Override
|
@Override
|
||||||
public Session findSession(String sessionId) throws IOException {
|
public Session findSession(String sessionId) throws IOException {
|
||||||
Session session = null;
|
Session session = null;
|
||||||
if (sessionId != null && this.sessionContext.get() != null && sessionId
|
if (sessionId != null && this.sessionContext.get() != null && sessionId.equals(this.sessionContext.get().getId())) {
|
||||||
.equals(this.sessionContext.get().getId())) {
|
|
||||||
session = this.sessionContext.get().getSession();
|
session = this.sessionContext.get().getSession();
|
||||||
} else {
|
} else {
|
||||||
byte[] data = this.dataCache.get(sessionId);
|
byte[] data = this.dataCache.get(sessionId);
|
||||||
|
@ -234,7 +232,6 @@ public class SessionManager extends ManagerBase implements Lifecycle {
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
try {
|
try {
|
||||||
this.dataCache = new RedisCache();
|
this.dataCache = new RedisCache();
|
||||||
|
|
||||||
this.serializer = new SerializationUtil();
|
this.serializer = new SerializationUtil();
|
||||||
Context context = getContextIns();
|
Context context = getContextIns();
|
||||||
ClassLoader loader = (context != null && context.getLoader() != null) ? context.getLoader().getClassLoader() : null;
|
ClassLoader loader = (context != null && context.getLoader() != null) ? context.getLoader().getClassLoader() : null;
|
||||||
|
@ -254,24 +251,22 @@ public class SessionManager extends ManagerBase implements Lifecycle {
|
||||||
? this.sessionContext.get().getMetadata().getAttributesHash() : null;
|
? this.sessionContext.get().getMetadata().getAttributesHash() : null;
|
||||||
byte[] currentHash = serializer.getSessionAttributesHashCode(newSession);
|
byte[] currentHash = serializer.getSessionAttributesHashCode(newSession);
|
||||||
|
|
||||||
if (forceSave || newSession.isDirty()
|
if (forceSave
|
||||||
|| (isPersisted =
|
|| newSession.isDirty()
|
||||||
(this.sessionContext.get() != null) ? this.sessionContext.get().isPersisted() : null)
|
|| (isPersisted = (this.sessionContext.get() != null) ? this.sessionContext.get().isPersisted() : null) == null
|
||||||
== null
|
|
||||||
|| !isPersisted || !Arrays.equals(hash, currentHash)) {
|
|| !isPersisted || !Arrays.equals(hash, currentHash)) {
|
||||||
|
|
||||||
SessionMetadata metadata = new SessionMetadata();
|
SessionMetadata metadata = new SessionMetadata();
|
||||||
metadata.setAttributesHash(currentHash);
|
metadata.setAttributesHash(currentHash);
|
||||||
|
|
||||||
this.dataCache
|
this.dataCache.set(newSession.getId(), serializer.serializeSessionData(newSession, metadata));
|
||||||
.set(newSession.getId(), serializer.serializeSessionData(newSession, metadata));
|
|
||||||
newSession.resetDirtyTracking();
|
newSession.resetDirtyTracking();
|
||||||
setValues(true, metadata);
|
setValues(true, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
int timeout = getSessionTimeout(newSession);
|
int timeout = getSessionTimeout(newSession);
|
||||||
this.dataCache.expire(newSession.getId(), timeout);
|
this.dataCache.expire(newSession.getId(), timeout);
|
||||||
LOGGER.trace("Session [" + newSession.getId() + "] expire in [" + timeout + "] seconds.");
|
LOGGER.debug("Session [" + newSession.getId() + "] expire in [" + timeout + "] seconds.");
|
||||||
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LOGGER.error("Error occurred while saving the session object in data cache..", ex);
|
LOGGER.error("Error occurred while saving the session object in data cache..", ex);
|
||||||
|
@ -289,15 +284,13 @@ public class SessionManager extends ManagerBase implements Lifecycle {
|
||||||
} else {
|
} else {
|
||||||
remove(session);
|
remove(session);
|
||||||
}
|
}
|
||||||
LOGGER.trace(
|
LOGGER.debug("Session object " + (session.isValid() ? "saved: " : "removed: ") + session.getId());
|
||||||
"Session object " + (session.isValid() ? "saved: " : "removed: ") + session.getId());
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOGGER.error("Error occurred while processing post request process..", ex);
|
LOGGER.error("Error occurred while processing post request process..", ex);
|
||||||
} finally {
|
} finally {
|
||||||
this.sessionContext.remove();
|
this.sessionContext.remove();
|
||||||
LOGGER.trace(
|
LOGGER.debug("Session removed from ThreadLocal:" + ((session != null) ? session.getIdInternal() : ""));
|
||||||
"Session removed from ThreadLocal:" + ((session != null) ? session.getIdInternal() : ""));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue