From a33e6c3926b41a29a5828677cbad265f7c503d57 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 6 Jul 2016 20:18:49 +0300 Subject: refactor --- .../java/com/juick/xmpp/s2s/XMPPComponent.java | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java index 21efaeab..d0b231e2 100644 --- a/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java +++ b/src/main/java/com/juick/xmpp/s2s/XMPPComponent.java @@ -159,9 +159,8 @@ public class XMPPComponent implements ServletContextListener, Stream.StreamListe } if (!haveAnyConn) { - ConnectionOut connectionOut = null; try { - connectionOut = new ConnectionOut(this, hostname); + ConnectionOut connectionOut = new ConnectionOut(this, hostname); executorService.submit(connectionOut); } catch (CertificateException | UnrecoverableKeyException | NoSuchAlgorithmException | XmlPullParserException | KeyStoreException | KeyManagementException | IOException e) { logger.log(Level.SEVERE, "s2s out error", e); @@ -190,16 +189,22 @@ public class XMPPComponent implements ServletContextListener, Stream.StreamListe bot = new JuickBot(this, Jid); childParsers.put(JuickMessage.XMLNS, new JuickMessage()); - Socket routerSocket = new Socket("localhost", 5347); - router = new StreamComponent(new JID("s2s"), routerSocket.getInputStream(), routerSocket.getOutputStream(), conf.getProperty("xmpp_password")); - router.addChildParser(new JuickMessage()); - router.addListener((Stream.StreamListener) this); - router.addListener((Message.MessageListener) this); - router.addListener((Iq.IqListener) this); - executorService.submit(() -> router.startParsing()); + + executorService.submit(() -> { + Socket routerSocket = null; + try { + routerSocket = new Socket("localhost", 5347); + router = new StreamComponent(new JID("s2s"), routerSocket.getInputStream(), routerSocket.getOutputStream(), conf.getProperty("xmpp_password")); + router.addChildParser(new JuickMessage()); + router.addListener((Stream.StreamListener) this); + router.addListener((Message.MessageListener) this); + router.addListener((Iq.IqListener) this); + router.startParsing(); + } catch (IOException e) { + logger.log(Level.SEVERE, "router error", e); + } + }); executorService.submit(() -> { - router.startParsing(); - executorService.submit(new CleaningUp(this)); final ServerSocket listener = new ServerSocket(5269); logger.info("s2s listener ready"); while (true) { @@ -213,6 +218,7 @@ public class XMPPComponent implements ServletContextListener, Stream.StreamListe } } }); + executorService.submit(new CleaningUp(this)); } catch (Exception e) { logger.log(Level.SEVERE, "XMPPComponent error", e); -- cgit v1.2.3