From 0ad4b98456e5de96a9fea6e128a20a4624c72c6a Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 10 Oct 2017 11:40:19 +0300 Subject: xmpp: make jids inactive in case of socket exceptions --- .../src/main/java/com/juick/components/XMPPServer.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'juick-xmpp/src/main/java/com/juick/components') diff --git a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java index 29d57d53..de9476a8 100644 --- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java +++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java @@ -18,6 +18,7 @@ package com.juick.components; import com.juick.components.s2s.*; +import com.juick.service.UserService; import com.juick.xmpp.extensions.JuickMessage; import com.juick.xmpp.extensions.StreamError; import org.slf4j.Logger; @@ -37,9 +38,7 @@ import javax.xml.bind.Unmarshaller; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import java.io.*; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketException; +import java.net.*; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.SecureRandom; @@ -100,6 +99,8 @@ public class XMPPServer implements ConnectionListener, AutoCloseable { @Inject private BasicXmppSession session; + @Inject + private UserService userService; @PostConstruct public void init() throws KeyStoreException { @@ -252,6 +253,12 @@ public class XMPPServer implements ConnectionListener, AutoCloseable { addConnectionOut(socket, streamServerDialback); streamServerDialback.addChildParser(new JuickMessage()); streamServerDialback.connect(); + } catch (UnknownHostException | ConnectException e) { + userService.getActiveJIDs().stream().filter(j -> Jid.of(j).getDomain().equals(to)) + .forEach(j -> { + userService.setActiveStatusForJID(j, UserService.ActiveStatus.Inactive); + logger.info("{} is inactive now", j); + }); } catch (Exception e) { logger.error("s2s out error", e); } -- cgit v1.2.3