diff options
author | 2018-01-30 15:22:02 +0300 | |
---|---|---|
committer | 2018-01-30 15:22:02 +0300 | |
commit | 31ff67f333894b79fdfcbeb948cedfd6e588417f (patch) | |
tree | 615c11fb48eb119614137586d86324fcfbd9b268 /juick-xmpp/src/main/java/com/juick | |
parent | 2d6e1dc76e659b78b3103af2bcf1b7f13db62f0a (diff) |
xmpp: do not create new connections when restarting
Diffstat (limited to 'juick-xmpp/src/main/java/com/juick')
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/XMPPServer.java | 10 |
1 files changed, 9 insertions, 1 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 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<ConnectionOut, Optional<Socket>> outConnections = new ConcurrentHashMap<>(); private final List<CacheEntry> outCache = new CopyOnWriteArrayList<>(); private final List<StanzaListener> 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); + } } |