aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main/java/com/juick/components/s2s
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-12-05 22:54:22 +0300
committerGravatar Vitaly Takmazov2016-12-05 23:19:10 +0300
commitc9c253f24601cc172058fd980b73791da4ec4f9c (patch)
treef4393dcec1d44b80357b4a3622e942f268ceeb12 /juick-xmpp/src/main/java/com/juick/components/s2s
parent4d9b066060bd78243616cb6f1fbdf0d06b09cbe7 (diff)
juick-xmpp: CleaningUp refactoring
Diffstat (limited to 'juick-xmpp/src/main/java/com/juick/components/s2s')
-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) {
- }
-
}
}
}