diff options
Diffstat (limited to 'juick-api/src/main/java')
-rw-r--r-- | juick-api/src/main/java/com/juick/api/ApiServer.java | 14 |
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(); } } |