提交 30f361b7 编写于 作者: Y Yasin Koyuncu

Fix tomcat session replication issue #1414

上级 9aee2799
......@@ -26,6 +26,8 @@ public class AttributeMessage implements Serializable {
private String sessionId;
private String nodeId;
public AttributeMessage() {
}
......@@ -33,8 +35,17 @@ public class AttributeMessage implements Serializable {
this.sessionId = sessionId;
}
public AttributeMessage(String nodeId, String sessionId) {
this.nodeId = nodeId;
this.sessionId = sessionId;
}
public String getSessionId() {
return sessionId;
}
public String getNodeId() {
return nodeId;
}
}
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
/**
......@@ -33,6 +26,11 @@ public class AttributeRemoveMessage extends AttributeMessage {
this.name = name;
}
public AttributeRemoveMessage(String nodeId, String sessionId, String name) {
super(nodeId, sessionId);
this.name = name;
}
public String getName() {
return name;
}
......
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
/**
......@@ -34,6 +27,12 @@ public class AttributeUpdateMessage extends AttributeMessage {
this.value = value;
}
public AttributeUpdateMessage(String nodeId, String sessionId, String name, Object value) {
super(nodeId, sessionId);
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
......
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
/**
......@@ -29,4 +22,8 @@ public class AttributesClearMessage extends AttributeMessage {
super(sessionId);
}
public AttributesClearMessage(String nodeId, String sessionId) {
super(nodeId, sessionId);
}
}
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
import java.util.Map;
......@@ -34,6 +27,11 @@ public class AttributesPutAllMessage extends AttributeMessage {
this.attrs = attrs;
}
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs) {
super(nodeId, sessionId);
this.attrs = attrs;
}
public Map<String, Object> getAttrs() {
return attrs;
}
......
......@@ -90,7 +90,7 @@ public class RedissonSession extends StandardSession {
public void delete() {
map.delete();
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributesClearMessage(getId()));
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));
}
map = null;
}
......@@ -134,7 +134,7 @@ public class RedissonSession extends StandardSession {
for (Entry<String, Object> entry : newMap.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return new AttributesPutAllMessage(getId(), map);
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), map);
}
@Override
......@@ -152,7 +152,7 @@ public class RedissonSession extends StandardSession {
private void fastPut(String name, Object value) {
map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributeUpdateMessage(getId(), name, value));
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value));
}
}
......@@ -212,7 +212,7 @@ public class RedissonSession extends StandardSession {
if (updateMode == UpdateMode.DEFAULT && map != null) {
map.fastRemove(name);
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributeRemoveMessage(getId(), name));
topic.publish(new AttributeRemoveMessage(redissonManager.getNodeId(), getId(), name));
}
}
}
......
......@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import javax.servlet.http.HttpSession;
......@@ -61,6 +62,10 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
private UpdateMode updateMode = UpdateMode.DEFAULT;
private String keyPrefix = "";
private final String nodeId = UUID.randomUUID().toString();
public String getNodeId() { return nodeId; }
public String getUpdateMode() {
return updateMode.toString();
}
......@@ -225,7 +230,7 @@ public class RedissonSessionManager extends ManagerBase implements Lifecycle {
try {
// TODO make it thread-safe
RedissonSession session = (RedissonSession) RedissonSessionManager.super.findSession(msg.getSessionId());
if (session != null) {
if (session != null && !msg.getNodeId().equals(nodeId)) {
if (msg instanceof AttributeRemoveMessage) {
session.superRemoveAttributeInternal(((AttributeRemoveMessage)msg).getName(), true);
}
......
......@@ -26,6 +26,8 @@ public class AttributeMessage implements Serializable {
private String sessionId;
private String nodeId;
public AttributeMessage() {
}
......@@ -33,8 +35,17 @@ public class AttributeMessage implements Serializable {
this.sessionId = sessionId;
}
public AttributeMessage(String nodeId, String sessionId) {
this.nodeId = nodeId;
this.sessionId = sessionId;
}
public String getSessionId() {
return sessionId;
}
public String getNodeId() {
return nodeId;
}
}
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
/**
......@@ -33,6 +26,11 @@ public class AttributeRemoveMessage extends AttributeMessage {
this.name = name;
}
public AttributeRemoveMessage(String nodeId, String sessionId, String name) {
super(nodeId, sessionId);
this.name = name;
}
public String getName() {
return name;
}
......
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
/**
......@@ -34,6 +27,12 @@ public class AttributeUpdateMessage extends AttributeMessage {
this.value = value;
}
public AttributeUpdateMessage(String nodeId, String sessionId, String name, Object value) {
super(nodeId, sessionId);
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
......
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
/**
......@@ -29,4 +22,8 @@ public class AttributesClearMessage extends AttributeMessage {
super(sessionId);
}
public AttributesClearMessage(String nodeId, String sessionId) {
super(nodeId, sessionId);
}
}
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
import java.util.Map;
......@@ -34,6 +27,11 @@ public class AttributesPutAllMessage extends AttributeMessage {
this.attrs = attrs;
}
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs) {
super(nodeId, sessionId);
this.attrs = attrs;
}
public Map<String, Object> getAttrs() {
return attrs;
}
......
......@@ -90,7 +90,7 @@ public class RedissonSession extends StandardSession {
public void delete() {
map.delete();
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributesClearMessage(getId()));
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));
}
map = null;
}
......@@ -134,7 +134,7 @@ public class RedissonSession extends StandardSession {
for (Entry<String, Object> entry : newMap.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return new AttributesPutAllMessage(getId(), map);
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), map);
}
@Override
......@@ -152,7 +152,7 @@ public class RedissonSession extends StandardSession {
private void fastPut(String name, Object value) {
map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributeUpdateMessage(getId(), name, value));
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value));
}
}
......@@ -212,7 +212,7 @@ public class RedissonSession extends StandardSession {
if (updateMode == UpdateMode.DEFAULT && map != null) {
map.fastRemove(name);
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributeRemoveMessage(getId(), name));
topic.publish(new AttributeRemoveMessage(redissonManager.getNodeId(), getId(), name));
}
}
}
......
......@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import javax.servlet.http.HttpSession;
......@@ -59,6 +60,10 @@ public class RedissonSessionManager extends ManagerBase {
private String keyPrefix = "";
private final String nodeId = UUID.randomUUID().toString();
public String getNodeId() { return nodeId; }
public String getUpdateMode() {
return updateMode.toString();
}
......@@ -205,7 +210,7 @@ public class RedissonSessionManager extends ManagerBase {
try {
// TODO make it thread-safe
RedissonSession session = (RedissonSession) RedissonSessionManager.super.findSession(msg.getSessionId());
if (session != null) {
if (session != null && !msg.getNodeId().equals(nodeId)) {
if (msg instanceof AttributeRemoveMessage) {
session.superRemoveAttributeInternal(((AttributeRemoveMessage)msg).getName(), true);
}
......
......@@ -26,6 +26,8 @@ public class AttributeMessage implements Serializable {
private String sessionId;
private String nodeId;
public AttributeMessage() {
}
......@@ -33,8 +35,17 @@ public class AttributeMessage implements Serializable {
this.sessionId = sessionId;
}
public AttributeMessage(String nodeId, String sessionId) {
this.nodeId = nodeId;
this.sessionId = sessionId;
}
public String getSessionId() {
return sessionId;
}
public String getNodeId() {
return nodeId;
}
}
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
/**
......@@ -33,6 +26,11 @@ public class AttributeRemoveMessage extends AttributeMessage {
this.name = name;
}
public AttributeRemoveMessage(String nodeId, String sessionId, String name) {
super(nodeId, sessionId);
this.name = name;
}
public String getName() {
return name;
}
......
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
/**
......@@ -34,6 +27,12 @@ public class AttributeUpdateMessage extends AttributeMessage {
this.value = value;
}
public AttributeUpdateMessage(String nodeId, String sessionId, String name, Object value) {
super(nodeId, sessionId);
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
......
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
/**
......@@ -29,4 +22,8 @@ public class AttributesClearMessage extends AttributeMessage {
super(sessionId);
}
public AttributesClearMessage(String nodeId, String sessionId) {
super(nodeId, sessionId);
}
}
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
import java.util.Map;
......@@ -34,6 +27,11 @@ public class AttributesPutAllMessage extends AttributeMessage {
this.attrs = attrs;
}
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs) {
super(nodeId, sessionId);
this.attrs = attrs;
}
public Map<String, Object> getAttrs() {
return attrs;
}
......
......@@ -90,7 +90,7 @@ public class RedissonSession extends StandardSession {
public void delete() {
map.delete();
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributesClearMessage(getId()));
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));
}
map = null;
}
......@@ -134,7 +134,7 @@ public class RedissonSession extends StandardSession {
for (Entry<String, Object> entry : newMap.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return new AttributesPutAllMessage(getId(), map);
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), map);
}
@Override
......@@ -152,7 +152,7 @@ public class RedissonSession extends StandardSession {
private void fastPut(String name, Object value) {
map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributeUpdateMessage(getId(), name, value));
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value));
}
}
......@@ -212,7 +212,7 @@ public class RedissonSession extends StandardSession {
if (updateMode == UpdateMode.DEFAULT && map != null) {
map.fastRemove(name);
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributeRemoveMessage(getId(), name));
topic.publish(new AttributeRemoveMessage(redissonManager.getNodeId(), getId(), name));
}
}
}
......
......@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import javax.servlet.http.HttpSession;
......@@ -58,6 +59,10 @@ public class RedissonSessionManager extends ManagerBase {
private String keyPrefix = "";
private final String nodeId = UUID.randomUUID().toString();
public String getNodeId() { return nodeId; }
public String getUpdateMode() {
return updateMode.toString();
}
......@@ -204,7 +209,7 @@ public class RedissonSessionManager extends ManagerBase {
try {
// TODO make it thread-safe
RedissonSession session = (RedissonSession) RedissonSessionManager.super.findSession(msg.getSessionId());
if (session != null) {
if (session != null && !msg.getNodeId().equals(nodeId)) {
if (msg instanceof AttributeRemoveMessage) {
session.superRemoveAttributeInternal(((AttributeRemoveMessage)msg).getName(), true);
}
......
......@@ -26,6 +26,8 @@ public class AttributeMessage implements Serializable {
private String sessionId;
private String nodeId;
public AttributeMessage() {
}
......@@ -33,8 +35,17 @@ public class AttributeMessage implements Serializable {
this.sessionId = sessionId;
}
public AttributeMessage(String nodeId, String sessionId) {
this.nodeId = nodeId;
this.sessionId = sessionId;
}
public String getSessionId() {
return sessionId;
}
public String getNodeId() {
return nodeId;
}
}
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
/**
......@@ -33,6 +26,11 @@ public class AttributeRemoveMessage extends AttributeMessage {
this.name = name;
}
public AttributeRemoveMessage(String nodeId, String sessionId, String name) {
super(nodeId, sessionId);
this.name = name;
}
public String getName() {
return name;
}
......
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
/**
......@@ -34,6 +27,12 @@ public class AttributeUpdateMessage extends AttributeMessage {
this.value = value;
}
public AttributeUpdateMessage(String nodeId, String sessionId, String name, Object value) {
super(nodeId, sessionId);
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
......
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
/**
......@@ -29,4 +22,8 @@ public class AttributesClearMessage extends AttributeMessage {
super(sessionId);
}
public AttributesClearMessage(String nodeId, String sessionId) {
super(nodeId, sessionId);
}
}
/**
* Copyright 2018 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright (c) 2018. Engie-Electrabel. All rights reserved.
//
// Engie-Electrabel n.v./s.a., Simon Bolivarlaan 34 Boulevard Simón Bolivar, BTW BE 0403.107.701 - 1000 Brussel/Bruxelles, Belgium.
//
// Proprietary Notice:
// This software is the confidential and proprietary information of Engie-Electrabel s.a./n.v. and/or its licensors.
// You shall not disclose this Confidential Information to any third parties and any use thereof shall be subject to the terms and conditions of use, as agreed upon with Engie-Electrabel in writing.
//
package org.redisson.tomcat;
import java.util.Map;
......@@ -34,6 +27,11 @@ public class AttributesPutAllMessage extends AttributeMessage {
this.attrs = attrs;
}
public AttributesPutAllMessage(String nodeId, String sessionId, Map<String, Object> attrs) {
super(nodeId, sessionId);
this.attrs = attrs;
}
public Map<String, Object> getAttrs() {
return attrs;
}
......
......@@ -90,7 +90,7 @@ public class RedissonSession extends StandardSession {
public void delete() {
map.delete();
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributesClearMessage(getId()));
topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));
}
map = null;
}
......@@ -134,7 +134,7 @@ public class RedissonSession extends StandardSession {
for (Entry<String, Object> entry : newMap.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return new AttributesPutAllMessage(getId(), map);
return new AttributesPutAllMessage(redissonManager.getNodeId(), getId(), map);
}
@Override
......@@ -152,7 +152,7 @@ public class RedissonSession extends StandardSession {
private void fastPut(String name, Object value) {
map.fastPut(name, value);
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributeUpdateMessage(getId(), name, value));
topic.publish(new AttributeUpdateMessage(redissonManager.getNodeId(), getId(), name, value));
}
}
......@@ -212,7 +212,7 @@ public class RedissonSession extends StandardSession {
if (updateMode == UpdateMode.DEFAULT && map != null) {
map.fastRemove(name);
if (readMode == ReadMode.MEMORY) {
topic.publish(new AttributeRemoveMessage(getId(), name));
topic.publish(new AttributeRemoveMessage(redissonManager.getNodeId(), getId(), name));
}
}
}
......
......@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import javax.servlet.http.HttpSession;
......@@ -58,6 +59,10 @@ public class RedissonSessionManager extends ManagerBase {
private String keyPrefix = "";
private final String nodeId = UUID.randomUUID().toString();
public String getNodeId() { return nodeId; }
public String getUpdateMode() {
return updateMode.toString();
}
......@@ -204,7 +209,7 @@ public class RedissonSessionManager extends ManagerBase {
try {
// TODO make it thread-safe
RedissonSession session = (RedissonSession) RedissonSessionManager.super.findSession(msg.getSessionId());
if (session != null) {
if (session != null && !msg.getNodeId().equals(nodeId)) {
if (msg instanceof AttributeRemoveMessage) {
session.superRemoveAttributeInternal(((AttributeRemoveMessage)msg).getName(), true);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册