diff options
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.java | 106 |
1 files changed, 29 insertions, 77 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 031a7b34..52d2f3a6 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 @@ -2,9 +2,6 @@ package com.juick.components.s2s; import com.juick.components.XMPPServer; -import java.io.FileNotFoundException; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; import java.util.Iterator; /** @@ -21,89 +18,44 @@ public class CleaningUp implements Runnable { @Override public void run() { while (true) { - try { - PrintWriter statsFile = new PrintWriter(xmpp.STATSFILE, "UTF-8"); - statsFile.write("<html><body><h2>Threads: " + Thread.activeCount() + "</h2>"); - statsFile.write("<h2>Out (" + xmpp.getOutConnections().size() + ")</h2><table border=1><tr><th>to</th><th>sid</th><th>inactive</th><th>out packets</th><th>out bytes</th></tr>"); - - 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(); - } else { - statsFile.write(" <tr>"); - statsFile.write(" <td>" + c.to + "</td>\n"); - statsFile.write(" <td>" + c.streamID + "</td>\n"); - statsFile.write(" <td>" + inactive + "</td>\n"); - statsFile.write(" <td>" + c.packetsLocal + "</td>\n"); - statsFile.write(" <td>" + c.bytesLocal + "</td>\n"); - statsFile.write(" <tr>"); - } + 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(); } } + } - statsFile.write("</table><h2>In (" + xmpp.getInConnections().size() + ")</h2><table border=1><tr><th>from</th><th>sid</th><th>inactive</th><th>in packets</th></tr>"); - - 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(); - } else { - statsFile.write(" <tr>"); - if (c.from.isEmpty()) { - statsFile.write(" <td> </td>\n"); - } else if (c.from.size() == 1) { - statsFile.write(" <td>" + c.from.get(0) + "</td>\n"); - } else { - String out = " <td>"; - for (int n = 0; n < c.from.size(); n++) { - if (n > 0) { - out += "<br/>"; - } - out += c.from.get(n); - } - statsFile.write(out + "</td>\n"); - } - statsFile.write(" <td>" + c.streamID + "</td>\n"); - statsFile.write(" <td>" + inactive + "</td>\n"); - statsFile.write(" <td>" + c.packetsRemote + "</td>\n"); - statsFile.write(" <tr>"); - } + 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(); } } + } - statsFile.write("</table><h2>Cache (" + xmpp.getOutCache().size() + ")</h2><table border=1><tr><th>host</th><th>live</th><th>size</th></tr>"); - - 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(); - } else { - statsFile.write("<tr><td>" + c.hostname + "</td><td>" + inactive + "</td><td>" + c.xml.length() + "</td></tr>"); - } + 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(); } } - - statsFile.write("</table></body></html>"); - statsFile.close(); - - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - } - } catch (FileNotFoundException e) { - } catch (UnsupportedEncodingException e) { } + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + } + } } } |