package com.juick.xmpp.s2s; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.Iterator; /** * * @author ugnich */ public class CleaningUp implements Runnable { @Override public void run() { while (true) { try { PrintWriter statsFile = new PrintWriter(S2SComponent.STATSFILE, "UTF-8"); statsFile.write("

Threads: " + Thread.activeCount() + "

"); statsFile.write("

Out (" + S2SComponent.outConnections.size() + ")

"); long now = System.currentTimeMillis(); synchronized (S2SComponent.outConnections) { for (Iterator i = S2SComponent.outConnections.iterator(); i.hasNext();) { ConnectionOut c = i.next(); int inactive = (int) ((double) (now - c.tsLocalData) / 1000.0); if (inactive > 900) { c.closeConnection(); i.remove(); } else { statsFile.write(" "); statsFile.write(" \n"); statsFile.write(" \n"); statsFile.write(" \n"); statsFile.write(" \n"); statsFile.write(" \n"); statsFile.write(" "); } } } statsFile.write("
tosidinactiveout packetsout bytes
" + c.to + "" + c.streamID + "" + inactive + "" + c.packetsLocal + "" + c.bytesLocal + "

In (" + S2SComponent.inConnections.size() + ")

"); synchronized (S2SComponent.inConnections) { for (Iterator i = S2SComponent.inConnections.iterator(); i.hasNext();) { ConnectionIn c = i.next(); int inactive = (int) ((double) (now - c.tsRemoteData) / 1000.0); if (inactive > 900) { c.closeConnection(); i.remove(); } else { statsFile.write(" "); if (c.from.isEmpty()) { statsFile.write(" \n"); } else if (c.from.size() == 1) { statsFile.write(" \n"); } else { String out = " \n"); } statsFile.write(" \n"); statsFile.write(" \n"); statsFile.write(" \n"); statsFile.write(" "); } } } statsFile.write("
fromsidinactivein packets
 " + c.from.get(0) + ""; for (int n = 0; n < c.from.size(); n++) { if (n > 0) { out += "
"; } out += c.from.get(n); } statsFile.write(out + "
" + c.streamID + "" + inactive + "" + c.packetsRemote + "

Cache (" + S2SComponent.outCache.size() + ")

"); synchronized (S2SComponent.outCache) { for (Iterator i = S2SComponent.outCache.iterator(); i.hasNext();) { CacheEntry c = i.next(); int inactive = (int) ((double) (now - c.tsCreated) / 1000.0); if (inactive > 600) { i.remove(); } else { statsFile.write(""); } } } statsFile.write("
hostlivesize
" + c.hostname + "" + inactive + "" + c.xml.length() + "
"); statsFile.close(); try { Thread.sleep(10000); } catch (InterruptedException e) { } } catch (FileNotFoundException e) { } catch (UnsupportedEncodingException e) { } } } }