From e5d1e1966618f5a4a45b0b0a7647ab3f91436b6c Mon Sep 17 00:00:00 2001 From: bjxiaojian Date: Mon, 12 Oct 2020 17:55:02 +0800 Subject: [PATCH] session disconnect delay configurable (#141) --- .../data/bootstrap/DataServerConfig.java | 20 +++++++++++++++++++ .../SessionServerConnectionFactory.java | 7 +++++-- .../src/main/resources/application.properties | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/bootstrap/DataServerConfig.java b/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/bootstrap/DataServerConfig.java index f81deebf5..2b9c8306b 100644 --- a/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/bootstrap/DataServerConfig.java +++ b/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/bootstrap/DataServerConfig.java @@ -123,6 +123,8 @@ public class DataServerConfig { private int dataSyncNotifyRetry = 3; + private int sessionDisconnectDelayMs = 30000; + /** * constructor * @param commonConfig @@ -848,6 +850,24 @@ public void setDataSyncNotifyRetry(int dataSyncNotifyRetry) { this.dataSyncNotifyRetry = dataSyncNotifyRetry; } + /** + * Getter method for property sessionDisconnectDelayMs. + * + * @return property value of sessionDisconnectDelayMs + */ + public int getSessionDisconnectDelayMs() { + return sessionDisconnectDelayMs; + } + + /** + * Setter method for property sessionDisconnectDelayMs. + * + * @param sessionDisconnectDelayMs value to be assigned to property sessionDisconnectDelayMs + */ + public void setSessionDisconnectDelayMs(int sessionDisconnectDelayMs) { + this.sessionDisconnectDelayMs = sessionDisconnectDelayMs; + } + @Override public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); diff --git a/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/remoting/sessionserver/SessionServerConnectionFactory.java b/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/remoting/sessionserver/SessionServerConnectionFactory.java index 7c8a76901..b3384d4dd 100644 --- a/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/remoting/sessionserver/SessionServerConnectionFactory.java +++ b/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/remoting/sessionserver/SessionServerConnectionFactory.java @@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; +import com.alipay.sofa.registry.server.data.bootstrap.DataServerConfig; import org.springframework.beans.factory.annotation.Autowired; import com.alipay.remoting.Connection; @@ -45,7 +46,6 @@ public class SessionServerConnectionFactory { private static final Logger LOGGER = LoggerFactory .getLogger(SessionServerConnectionFactory.class); - private static final int DELAY = 30 * 1000; private static final Map EMPTY_MAP = new HashMap(0); /** @@ -69,6 +69,9 @@ public class SessionServerConnectionFactory { @Autowired private DisconnectEventHandler disconnectEventHandler; + @Autowired + private DataServerConfig dataServerConfig; + /** * register connection * @@ -125,7 +128,7 @@ public void sessionDisconnected(String sessionConnAddress) { // The SessionServerDisconnectEvent is triggered only when the last connection is broken if (pair == null || pair.getConnections().isEmpty()) { disconnectEventHandler.receive(new SessionServerDisconnectEvent(processId, - sessionConnAddress, DELAY)); + sessionConnAddress, dataServerConfig.getSessionDisconnectDelayMs())); } } } diff --git a/server/server/data/src/main/resources/application.properties b/server/server/data/src/main/resources/application.properties index a65d7295f..c0338550a 100644 --- a/server/server/data/src/main/resources/application.properties +++ b/server/server/data/src/main/resources/application.properties @@ -17,4 +17,5 @@ data.server.metaServerPort=9611 data.server.storeNodes=3 data.server.numberOfReplicas=1000 data.server.datumTimeToLiveSec=900 +data.server.sessionDisconnectDelayMs=30000