aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main/java/com/juick/components/s2s
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-01-24 11:09:06 +0300
committerGravatar Vitaly Takmazov2017-01-30 10:41:35 +0300
commit68a0e8f60cafd7bba03ff14fe6f5671855ffac72 (patch)
tree5d794583c86c350c6173ed958b86b6c3b3e9254a /juick-xmpp/src/main/java/com/juick/components/s2s
parentcafc4d3d47f4de89808208cb2f8c5a1ceef5c443 (diff)
juick-xmpp: shutdown app correctly
Diffstat (limited to 'juick-xmpp/src/main/java/com/juick/components/s2s')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java
index b28298a2..37d3c59f 100644
--- a/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/ConnectionRouter.java
@@ -29,13 +29,14 @@ import java.util.concurrent.TimeUnit;
/**
* @author ugnich
*/
-public class ConnectionRouter extends Connection implements Runnable {
+public class ConnectionRouter extends Connection implements Runnable, AutoCloseable {
private static final Logger logger = LoggerFactory.getLogger(ConnectionRouter.class);
private String componentName;
private int componentPort;
private String password;
+ private Execution execution;
public ConnectionRouter(XMPPServer s2s, String componentName, int componentPort, String password) throws Exception {
super(s2s);
@@ -51,7 +52,7 @@ public class ConnectionRouter extends Connection implements Runnable {
.withBackoff(1, 30, TimeUnit.SECONDS)
.withJitter(0.1)
.retryOn(IOException.class, XmlPullParserException.class);
- Execution execution = new Execution(retryPolicy);
+ execution = new Execution(retryPolicy);
xmpp.service.submit(() -> {
while (!execution.isComplete()) {
try {
@@ -109,6 +110,9 @@ public class ConnectionRouter extends Connection implements Runnable {
}
}
}
+ } else if (tag.equals("iq") || tag.equals("presence")) {
+ String xml = XmlUtils.parseToString(parser, true);
+ logger.info("stream router (stanza): {}", xml);
}
} else if (jid.Host.endsWith(xmpp.HOSTNAME) && (jid.Host.equals(xmpp.HOSTNAME) || jid.Host.endsWith("." + xmpp.HOSTNAME))) {
String xml = XmlUtils.parseToString(parser, true);
@@ -129,6 +133,9 @@ public class ConnectionRouter extends Connection implements Runnable {
}
logger.warn("stream router finished");
+ } catch (InterruptedException ex) {
+ logger.info("shutting down");
+ execution.complete();
} catch (Exception e) {
logger.warn("router error, reconnection ", e);
execution.recordFailure(e);
@@ -260,4 +267,9 @@ public class ConnectionRouter extends Connection implements Runnable {
}
}
}
+
+ @Override
+ public void close() throws Exception {
+ execution.complete();
+ }
}