From 8b48db63341bb0edf2273cb9f0bbdc8f84553bb7 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 2 Nov 2017 14:39:19 +0300 Subject: api: schedule ws reconnection --- juick-api/src/main/java/com/juick/api/ApiServer.java | 14 ++++++++++---- 1 file 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, 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(); } } -- cgit v1.2.3