Fixed - RedissonSessionManager throws java.lang.ClassNotFoundException if readMode=MEMORY #1867

pull/1871/head
Nikita Koksharov 6 years ago
parent 228319d656
commit ae14dba2fc

@ -15,8 +15,14 @@
*/
package org.redisson.tomcat;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.apache.catalina.util.CustomObjectInputStream;
/**
*
* @author Nikita Koksharov
@ -31,10 +37,6 @@ public class AttributeMessage implements Serializable {
public AttributeMessage() {
}
public AttributeMessage(String sessionId) {
this.sessionId = sessionId;
}
public AttributeMessage(String nodeId, String sessionId) {
this.nodeId = nodeId;
this.sessionId = sessionId;
@ -48,4 +50,22 @@ public class AttributeMessage implements Serializable {
return nodeId;
}
protected byte[] toByteArray(Object value) throws IOException {
if (value == null) {
return null;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(value);
out.flush();
return bos.toByteArray();
}
protected Object toObject(ClassLoader classLoader, byte[] value) throws IOException, ClassNotFoundException {
if (value == null) {
return null;
}
CustomObjectInputStream in = new CustomObjectInputStream(new ByteArrayInputStream(value), classLoader);
return in.readObject();
}
}

@ -28,11 +28,6 @@ public class AttributeRemoveMessage extends AttributeMessage {
super();
}
public AttributeRemoveMessage(String sessionId, String name) {
super(sessionId);
this.name = name;
}
public AttributeRemoveMessage(String nodeId, String sessionId, String name) {
super(nodeId, sessionId);
this.name = name;

@ -15,6 +15,8 @@
*/
package org.redisson.tomcat;
import java.io.IOException;
/**
*
* @author Nikita Koksharov
@ -23,29 +25,23 @@ package org.redisson.tomcat;
public class AttributeUpdateMessage extends AttributeMessage {
private String name;
private Object value;
private byte[] value;
public AttributeUpdateMessage() {
}
public AttributeUpdateMessage(String sessionId, String name, Object value) {
super(sessionId);
this.name = name;
this.value = value;
}
public AttributeUpdateMessage(String nodeId, String sessionId, String name, Object value) {
public AttributeUpdateMessage(String nodeId, String sessionId, String name, Object value) throws IOException {
super(nodeId, sessionId);
this.name = name;
this.value = value;
this.value = toByteArray(value);
}
public String getName() {
return name;
}
public Object getValue() {
return value;
public Object getValue(ClassLoader classLoader) throws IOException, ClassNotFoundException {
return toObject(classLoader, value);
}
}

@ -25,10 +25,6 @@ public class AttributesClearMessage extends AttributeMessage {
public AttributesClearMessage() {
}
public AttributesClearMessage(String sessionId) {
super(sessionId);
}
public AttributesClearMessage(String nodeId, String sessionId) {
super(nodeId, sessionId);
}

@ -15,7 +15,10 @@
*/
package org.redisson.tomcat;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
*
@ -24,23 +27,32 @@ import java.util.Map;
*/
public class AttributesPutAllMessage extends AttributeMessage {
private Map<String, Object> attrs;
private Map<String, byte[]> attrs;
public AttributesPutAllMessage() {
}
public AttributesPutAllMessage(String sessionId, Map<String, Object> attrs) {
super(sessionId);
this.attrs = attrs;
}
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs) {
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs) throws IOException {
super(nodeId, sessionId);
this.attrs = attrs;
if (attrs != null) {
this.attrs = new HashMap<String, byte[]>();
for (Entry<String, Object> entry: attrs.entrySet()) {
this.attrs.put(entry.getKey(), toByteArray(entry.getValue()));
}
} else {
this.attrs = null;
}
}
public Map<String, Object> getAttrs() {
return attrs;
public Map<String, Object> getAttrs(ClassLoader classLoader) throws IOException, ClassNotFoundException {
if (attrs == null) {
return null;
}
Map<String, Object> result = new HashMap<String, Object>();
for (Entry<String, byte[]> entry: attrs.entrySet()) {
result.put(entry.getKey(), toObject(classLoader, entry.getValue()));
}
return result;
}
}

