提交 ac83c953 编写于 作者: N Nikita Koksharov

Feature - broadcastSessionUpdates setting added to Tomcat Session Manager. #3596

上级 ee20d528
......@@ -71,14 +71,16 @@ public class RedissonSession extends StandardSession {
private Set<String> removedAttributes = Collections.emptySet();
private final boolean broadcastSessionEvents;
private final boolean broadcastSessionUpdates;
public RedissonSession(RedissonSessionManager manager, ReadMode readMode, UpdateMode updateMode, boolean broadcastSessionEvents) {
public RedissonSession(RedissonSessionManager manager, ReadMode readMode, UpdateMode updateMode, boolean broadcastSessionEvents, boolean broadcastSessionUpdates) {
super(manager);
this.redissonManager = manager;
this.readMode = readMode;
this.updateMode = updateMode;
this.topic = redissonManager.getTopic();
this.broadcastSessionEvents = broadcastSessionEvents;
this.broadcastSessionUpdates = broadcastSessionUpdates;
if (updateMode == UpdateMode.AFTER_REQUEST) {
removedAttributes = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
......@@ -183,7 +185,7 @@ public class RedissonSession extends StandardSession {
} else {
map.delete();
}
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));
}
map = null;
......@@ -201,7 +203,7 @@ public class RedissonSession extends StandardSession {
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(createPutAllMessage(newMap));
}
}
......@@ -253,7 +255,7 @@ public class RedissonSession extends StandardSession {
return;
}
map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
try {
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, this.map.getCodec().getMapValueEncoder()));
} catch (IOException e) {
......@@ -319,7 +321,7 @@ public class RedissonSession extends StandardSession {
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(createPutAllMessage(newMap));
}
expireSession();
......@@ -376,7 +378,7 @@ public class RedissonSession extends StandardSession {
private void removeRedisAttribute(String name) {
if (updateMode == UpdateMode.DEFAULT && map != null) {
map.fastRemove(name);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(new AttributeRemoveMessage(redissonManager.getNodeId(), getId(), new HashSet<String>(Arrays.asList(name))));
}
}
......@@ -425,7 +427,7 @@ public class RedissonSession extends StandardSession {
map.putAll(newMap);
map.fastRemove(removedAttributes.toArray(new String[0]));
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(createPutAllMessage(newMap));
if (updateMode == UpdateMode.AFTER_REQUEST) {
......
......@@ -48,14 +48,15 @@ public class RedissonSessionManager extends ManagerBase {
private final Log log = LogFactory.getLog(RedissonSessionManager.class);
private RedissonClient redisson;
protected RedissonClient redisson;
private String configPath;
private ReadMode readMode = ReadMode.REDIS;
private UpdateMode updateMode = UpdateMode.DEFAULT;
private String keyPrefix = "";
protected String keyPrefix = "";
private boolean broadcastSessionEvents = false;
private boolean broadcastSessionUpdates = true;
private final String nodeId = UUID.randomUUID().toString();
......@@ -80,7 +81,15 @@ public class RedissonSessionManager extends ManagerBase {
public void setBroadcastSessionEvents(boolean replicateSessionEvents) {
this.broadcastSessionEvents = replicateSessionEvents;
}
public boolean isBroadcastSessionUpdates() {
return broadcastSessionUpdates;
}
public void setBroadcastSessionUpdates(boolean broadcastSessionUpdates) {
this.broadcastSessionUpdates = broadcastSessionUpdates;
}
public String getReadMode() {
return readMode.toString();
}
......@@ -194,7 +203,7 @@ public class RedissonSessionManager extends ManagerBase {
@Override
public Session createEmptySession() {
return new RedissonSession(this, readMode, updateMode, broadcastSessionEvents);
return new RedissonSession(this, readMode, updateMode, broadcastSessionEvents, this.broadcastSessionUpdates);
}
@Override
......@@ -259,7 +268,7 @@ public class RedissonSessionManager extends ManagerBase {
}
}
if (readMode == ReadMode.MEMORY || broadcastSessionEvents) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || broadcastSessionEvents) {
RTopic updatesTopic = getTopic();
messageListener = new MessageListener<AttributeMessage>() {
......
......@@ -71,14 +71,16 @@ public class RedissonSession extends StandardSession {
private Set<String> removedAttributes = Collections.emptySet();
private final boolean broadcastSessionEvents;
private final boolean broadcastSessionUpdates;
public RedissonSession(RedissonSessionManager manager, ReadMode readMode, UpdateMode updateMode, boolean broadcastSessionEvents) {
public RedissonSession(RedissonSessionManager manager, ReadMode readMode, UpdateMode updateMode, boolean broadcastSessionEvents, boolean broadcastSessionUpdates) {
super(manager);
this.redissonManager = manager;
this.readMode = readMode;
this.updateMode = updateMode;
this.topic = redissonManager.getTopic();
this.broadcastSessionEvents = broadcastSessionEvents;
this.broadcastSessionUpdates = broadcastSessionUpdates;
if (updateMode == UpdateMode.AFTER_REQUEST) {
removedAttributes = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
......@@ -183,7 +185,7 @@ public class RedissonSession extends StandardSession {
} else {
map.delete();
}
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));
}
map = null;
......@@ -201,7 +203,7 @@ public class RedissonSession extends StandardSession {
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(createPutAllMessage(newMap));
}
}
......@@ -253,7 +255,7 @@ public class RedissonSession extends StandardSession {
return;
}
map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
try {
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, this.map.getCodec().getMapValueEncoder()));
} catch (IOException e) {
......@@ -319,7 +321,7 @@ public class RedissonSession extends StandardSession {
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(createPutAllMessage(newMap));
}
expireSession();
......@@ -399,7 +401,7 @@ public class RedissonSession extends StandardSession {
private void removeRedisAttribute(String name) {
if (updateMode == UpdateMode.DEFAULT && map != null) {
map.fastRemove(name);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(new AttributeRemoveMessage(redissonManager.getNodeId(), getId(), new HashSet<String>(Arrays.asList(name))));
}
}
......@@ -448,7 +450,7 @@ public class RedissonSession extends StandardSession {
map.putAll(newMap);
map.fastRemove(removedAttributes.toArray(new String[0]));
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(createPutAllMessage(newMap));
if (updateMode == UpdateMode.AFTER_REQUEST) {
......
......@@ -48,14 +48,15 @@ public class RedissonSessionManager extends ManagerBase {
private final Log log = LogFactory.getLog(RedissonSessionManager.class);
private RedissonClient redisson;
protected RedissonClient redisson;
private String configPath;
private ReadMode readMode = ReadMode.REDIS;
private UpdateMode updateMode = UpdateMode.DEFAULT;
private String keyPrefix = "";
protected String keyPrefix = "";
private boolean broadcastSessionEvents = false;
private boolean broadcastSessionUpdates = true;
private final String nodeId = UUID.randomUUID().toString();
......@@ -80,7 +81,15 @@ public class RedissonSessionManager extends ManagerBase {
public void setBroadcastSessionEvents(boolean replicateSessionEvents) {
this.broadcastSessionEvents = replicateSessionEvents;
}
public boolean isBroadcastSessionUpdates() {
return broadcastSessionUpdates;
}
public void setBroadcastSessionUpdates(boolean broadcastSessionUpdates) {
this.broadcastSessionUpdates = broadcastSessionUpdates;
}
public String getReadMode() {
return readMode.toString();
}
......@@ -194,7 +203,7 @@ public class RedissonSessionManager extends ManagerBase {
@Override
public Session createEmptySession() {
return new RedissonSession(this, readMode, updateMode, broadcastSessionEvents);
return new RedissonSession(this, readMode, updateMode, broadcastSessionEvents, this.broadcastSessionUpdates);
}
@Override
......@@ -259,7 +268,7 @@ public class RedissonSessionManager extends ManagerBase {
}
}
if (readMode == ReadMode.MEMORY || broadcastSessionEvents) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || broadcastSessionEvents) {
RTopic updatesTopic = getTopic();
messageListener = new MessageListener<AttributeMessage>() {
......
......@@ -71,14 +71,16 @@ public class RedissonSession extends StandardSession {
private Set<String> removedAttributes = Collections.emptySet();
private final boolean broadcastSessionEvents;
private final boolean broadcastSessionUpdates;
public RedissonSession(RedissonSessionManager manager, ReadMode readMode, UpdateMode updateMode, boolean broadcastSessionEvents) {
public RedissonSession(RedissonSessionManager manager, ReadMode readMode, UpdateMode updateMode, boolean broadcastSessionEvents, boolean broadcastSessionUpdates) {
super(manager);
this.redissonManager = manager;
this.readMode = readMode;
this.updateMode = updateMode;
this.topic = redissonManager.getTopic();
this.broadcastSessionEvents = broadcastSessionEvents;
this.broadcastSessionUpdates = broadcastSessionUpdates;
if (updateMode == UpdateMode.AFTER_REQUEST) {
removedAttributes = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
......@@ -183,7 +185,7 @@ public class RedissonSession extends StandardSession {
} else {
map.delete();
}
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));
}
map = null;
......@@ -201,7 +203,7 @@ public class RedissonSession extends StandardSession {
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(createPutAllMessage(newMap));
}
}
......@@ -253,7 +255,7 @@ public class RedissonSession extends StandardSession {
return;
}
map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
try {
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, this.map.getCodec().getMapValueEncoder()));
} catch (IOException e) {
......@@ -319,7 +321,7 @@ public class RedissonSession extends StandardSession {
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(createPutAllMessage(newMap));
}
expireSession();
......@@ -376,7 +378,7 @@ public class RedissonSession extends StandardSession {
private void removeRedisAttribute(String name) {
if (updateMode == UpdateMode.DEFAULT && map != null) {
map.fastRemove(name);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(new AttributeRemoveMessage(redissonManager.getNodeId(), getId(), new HashSet<String>(Arrays.asList(name))));
}
}
......@@ -425,7 +427,7 @@ public class RedissonSession extends StandardSession {
map.putAll(newMap);
map.fastRemove(removedAttributes.toArray(new String[0]));
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(createPutAllMessage(newMap));
if (updateMode == UpdateMode.AFTER_REQUEST) {
......
......@@ -48,14 +48,15 @@ public class RedissonSessionManager extends ManagerBase {
private final Log log = LogFactory.getLog(RedissonSessionManager.class);
private RedissonClient redisson;
protected RedissonClient redisson;
private String configPath;
private ReadMode readMode = ReadMode.REDIS;
private UpdateMode updateMode = UpdateMode.DEFAULT;
private String keyPrefix = "";
protected String keyPrefix = "";
private boolean broadcastSessionEvents = false;
private boolean broadcastSessionUpdates = true;
private final String nodeId = UUID.randomUUID().toString();
......@@ -80,7 +81,15 @@ public class RedissonSessionManager extends ManagerBase {
public void setBroadcastSessionEvents(boolean replicateSessionEvents) {
this.broadcastSessionEvents = replicateSessionEvents;
}
public boolean isBroadcastSessionUpdates() {
return broadcastSessionUpdates;
}
public void setBroadcastSessionUpdates(boolean broadcastSessionUpdates) {
this.broadcastSessionUpdates = broadcastSessionUpdates;
}
public String getReadMode() {
return readMode.toString();
}
......@@ -194,7 +203,7 @@ public class RedissonSessionManager extends ManagerBase {
@Override
public Session createEmptySession() {
return new RedissonSession(this, readMode, updateMode, broadcastSessionEvents);
return new RedissonSession(this, readMode, updateMode, broadcastSessionEvents, this.broadcastSessionUpdates);
}
@Override
......@@ -259,7 +268,7 @@ public class RedissonSessionManager extends ManagerBase {
}
}
if (readMode == ReadMode.MEMORY || broadcastSessionEvents) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || broadcastSessionEvents) {
RTopic updatesTopic = getTopic();
messageListener = new MessageListener<AttributeMessage>() {
......@@ -354,7 +363,7 @@ public class RedissonSessionManager extends ManagerBase {
super.stopInternal();
setState(LifecycleState.STOPPING);
Pipeline pipeline = getContext().getPipeline();
synchronized (pipeline) {
if (readMode == ReadMode.REDIS) {
......
......@@ -71,14 +71,16 @@ public class RedissonSession extends StandardSession {
private Set<String> removedAttributes = Collections.emptySet();
private final boolean broadcastSessionEvents;
private final boolean broadcastSessionUpdates;
public RedissonSession(RedissonSessionManager manager, ReadMode readMode, UpdateMode updateMode, boolean broadcastSessionEvents) {
public RedissonSession(RedissonSessionManager manager, ReadMode readMode, UpdateMode updateMode, boolean broadcastSessionEvents, boolean broadcastSessionUpdates) {
super(manager);
this.redissonManager = manager;
this.readMode = readMode;
this.updateMode = updateMode;
this.topic = redissonManager.getTopic();
this.broadcastSessionEvents = broadcastSessionEvents;
this.broadcastSessionUpdates = broadcastSessionUpdates;
if (updateMode == UpdateMode.AFTER_REQUEST) {
removedAttributes = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
......@@ -183,7 +185,7 @@ public class RedissonSession extends StandardSession {
} else {
map.delete();
}
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));
}
map = null;
......@@ -201,7 +203,7 @@ public class RedissonSession extends StandardSession {
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(createPutAllMessage(newMap));
}
}
......@@ -253,7 +255,7 @@ public class RedissonSession extends StandardSession {
return;
}
map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
try {
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value, this.map.getCodec().getMapValueEncoder()));
} catch (IOException e) {
......@@ -319,7 +321,7 @@ public class RedissonSession extends StandardSession {
newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime);
newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime);
map.putAll(newMap);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(createPutAllMessage(newMap));
}
expireSession();
......@@ -376,7 +378,7 @@ public class RedissonSession extends StandardSession {
private void removeRedisAttribute(String name) {
if (updateMode == UpdateMode.DEFAULT && map != null) {
map.fastRemove(name);
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(new AttributeRemoveMessage(redissonManager.getNodeId(), getId(), new HashSet<String>(Arrays.asList(name))));
}
}
......@@ -425,7 +427,7 @@ public class RedissonSession extends StandardSession {
map.putAll(newMap);
map.fastRemove(removedAttributes.toArray(new String[0]));
if (readMode == ReadMode.MEMORY) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates) {
topic.publish(createPutAllMessage(newMap));
if (updateMode == UpdateMode.AFTER_REQUEST) {
......
......@@ -48,14 +48,15 @@ public class RedissonSessionManager extends ManagerBase {
private final Log log = LogFactory.getLog(RedissonSessionManager.class);
private RedissonClient redisson;
protected RedissonClient redisson;
private String configPath;
private ReadMode readMode = ReadMode.REDIS;
private UpdateMode updateMode = UpdateMode.DEFAULT;
private String keyPrefix = "";
protected String keyPrefix = "";
private boolean broadcastSessionEvents = false;
private boolean broadcastSessionUpdates = true;
private final String nodeId = UUID.randomUUID().toString();
......@@ -80,7 +81,15 @@ public class RedissonSessionManager extends ManagerBase {
public void setBroadcastSessionEvents(boolean replicateSessionEvents) {
this.broadcastSessionEvents = replicateSessionEvents;
}
public boolean isBroadcastSessionUpdates() {
return broadcastSessionUpdates;
}
public void setBroadcastSessionUpdates(boolean broadcastSessionUpdates) {
this.broadcastSessionUpdates = broadcastSessionUpdates;
}
public String getReadMode() {
return readMode.toString();
}
......@@ -194,7 +203,7 @@ public class RedissonSessionManager extends ManagerBase {
@Override
public Session createEmptySession() {
return new RedissonSession(this, readMode, updateMode, broadcastSessionEvents);
return new RedissonSession(this, readMode, updateMode, broadcastSessionEvents, this.broadcastSessionUpdates);
}
@Override
......@@ -259,7 +268,7 @@ public class RedissonSessionManager extends ManagerBase {
}
}
if (readMode == ReadMode.MEMORY || broadcastSessionEvents) {
if (readMode == ReadMode.MEMORY && this.broadcastSessionUpdates || broadcastSessionEvents) {
RTopic updatesTopic = getTopic();
messageListener = new MessageListener<AttributeMessage>() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册