From e5c8298beee5dde90ca98cc4707faac4bf0e2f0c Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Thu, 7 Jul 2016 15:13:47 +0300
Subject: reorganize project
---
.../main/java/com/juick/xmpp/s2s/CleaningUp.java | 107 +++++++++++++++++++++
1 file changed, 107 insertions(+)
create mode 100644 juick-www/src/main/java/com/juick/xmpp/s2s/CleaningUp.java
(limited to 'juick-www/src/main/java/com/juick/xmpp/s2s/CleaningUp.java')
diff --git a/juick-www/src/main/java/com/juick/xmpp/s2s/CleaningUp.java b/juick-www/src/main/java/com/juick/xmpp/s2s/CleaningUp.java
new file mode 100644
index 00000000..14d97ed8
--- /dev/null
+++ b/juick-www/src/main/java/com/juick/xmpp/s2s/CleaningUp.java
@@ -0,0 +1,107 @@
+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 {
+ XMPPComponent xmpp;
+
+ public CleaningUp(XMPPComponent xmpp) {
+ this.xmpp = xmpp;
+ }
+
+ @Override
+ public void run() {
+ while (true) {
+ try {
+ PrintWriter statsFile = new PrintWriter(xmpp.STATSFILE, "UTF-8");
+ statsFile.write("
Threads: " + Thread.activeCount() + "
");
+ statsFile.write("Out (" + xmpp.outConnections.size() + ")
to | sid | inactive | out packets | out bytes |
");
+
+ long now = System.currentTimeMillis();
+
+ synchronized (xmpp.outConnections) {
+ for (Iterator i = xmpp.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(" " + c.to + " | \n");
+ statsFile.write(" " + c.streamID + " | \n");
+ statsFile.write(" " + inactive + " | \n");
+ statsFile.write(" " + c.packetsLocal + " | \n");
+ statsFile.write(" " + c.bytesLocal + " | \n");
+ statsFile.write("
");
+ }
+ }
+ }
+
+ statsFile.write("
In (" + xmpp.inConnections.size() + ")
from | sid | inactive | in packets |
");
+
+ synchronized (xmpp.inConnections) {
+ for (Iterator i = xmpp.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(" " + c.from.get(0) + " | \n");
+ } else {
+ String out = " ";
+ for (int n = 0; n < c.from.size(); n++) {
+ if (n > 0) {
+ out += " ";
+ }
+ out += c.from.get(n);
+ }
+ statsFile.write(out + " | \n");
+ }
+ statsFile.write(" " + c.streamID + " | \n");
+ statsFile.write(" " + inactive + " | \n");
+ statsFile.write(" " + c.packetsRemote + " | \n");
+ statsFile.write("
");
+ }
+ }
+ }
+
+ statsFile.write("
Cache (" + xmpp.outCache.size() + ")
host | live | size |
");
+
+ synchronized (xmpp.outCache) {
+ for (Iterator i = xmpp.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("" + c.hostname + " | " + inactive + " | " + c.xml.length() + " |
");
+ }
+ }
+ }
+
+ statsFile.write("
");
+ statsFile.close();
+
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ }
+ } catch (FileNotFoundException e) {
+ } catch (UnsupportedEncodingException e) {
+ }
+ }
+ }
+}
--
cgit v1.2.3