aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main/java/com/juick/components/CleaningUp.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-xmpp/src/main/java/com/juick/components/CleaningUp.java')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/CleaningUp.java37
1 files changed, 18 insertions, 19 deletions
diff --git a/juick-xmpp/src/main/java/com/juick/components/CleaningUp.java b/juick-xmpp/src/main/java/com/juick/components/CleaningUp.java
index 067af6e8..16747ea4 100644
--- a/juick-xmpp/src/main/java/com/juick/components/CleaningUp.java
+++ b/juick-xmpp/src/main/java/com/juick/components/CleaningUp.java
@@ -23,6 +23,8 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
+import java.time.Duration;
+import java.time.Instant;
/**
*
@@ -33,29 +35,26 @@ public class CleaningUp {
private static final Logger logger = LoggerFactory.getLogger(CleaningUp.class);
+ private static final int TIMEOUT_MINUTES = 15;
+
@Inject
XMPPServer xmpp;
@Scheduled(fixedDelay = 10000)
public void cleanUp() {
- long now = System.currentTimeMillis();
-
- xmpp.getOutConnections().stream().filter(c -> {
- int inactive = (int) ((double) (now - c.tsLocalData) / 1000.0);
- return inactive > 900;
- }).forEach(c -> {
- logger.info("closing idle outgoing connection to {}", c.to);
- c.closeConnection();
- xmpp.getOutConnections().remove(c);
- });
-
- xmpp.getInConnections().stream().filter(c -> {
- int inactive = (int) ((double) (now - c.tsRemoteData) / 1000.0);
- return inactive > 900;
- }).forEach(c -> {
- logger.info("closing idle incoming connection from {}", c.from);
- c.closeConnection();
- xmpp.getInConnections().remove(c);
- });
+ Instant now = Instant.now();
+ xmpp.getOutConnections().stream().filter(c -> Duration.between(now, c.updated).toMinutes() > TIMEOUT_MINUTES)
+ .forEach(c -> {
+ logger.info("closing idle outgoing connection to {}", c.to);
+ c.closeConnection();
+ xmpp.getOutConnections().remove(c);
+ });
+
+ xmpp.getInConnections().stream().filter(c -> Duration.between(now, c.updated).toMinutes() > TIMEOUT_MINUTES)
+ .forEach(c -> {
+ logger.info("closing idle incoming connection from {}", c.from);
+ c.closeConnection();
+ xmpp.getInConnections().remove(c);
+ });
}
}