package com.juick.components.s2s; import com.juick.components.XMPPServer; import java.util.Iterator; /** * * @author ugnich */ public class CleaningUp implements Runnable { XMPPServer xmpp; public CleaningUp(XMPPServer xmpp) { this.xmpp = xmpp; } @Override public void run() { while (true) { long now = System.currentTimeMillis(); synchronized (xmpp.getOutConnections()) { for (Iterator 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(); } } } synchronized (xmpp.getInConnections()) { for (Iterator 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(); } } } synchronized (xmpp.getOutCache()) { for (Iterator i = xmpp.getOutCache().iterator(); i.hasNext(); ) { CacheEntry c = i.next(); int inactive = (int) ((double) (now - c.tsCreated) / 1000.0); if (inactive > 600) { i.remove(); } } } try { Thread.sleep(10000); } catch (InterruptedException e) { } } } }