@ -15,6 +15,7 @@
*/
package org.redisson.tomcat;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
@ -132,7 +133,11 @@ public class RedissonSession extends StandardSession {
for (Entry<String, Object> entry : newMap.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), map);
try {
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), map);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override
@ -148,7 +153,11 @@ public class RedissonSession extends StandardSession {
private void fastPut(String name, Object value) {
map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value));
try {
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}

@ -158,7 +158,9 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
}
public RTopic getTopic() {
return redisson.getTopic("redisson:tomcat_session_updates:" + container.getName());
String separator = keyPrefix == null || keyPrefix.isEmpty() ? "" : ":";
final String name = keyPrefix + separator + "redisson:tomcat_session_updates:" + ((Context) getContainer()).getName();
return redisson.getTopic(name);
}
@Override
@ -228,6 +230,13 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
public void start() throws LifecycleException {
redisson = buildClient();
final ClassLoader applicationClassLoader;
if (Thread.currentThread().getContextClassLoader() != null) {
applicationClassLoader = Thread.currentThread().getContextClassLoader();
} else {
applicationClassLoader = getClass().getClassLoader();
}
if (updateMode == UpdateMode.AFTER_REQUEST) {
getEngine().getPipeline().addValve(new UpdateValve(this));
}
@ -252,17 +261,17 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
if (msg instanceof AttributesPutAllMessage) {
AttributesPutAllMessage m = (AttributesPutAllMessage) msg;
for (Entry<String, Object> entry : m.getAttrs().entrySet()) {
for (Entry<String, Object> entry : m.getAttrs(applicationClassLoader).entrySet()) {
session.superSetAttribute(entry.getKey(), entry.getValue(), true);
}
}
if (msg instanceof AttributeUpdateMessage) {
AttributeUpdateMessage m = (AttributeUpdateMessage)msg;
session.superSetAttribute(m.getName(), m.getValue(), true);
session.superSetAttribute(m.getName(), m.getValue(applicationClassLoader), true);
}
}
} catch (IOException e) {
} catch (Exception e) {
log.error("Can't handle topic message", e);
}
}

@ -15,8 +15,14 @@
*/
package org.redisson.tomcat;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.apache.catalina.util.CustomObjectInputStream;
/**
*
* @author Nikita Koksharov
@ -31,10 +37,6 @@ public class AttributeMessage implements Serializable {
public AttributeMessage() {
}
public AttributeMessage(String sessionId) {
this.sessionId = sessionId;
}
public AttributeMessage(String nodeId, String sessionId) {
this.nodeId = nodeId;
this.sessionId = sessionId;
@ -48,4 +50,22 @@ public class AttributeMessage implements Serializable {
return nodeId;
}
protected byte[] toByteArray(Object value) throws IOException {
if (value == null) {
return null;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(value);
out.flush();
return bos.toByteArray();
}
protected Object toObject(ClassLoader classLoader, byte[] value) throws IOException, ClassNotFoundException {
if (value == null) {
return null;
}
CustomObjectInputStream in = new CustomObjectInputStream(new ByteArrayInputStream(value), classLoader);
return in.readObject();
}
}

@ -28,11 +28,6 @@ public class AttributeRemoveMessage extends AttributeMessage {
super();
}
public AttributeRemoveMessage(String sessionId, String name) {
super(sessionId);
this.name = name;
}
public AttributeRemoveMessage(String nodeId, String sessionId, String name) {
super(nodeId, sessionId);
this.name = name;

@ -15,6 +15,8 @@
*/
package org.redisson.tomcat;
import java.io.IOException;
/**
*
* @author Nikita Koksharov
@ -23,29 +25,23 @@ package org.redisson.tomcat;
public class AttributeUpdateMessage extends AttributeMessage {
private String name;
private Object value;
private byte[] value;
public AttributeUpdateMessage() {
}
public AttributeUpdateMessage(String sessionId, String name, Object value) {
super(sessionId);
this.name = name;
this.value = value;
}
public AttributeUpdateMessage(String nodeId, String sessionId, String name, Object value) {
public AttributeUpdateMessage(String nodeId, String sessionId, String name, Object value) throws IOException {
super(nodeId, sessionId);
this.name = name;
this.value = value;
this.value = toByteArray(value);
}
public String getName() {
return name;
}
public Object getValue() {
return value;
public Object getValue(ClassLoader classLoader) throws IOException, ClassNotFoundException {
return toObject(classLoader, value);
}
}

@ -25,10 +25,6 @@ public class AttributesClearMessage extends AttributeMessage {
public AttributesClearMessage() {
}
public AttributesClearMessage(String sessionId) {
super(sessionId);
}
public AttributesClearMessage(String nodeId, String sessionId) {
super(nodeId, sessionId);
}

@ -15,7 +15,10 @@
*/
package org.redisson.tomcat;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
*
@ -24,23 +27,32 @@ import java.util.Map;
*/
public class AttributesPutAllMessage extends AttributeMessage {
private Map<String, Object> attrs;
private Map<String, byte[]> attrs;
public AttributesPutAllMessage() {
}
public AttributesPutAllMessage(String sessionId, Map<String, Object> attrs) {
super(sessionId);
this.attrs = attrs;
}
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs) {
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs) throws IOException {
super(nodeId, sessionId);
this.attrs = attrs;
if (attrs != null) {
this.attrs = new HashMap<String, byte[]>();
for (Entry<String, Object> entry: attrs.entrySet()) {
this.attrs.put(entry.getKey(), toByteArray(entry.getValue()));
}
} else {
this.attrs = null;
}
}
public Map<String, Object> getAttrs() {
return attrs;
public Map<String, Object> getAttrs(ClassLoader classLoader) throws IOException, ClassNotFoundException {
if (attrs == null) {
return null;
}
Map<String, Object> result = new HashMap<String, Object>();
for (Entry<String, byte[]> entry: attrs.entrySet()) {
result.put(entry.getKey(), toObject(classLoader, entry.getValue()));
}
return result;
}
}

