Răsfoiți Sursa

update heartbeat seconds

Signed-off-by: AE86 <836391306@qq.com>
AE86 1 an în urmă
părinte
comite
56719ae162

+ 10 - 8
dbsyncer-listener/src/main/java/org/dbsyncer/listener/mysql/BinaryLogRemoteClient.java

@@ -152,6 +152,7 @@ public class BinaryLogRemoteClient implements BinaryLogClient {
             try {
             try {
                 connectLock.lock();
                 connectLock.lock();
                 closeChannel(channel);
                 closeChannel(channel);
+                connected = false;
                 if (null != this.worker && !worker.isInterrupted()) {
                 if (null != this.worker && !worker.isInterrupted()) {
                     this.worker.interrupt();
                     this.worker.interrupt();
                     this.worker = null;
                     this.worker = null;
@@ -160,7 +161,6 @@ public class BinaryLogRemoteClient implements BinaryLogClient {
                     this.keepAlive.interrupt();
                     this.keepAlive.interrupt();
                     this.keepAlive = null;
                     this.keepAlive = null;
                 }
                 }
-                connected = false;
                 lifecycleListeners.forEach(listener -> listener.onDisconnect(this));
                 lifecycleListeners.forEach(listener -> listener.onDisconnect(this));
             } finally {
             } finally {
                 connectLock.unlock();
                 connectLock.unlock();
@@ -613,7 +613,7 @@ public class BinaryLogRemoteClient implements BinaryLogClient {
     }
     }
 
 
     private void spawnKeepAliveThread() {
     private void spawnKeepAliveThread() {
-        long keepAliveInterval = TimeUnit.MINUTES.toMillis(1);
+        long keepAliveInterval = TimeUnit.SECONDS.toMillis(30);
         String clientId = createClientId();
         String clientId = createClientId();
         this.keepAlive = new Thread(() -> {
         this.keepAlive = new Thread(() -> {
             while (connected) {
             while (connected) {
@@ -629,12 +629,14 @@ public class BinaryLogRemoteClient implements BinaryLogClient {
                     connectionLost = true;
                     connectionLost = true;
                 }
                 }
                 if (connectionLost) {
                 if (connectionLost) {
-                    String error = String.format("keepalive: Trying to restore lost connection to %s", clientId);
-                    logger.info(error);
-                    try {
-                        lifecycleListeners.forEach(listener -> listener.onCommunicationFailure(this, new ListenerException(error)));
-                    } catch (Exception e) {
-                        logger.warn("keepalive error", e);
+                    if (connected) {
+                        String error = String.format("keepalive: Trying to restore lost connection to %s", clientId);
+                        logger.info(error);
+                        try {
+                            lifecycleListeners.forEach(listener -> listener.onCommunicationFailure(this, new ListenerException(error)));
+                        } catch (Exception e) {
+                            logger.warn("keepalive error", e);
+                        }
                     }
                     }
                     break;
                     break;
                 }
                 }