Fix tomcat session replication issue #1414

pull/1639/head
Yasin Koyuncu 6 years ago
parent 9aee279980
commit 30f361b775

@ -26,15 +26,26 @@ public class AttributeMessage implements Serializable {
private String sessionId;
private String nodeId;
public AttributeMessage() {
}
public AttributeMessage(String sessionId) {
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;
}
}

@ -1,18 +1,11 @@
/**
* 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;
}

@ -1,18 +1,11 @@
/**
* 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;
}

@ -1,18 +1,11 @@
/**
* 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);
}
}

@ -1,18 +1,11 @@
/**
* 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;
@ -33,7 +26,12 @@ public class AttributesPutAllMessage extends AttributeMessage {
super(sessionId);
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,15 +26,26 @@ public class AttributeMessage implements Serializable {
private String sessionId;
private String nodeId;
public AttributeMessage() {
}
public AttributeMessage(String sessionId) {
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;
}
}

@ -1,18 +1,11 @@
/**
* 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;
}

@ -1,18 +1,11 @@
/**
* 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;
}

@ -1,18 +1,11 @@
/**
* 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);
}
}

@ -1,18 +1,11 @@
/**
* 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;
@ -33,7 +26,12 @@ public class AttributesPutAllMessage extends AttributeMessage {
super(sessionId);
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,15 +26,26 @@ public class AttributeMessage implements Serializable {
private String sessionId;
private String nodeId;
public AttributeMessage() {
}
public AttributeMessage(String sessionId) {
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;
}
}

@ -1,18 +1,11 @@
/**
* 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;
}

@ -1,18 +1,11 @@
/**
* 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;
}

@ -1,18 +1,11 @@
/**
* 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);
}
}

@ -1,18 +1,11 @@
/**
* 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;
@ -33,7 +26,12 @@ public class AttributesPutAllMessage extends AttributeMessage {
super(sessionId);
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,15 +26,26 @@ public class AttributeMessage implements Serializable {
private String sessionId;
private String nodeId;
public AttributeMessage() {
}
public AttributeMessage(String sessionId) {
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;
}
}

@ -1,18 +1,11 @@
/**
* 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;
}

@ -1,18 +1,11 @@
/**
* 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;
}

@ -1,18 +1,11 @@
/**
* 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);
}
}

@ -1,18 +1,11 @@
/**
* 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;
@ -33,7 +26,12 @@ public class AttributesPutAllMessage extends AttributeMessage {
super(sessionId);
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);
}

Loading…
Cancel
Save