From 331645f0fd7fbe7d9679d39dcce453cc3b2cab6e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 28 Jun 2016 10:36:28 +0300 Subject: spring-websocket --- src/main/java/com/juick/jabber/ws/WSKeepAlive.java | 106 --------------------- 1 file changed, 106 deletions(-) delete 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 deleted file mode 100644 index 6244013d..00000000 --- a/src/main/java/com/juick/jabber/ws/WSKeepAlive.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.juick.jabber.ws; - -import org.springframework.jdbc.core.JdbcTemplate; - -import java.io.PrintWriter; -import java.nio.ByteBuffer; -import java.util.Iterator; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author ugnich - */ -public class WSKeepAlive implements Runnable { - private static final Logger logger = Logger.getLogger(WSKeepAlive.class.getName()); - - JdbcTemplate sql; - ByteBuffer pingBytes; - ByteBuffer closeBytes; - - public WSKeepAlive(JdbcTemplate 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; - logger.severe("WSKeepAlive statsFile: " + e); - } - } - - long now = System.currentTimeMillis(); - - synchronized (Main.clients) { - if (statsFile != null) { - statsFile.write("

Connections (" + Main.clients.size() + ")

"); - } - - for (Iterator i = Main.clients.iterator(); i.hasNext();) { - SocketSubscribed s = i.next(); - int inactive = (int) ((double) (now - s.tsLastData) / 1000.0); - - if (statsFile != null) { - try { - statsFile.print(""); - statsFile.print(""); - statsFile.print(""); - statsFile.print(""); - statsFile.print(""); - statsFile.print(""); - statsFile.print(""); - } catch (Exception e) { - logger.log(Level.SEVERE, "WSKeepAlive statsFile print", e); - } - } - - if (inactive > 180) { - s.sendByteBuffer(closeBytes); - s.close(); - i.remove(); - } else if (inactive > 60) { - if (!s.sendByteBuffer(pingBytes)) { - i.remove(); - } - } - } - } - - if (Main.STATSFILE != null) { - try { - statsFile.write("
IPinactiveVUIDUIDMIDallMallR
" + (s.clientName != null ? s.clientName : "?") + "" + inactive + "" + (s.VUID > 0 ? s.VUID : "") + "" + (s.UID > 0 ? s.UID : "") + "" + (s.MID > 0 ? s.MID : "") + "" + (s.allMessages ? "+" : "") + "" + (s.allReplies ? "+" : "") + "
"); - statsFile.close(); - } catch (Exception e) { - logger.log(Level.SEVERE, "WSKeepAlive statsFile close", e); - } - } - - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - } - } - } -} -- cgit v1.2.3