aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'juick-xmpp')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/XMPPServer.java10
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);
+ }
}