aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java71
1 files changed, 30 insertions, 41 deletions
diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java b/juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java
index 52d2f3a6..9c6cf278 100644
--- a/juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/CleaningUp.java
@@ -1,61 +1,50 @@
package com.juick.components.s2s;
import com.juick.components.XMPPServer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.annotation.Scheduled;
+import javax.inject.Inject;
import java.util.Iterator;
/**
*
* @author ugnich
*/
-public class CleaningUp implements Runnable {
- XMPPServer xmpp;
-
- public CleaningUp(XMPPServer xmpp) {
- this.xmpp = xmpp;
- }
+public class CleaningUp {
- @Override
- public void run() {
- while (true) {
- long now = System.currentTimeMillis();
-
- synchronized (xmpp.getOutConnections()) {
- for (Iterator<ConnectionOut> i = xmpp.getOutConnections().iterator(); i.hasNext(); ) {
- ConnectionOut c = i.next();
- int inactive = (int) ((double) (now - c.tsLocalData) / 1000.0);
- if (inactive > 900) {
- c.closeConnection();
- i.remove();
- }
- }
- }
+ private static final Logger logger = LoggerFactory.getLogger(CleaningUp.class);
- synchronized (xmpp.getInConnections()) {
- for (Iterator<ConnectionIn> i = xmpp.getInConnections().iterator(); i.hasNext(); ) {
- ConnectionIn c = i.next();
- int inactive = (int) ((double) (now - c.tsRemoteData) / 1000.0);
- if (inactive > 900) {
- c.closeConnection();
- i.remove();
- }
+ @Inject
+ XMPPServer xmpp;
+
+ @Scheduled(fixedDelay = 10000)
+ public void cleanUp() {
+ long now = System.currentTimeMillis();
+
+ synchronized (xmpp.getOutConnections()) {
+ for (Iterator<ConnectionOut> i = xmpp.getOutConnections().iterator(); i.hasNext(); ) {
+ ConnectionOut c = i.next();
+ int inactive = (int) ((double) (now - c.tsLocalData) / 1000.0);
+ if (inactive > 900) {
+ logger.info("closing idle outgoing connection to {}", c.to);
+ c.closeConnection();
+ i.remove();
}
}
+ }
- synchronized (xmpp.getOutCache()) {
- for (Iterator<CacheEntry> i = xmpp.getOutCache().iterator(); i.hasNext(); ) {
- CacheEntry c = i.next();
- int inactive = (int) ((double) (now - c.tsCreated) / 1000.0);
- if (inactive > 600) {
- i.remove();
- }
+ synchronized (xmpp.getInConnections()) {
+ for (Iterator<ConnectionIn> i = xmpp.getInConnections().iterator(); i.hasNext(); ) {
+ ConnectionIn c = i.next();
+ int inactive = (int) ((double) (now - c.tsRemoteData) / 1000.0);
+ if (inactive > 900) {
+ logger.info("closing idle incoming connection from {}", c.from);
+ c.closeConnection();
+ i.remove();
}
}
- try {
- Thread.sleep(10000);
- } catch (InterruptedException e) {
- }
-
}
}
}