From e746ca6970bea80ec9b5ae79dda8f6332254e301 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 16 Jan 2016 16:43:43 +0300 Subject: moved to Gradle --- src/main/java/com/juick/jabber/ws/WSKeepAlive.java | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/main/java/com/juick/jabber/ws/WSKeepAlive.java (limited to 'src/main/java/com/juick/jabber/ws/WSKeepAlive.java') diff --git a/src/main/java/com/juick/jabber/ws/WSKeepAlive.java b/src/main/java/com/juick/jabber/ws/WSKeepAlive.java new file mode 100644 index 00000000..2deef594 --- /dev/null +++ b/src/main/java/com/juick/jabber/ws/WSKeepAlive.java @@ -0,0 +1,102 @@ +package com.juick.jabber.ws; + +import java.io.PrintWriter; +import java.nio.ByteBuffer; +import java.sql.Connection; +import java.util.Iterator; + +/** + * + * @author ugnich + */ +public class WSKeepAlive implements Runnable { + + Connection sql; + ByteBuffer pingBytes; + ByteBuffer closeBytes; + + public WSKeepAlive(Connection sql) { + this.sql = sql; + + //pingBytes = ByteBuffer.allocate(2); + //pingBytes.put((byte) 0x8A); // PONG FRAME + //pingBytes.put((byte) 0x00); // 0 byte long + pingBytes = ByteBuffer.allocate(3); + pingBytes.put((byte) 0x81); // TEXT FRAME + pingBytes.put((byte) 0x01); // 1 byte long + pingBytes.put((byte) 0x20); // ' ' + pingBytes.flip(); + + closeBytes = ByteBuffer.allocate(2); + closeBytes.put((byte) 0x88); // CLOSE FRAME + closeBytes.put((byte) 0x00); // 0 byte long + closeBytes.flip(); + } + + @Override + public void run() { + while (true) { + PrintWriter statsFile = null; + + if (Main.STATSFILE != null) { + try { + statsFile = new PrintWriter(Main.STATSFILE, "UTF-8"); + } catch (Exception e) { + statsFile = null; + System.err.println("WSKeepAlive statsFile: " + e); + } + } + + long now = System.currentTimeMillis(); + + synchronized (Main.clients) { + if (statsFile != null) { + statsFile.write("
IP | inactive | VUID | UID | MID | allM | allR |
---|---|---|---|---|---|---|
" + (s.clientName != null ? s.clientName : "?") + " | "); + statsFile.print("" + inactive + " | "); + statsFile.print("" + (s.VUID > 0 ? s.VUID : "") + " | "); + statsFile.print("" + (s.UID > 0 ? s.UID : "") + " | "); + statsFile.print("" + (s.MID > 0 ? s.MID : "") + " | "); + statsFile.print("" + (s.allMessages ? "+" : "") + " | "); + statsFile.print("" + (s.allReplies ? "+" : "") + " |