diff options
Diffstat (limited to 'juick-xmpp/src/main/java/com/juick/components/XMPPServer.java')
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/XMPPServer.java | 36 |
1 files changed, 23 insertions, 13 deletions
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 ac2c9ec8..3bfa49e1 100644 --- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java +++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java @@ -61,6 +61,8 @@ public class XMPPServer implements AutoCloseable { private JID jid; + private ServerSocket listener; + public XMPPServer(Environment env, ExecutorService service) { this.service = service; @@ -82,22 +84,27 @@ public class XMPPServer implements AutoCloseable { if (!disabled) { router = new ConnectionRouter(this, componentName, componentPort, env.getProperty("xmpp_password")); service.submit(router); + } - service.submit(() -> { - final ServerSocket listener = new ServerSocket(s2sPort); + service.submit(() -> { + try { + listener = new ServerSocket(s2sPort); logger.info("s2s listener ready"); while (true) { - try { - Socket socket = listener.accept(); - ConnectionIn client = new ConnectionIn(this, socket); - addConnectionIn(client); - service.submit(client); - } catch (Exception e) { - logger.error("s2s error", e); - } + if (Thread.currentThread().isInterrupted()) break; + Socket socket = listener.accept(); + ConnectionIn client = new ConnectionIn(this, socket); + addConnectionIn(client); + service.submit(client); } - }); - } + } catch (IOException e) { + logger.warn("io exception", e); + Thread.currentThread().interrupt(); + } catch (Exception ex) { + logger.warn("s2s error", ex); + } + logger.info("s2s interrupted"); + }); } catch (Exception e) { logger.error("XMPPComponent error", e); @@ -121,7 +128,10 @@ public class XMPPServer implements AutoCloseable { i.remove(); } } - logger.info("Xmpp server destroyed"); + if (!listener.isClosed()) { + listener.close(); + } + logger.info("XMPP server destroyed"); } public void addConnectionIn(ConnectionIn c) { |