aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-11-02 14:39:19 +0300
committerGravatar Vitaly Takmazov2017-11-02 14:39:19 +0300
commit8b48db63341bb0edf2273cb9f0bbdc8f84553bb7 (patch)
treeeb94d639000d77a6942e19c5ec341b040a9a4a85
parenta77f62ebf2f1635eec891b21a3ced6d7a4511db6 (diff)
api: schedule ws reconnection
-rw-r--r--juick-api/src/main/java/com/juick/api/ApiServer.java14
1 files changed, 10 insertions, 4 deletions
diff --git a/juick-api/src/main/java/com/juick/api/ApiServer.java b/juick-api/src/main/java/com/juick/api/ApiServer.java
index d5324319..83e21e22 100644
--- a/juick-api/src/main/java/com/juick/api/ApiServer.java
+++ b/juick-api/src/main/java/com/juick/api/ApiServer.java
@@ -23,6 +23,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
+import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.socket.client.WebSocketConnectionManager;
import rocks.xmpp.addr.Jid;
import rocks.xmpp.core.XmppException;
@@ -113,11 +114,16 @@ public class ApiServer implements ApplicationListener<DisconnectedEvent>, AutoCl
logger.warn("attachment error", e1);
}
}
-
+ @Scheduled(fixedRate = 60000)
+ public void reconnectWebsocket() {
+ if (!webSocketConnectionManager.isRunning()) {
+ logger.info("retrying...");
+ webSocketConnectionManager.stop();
+ webSocketConnectionManager.start();
+ }
+ }
@Override
public void onApplicationEvent(@Nonnull DisconnectedEvent event) {
- logger.info("reloading app...");
- webSocketConnectionManager.stop();
- webSocketConnectionManager.start();
+ reconnectWebsocket();
}
}