@ -15,6 +15,7 @@
*/
package org.redisson.tomcat;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
@ -55,7 +56,7 @@ public class RedissonSession extends StandardSession {
private final RedissonSessionManager.ReadMode readMode;
private final UpdateMode updateMode;
public RedissonSession(RedissonSessionManager manager, ReadMode readMode, UpdateMode updateMode) {
public RedissonSession(RedissonSessionManager manager, RedissonSessionManager.ReadMode readMode, UpdateMode updateMode) {
super(manager);
this.redissonManager = manager;
this.readMode = readMode;
@ -132,7 +133,11 @@ public class RedissonSession extends StandardSession {
for (Entry<String, Object> entry : newMap.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), map);
try {
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), map);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override
@ -148,7 +153,11 @@ public class RedissonSession extends StandardSession {
private void fastPut(String name, Object value) {
map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value));
try {
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}

@ -137,7 +137,9 @@ public class RedissonSessionManager extends ManagerBase {
}
public RTopic getTopic() {
return redisson.getTopic("redisson:tomcat_session_updates:" + container.getName());
String separator = keyPrefix == null || keyPrefix.isEmpty() ? "" : ":";
final String name = keyPrefix + separator + "redisson:tomcat_session_updates:" + ((Context) getContainer()).getName();
return redisson.getTopic(name);
}
@Override
@ -208,6 +210,13 @@ public class RedissonSessionManager extends ManagerBase {
super.startInternal();
redisson = buildClient();
final ClassLoader applicationClassLoader;
if (Thread.currentThread().getContextClassLoader() != null) {
applicationClassLoader = Thread.currentThread().getContextClassLoader();
} else {
applicationClassLoader = getClass().getClassLoader();
}
if (updateMode == UpdateMode.AFTER_REQUEST) {
getEngine().getPipeline().addValve(new UpdateValve(this));
}
@ -232,17 +241,17 @@ public class RedissonSessionManager extends ManagerBase {
if (msg instanceof AttributesPutAllMessage) {
AttributesPutAllMessage m = (AttributesPutAllMessage) msg;
for (Entry<String, Object> entry : m.getAttrs().entrySet()) {
for (Entry<String, Object> entry : m.getAttrs(applicationClassLoader).entrySet()) {
session.superSetAttribute(entry.getKey(), entry.getValue(), true);
}
}
if (msg instanceof AttributeUpdateMessage) {
AttributeUpdateMessage m = (AttributeUpdateMessage)msg;
session.superSetAttribute(m.getName(), m.getValue(), true);
session.superSetAttribute(m.getName(), m.getValue(applicationClassLoader), true);
}
}
} catch (IOException e) {
} catch (Exception e) {
log.error("Can't handle topic message", e);
}
}

@ -15,8 +15,14 @@
*/
package org.redisson.tomcat;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.apache.catalina.util.CustomObjectInputStream;
/**
*
* @author Nikita Koksharov
@ -31,10 +37,6 @@ public class AttributeMessage implements Serializable {
public AttributeMessage() {
}
public AttributeMessage(String sessionId) {
this.sessionId = sessionId;
}
public AttributeMessage(String nodeId, String sessionId) {
this.nodeId = nodeId;
this.sessionId = sessionId;
@ -48,4 +50,22 @@ public class AttributeMessage implements Serializable {
return nodeId;
}
protected byte[] toByteArray(Object value) throws IOException {
if (value == null) {
return null;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(value);
out.flush();
return bos.toByteArray();
}
protected Object toObject(ClassLoader classLoader, byte[] value) throws IOException, ClassNotFoundException {
if (value == null) {
return null;
}
CustomObjectInputStream in = new CustomObjectInputStream(new ByteArrayInputStream(value), classLoader);
return in.readObject();
}
}

@ -28,11 +28,6 @@ public class AttributeRemoveMessage extends AttributeMessage {
super();
}
public AttributeRemoveMessage(String sessionId, String name) {
super(sessionId);
this.name = name;
}
public AttributeRemoveMessage(String nodeId, String sessionId, String name) {
super(nodeId, sessionId);
this.name = name;

@ -15,6 +15,8 @@
*/
package org.redisson.tomcat;
import java.io.IOException;
/**
*
* @author Nikita Koksharov
@ -23,29 +25,23 @@ package org.redisson.tomcat;
public class AttributeUpdateMessage extends AttributeMessage {
private String name;
private Object value;
private byte[] value;
public AttributeUpdateMessage() {
}
public AttributeUpdateMessage(String sessionId, String name, Object value) {
super(sessionId);
this.name = name;
this.value = value;
}
public AttributeUpdateMessage(String nodeId, String sessionId, String name, Object value) {
public AttributeUpdateMessage(String nodeId, String sessionId, String name, Object value) throws IOException {
super(nodeId, sessionId);
this.name = name;
this.value = value;
this.value = toByteArray(value);
}
public String getName() {
return name;
}
public Object getValue() {
return value;
public Object getValue(ClassLoader classLoader) throws IOException, ClassNotFoundException {
return toObject(classLoader, value);
}
}

@ -25,10 +25,6 @@ public class AttributesClearMessage extends AttributeMessage {
public AttributesClearMessage() {
}
public AttributesClearMessage(String sessionId) {
super(sessionId);
}
public AttributesClearMessage(String nodeId, String sessionId) {
super(nodeId, sessionId);
}

@ -15,7 +15,10 @@
*/
package org.redisson.tomcat;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
*
@ -24,23 +27,32 @@ import java.util.Map;
*/
public class AttributesPutAllMessage extends AttributeMessage {
private Map<String, Object> attrs;
private Map<String, byte[]> attrs;
public AttributesPutAllMessage() {
}
public AttributesPutAllMessage(String sessionId, Map<String, Object> attrs) {
super(sessionId);
this.attrs = attrs;
}
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs) {
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs) throws IOException {
super(nodeId, sessionId);
this.attrs = attrs;
if (attrs != null) {
this.attrs = new HashMap<String, byte[]>();
for (Entry<String, Object> entry: attrs.entrySet()) {
this.attrs.put(entry.getKey(), toByteArray(entry.getValue()));
}
} else {
this.attrs = null;
}
}
public Map<String, Object> getAttrs() {
return attrs;
public Map<String, Object> getAttrs(ClassLoader classLoader) throws IOException, ClassNotFoundException {
if (attrs == null) {
return null;
}
Map<String, Object> result = new HashMap<String, Object>();
for (Entry<String, byte[]> entry: attrs.entrySet()) {
result.put(entry.getKey(), toObject(classLoader, entry.getValue()));
}
return result;
}
}

@ -15,6 +15,7 @@
*/
package org.redisson.tomcat;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
@ -132,7 +133,11 @@ public class RedissonSession extends StandardSession {
for (Entry<String, Object> entry : newMap.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), map);
try {
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), map);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override
@ -148,7 +153,11 @@ public class RedissonSession extends StandardSession {
private void fastPut(String name, Object value) {
map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value));
try {
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}

@ -209,6 +209,13 @@ public class RedissonSessionManager extends ManagerBase {
super.startInternal();
redisson = buildClient();
final ClassLoader applicationClassLoader;
if (Thread.currentThread().getContextClassLoader() != null) {
applicationClassLoader = Thread.currentThread().getContextClassLoader();
} else {
applicationClassLoader = getClass().getClassLoader();
}
if (updateMode == UpdateMode.AFTER_REQUEST) {
getEngine().getPipeline().addValve(new UpdateValve(this));
}
@ -233,17 +240,17 @@ public class RedissonSessionManager extends ManagerBase {
if (msg instanceof AttributesPutAllMessage) {
AttributesPutAllMessage m = (AttributesPutAllMessage) msg;
for (Entry<String, Object> entry : m.getAttrs().entrySet()) {
for (Entry<String, Object> entry : m.getAttrs(applicationClassLoader).entrySet()) {
session.superSetAttribute(entry.getKey(), entry.getValue(), true);
}
}
if (msg instanceof AttributeUpdateMessage) {
AttributeUpdateMessage m = (AttributeUpdateMessage)msg;
session.superSetAttribute(m.getName(), m.getValue(), true);
session.superSetAttribute(m.getName(), m.getValue(applicationClassLoader), true);
}
}
} catch (IOException e) {
} catch (Exception e) {
log.error("Can't handle topic message", e);
}
}

@ -15,8 +15,14 @@
*/
package org.redisson.tomcat;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.apache.catalina.util.CustomObjectInputStream;
/**
*
* @author Nikita Koksharov
@ -31,10 +37,6 @@ public class AttributeMessage implements Serializable {
public AttributeMessage() {
}
public AttributeMessage(String sessionId) {
this.sessionId = sessionId;
}
public AttributeMessage(String nodeId, String sessionId) {
this.nodeId = nodeId;
this.sessionId = sessionId;
@ -48,4 +50,22 @@ public class AttributeMessage implements Serializable {
return nodeId;
}
protected byte[] toByteArray(Object value) throws IOException {
if (value == null) {
return null;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(value);
out.flush();
return bos.toByteArray();
}
protected Object toObject(ClassLoader classLoader, byte[] value) throws IOException, ClassNotFoundException {
if (value == null) {
return null;
}
CustomObjectInputStream in = new CustomObjectInputStream(new ByteArrayInputStream(value), classLoader);
return in.readObject();
}
}

@ -28,11 +28,6 @@ public class AttributeRemoveMessage extends AttributeMessage {
super();
}
public AttributeRemoveMessage(String sessionId, String name) {
super(sessionId);
this.name = name;
}
public AttributeRemoveMessage(String nodeId, String sessionId, String name) {
super(nodeId, sessionId);
this.name = name;

@ -15,6 +15,8 @@
*/
package org.redisson.tomcat;
import java.io.IOException;
/**
*
* @author Nikita Koksharov
@ -23,29 +25,23 @@ package org.redisson.tomcat;
public class AttributeUpdateMessage extends AttributeMessage {
private String name;
private Object value;
private byte[] value;
public AttributeUpdateMessage() {
}
public AttributeUpdateMessage(String sessionId, String name, Object value) {
super(sessionId);
this.name = name;
this.value = value;
}
public AttributeUpdateMessage(String nodeId, String sessionId, String name, Object value) {
public AttributeUpdateMessage(String nodeId, String sessionId, String name, Object value) throws IOException {
super(nodeId, sessionId);
this.name = name;
this.value = value;
this.value = toByteArray(value);
}
public String getName() {
return name;
}
public Object getValue() {
return value;
public Object getValue(ClassLoader classLoader) throws IOException, ClassNotFoundException {
return toObject(classLoader, value);
}
}

@ -25,10 +25,6 @@ public class AttributesClearMessage extends AttributeMessage {
public AttributesClearMessage() {
}
public AttributesClearMessage(String sessionId) {
super(sessionId);
}
public AttributesClearMessage(String nodeId, String sessionId) {
super(nodeId, sessionId);
}

@ -15,7 +15,10 @@
*/
package org.redisson.tomcat;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
*
@ -24,23 +27,32 @@ import java.util.Map;
*/
public class AttributesPutAllMessage extends AttributeMessage {
private Map<String, Object> attrs;
private Map<String, byte[]> attrs;
public AttributesPutAllMessage() {
}
public AttributesPutAllMessage(String sessionId, Map<String, Object> attrs) {
super(sessionId);
this.attrs = attrs;
}
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs) {
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs) throws IOException {
super(nodeId, sessionId);
this.attrs = attrs;
if (attrs != null) {
this.attrs = new HashMap<String, byte[]>();
for (Entry<String, Object> entry: attrs.entrySet()) {
this.attrs.put(entry.getKey(), toByteArray(entry.getValue()));
}
} else {
this.attrs = null;
}
}
public Map<String, Object> getAttrs() {
return attrs;
public Map<String, Object> getAttrs(ClassLoader classLoader) throws IOException, ClassNotFoundException {
if (attrs == null) {
return null;
}
Map<String, Object> result = new HashMap<String, Object>();
for (Entry<String, byte[]> entry: attrs.entrySet()) {
result.put(entry.getKey(), toObject(classLoader, entry.getValue()));
}
return result;
}
}

@ -15,6 +15,7 @@
*/
package org.redisson.tomcat;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
@ -132,7 +133,11 @@ public class RedissonSession extends StandardSession {
for (Entry<String, Object> entry : newMap.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), map);
try {
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), map);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override
@ -148,7 +153,11 @@ public class RedissonSession extends StandardSession {
private void fastPut(String name, Object value) {
map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value));
try {
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}

