From 31ff67f333894b79fdfcbeb948cedfd6e588417f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 30 Jan 2018 15:22:02 +0300 Subject: xmpp: do not create new connections when restarting --- juick-xmpp/src/main/java/com/juick/components/XMPPServer.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'juick-xmpp/src/main/java/com') 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 15e2ba46..c57ed58e 100644 --- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java +++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java @@ -31,6 +31,7 @@ import rocks.xmpp.core.stanza.model.Stanza; import rocks.xmpp.util.XmppUtils; import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.inject.Inject; import javax.net.ssl.*; import javax.xml.bind.JAXBException; @@ -51,6 +52,7 @@ import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; import static com.juick.components.s2s.Connection.NS_TLS; @@ -80,6 +82,7 @@ public class XMPPServer implements ConnectionListener, AutoCloseable { private final Map> outConnections = new ConcurrentHashMap<>(); private final List outCache = new CopyOnWriteArrayList<>(); private final List stanzaListeners = new CopyOnWriteArrayList<>(); + private final AtomicBoolean closeFlag = new AtomicBoolean(false); SSLContext sc; private TrustManager[] trustAllCerts = new TrustManager[]{ @@ -105,6 +108,7 @@ public class XMPPServer implements ConnectionListener, AutoCloseable { @PostConstruct public void init() throws KeyStoreException { + closeFlag.set(false); KeyStore ks = KeyStore.getInstance("JKS"); try (InputStream ksIs = new FileInputStream(keystore)) { ks.load(ksIs, keystorePassword.toCharArray()); @@ -240,7 +244,7 @@ public class XMPPServer implements ConnectionListener, AutoCloseable { outCache.add(new CacheEntry(hostname, xml)); } - if (!haveAnyConn) { + if (!haveAnyConn && !closeFlag.get()) { try { createDialbackConnection(hostname.toEscapedString(), null, null); } catch (Exception e) { @@ -398,4 +402,8 @@ public class XMPPServer implements ConnectionListener, AutoCloseable { public Jid getJid() { return jid; } + @PreDestroy + public void preDestroy() { + closeFlag.set(true); + } } -- cgit v1.2.3