@ -136,7 +136,9 @@ public class RedissonSessionManager extends ManagerBase {
}
public RTopic getTopic() {
return redisson.getTopic("redisson:tomcat_session_updates:" + getContext().getName());
String separator = keyPrefix == null || keyPrefix.isEmpty() ? "" : ":";
final String name = keyPrefix + separator + "redisson:tomcat_session_updates:" + getContext().getName();
return redisson.getTopic(name);
}
@Override
@ -207,6 +209,13 @@ public class RedissonSessionManager extends ManagerBase {
super.startInternal();
redisson = buildClient();
final ClassLoader applicationClassLoader;
if (Thread.currentThread().getContextClassLoader() != null) {
applicationClassLoader = Thread.currentThread().getContextClassLoader();
} else {
applicationClassLoader = getClass().getClassLoader();
}
if (updateMode == UpdateMode.AFTER_REQUEST) {
getEngine().getPipeline().addValve(new UpdateValve(this));
}
@ -231,17 +240,17 @@ public class RedissonSessionManager extends ManagerBase {
if (msg instanceof AttributesPutAllMessage) {
AttributesPutAllMessage m = (AttributesPutAllMessage) msg;
for (Entry<String, Object> entry : m.getAttrs().entrySet()) {
for (Entry<String, Object> entry : m.getAttrs(applicationClassLoader).entrySet()) {
session.superSetAttribute(entry.getKey(), entry.getValue(), true);
}
}
if (msg instanceof AttributeUpdateMessage) {
AttributeUpdateMessage m = (AttributeUpdateMessage)msg;
session.superSetAttribute(m.getName(), m.getValue(), true);
session.superSetAttribute(m.getName(), m.getValue(applicationClassLoader), true);
}
}
} catch (IOException e) {
} catch (Exception e) {
log.error("Can't handle topic message", e);
}
}

Loading…
Cancel
Save