1 19 20 package com.sslexplorer.agent.client; 21 22 import com.sslexplorer.agent.client.util.IOStreamConnector; 23 import com.sslexplorer.agent.client.util.IOStreamConnectorListener; 24 25 26 34 public class TXRXMonitor extends Thread { 35 36 static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(TXRXMonitor.class); 38 39 41 private long lastRx, lastTx; 43 private final Agent client; 44 private IOStreamConnectorListener txIo, rxIo; 45 46 51 public TXRXMonitor(Agent client) { 52 super(Messages.getString("TXRXMonitor.threadName")); setDaemon(true); 54 this.client = client; 55 } 56 57 62 public IOStreamConnectorListener getTxListener() { 63 if(txIo == null) { 64 txIo = new TXIOStreamConnectorListener(); 65 } 66 return txIo; 67 } 68 69 74 public IOStreamConnectorListener getRxListener() { 75 if(rxIo == null) { 76 rxIo = new RXIOStreamConnectorListener(); 77 } 78 return rxIo; 79 } 80 81 84 public void run() { 85 86 long rx; 87 long tx; 88 try { 89 while (true) { 90 91 if (this.client.getState() != Agent.STATE_DISCONNECTED) { 92 rx = System.currentTimeMillis() - lastRx; 93 tx = System.currentTimeMillis() - lastTx; 94 95 if (rx < 500 && tx < 500) { 96 this.client.getGUI().showTxRx(); 97 } else if (rx < 500) { 98 this.client.getGUI().showRx(); 99 } else if (tx < 500) { 100 this.client.getGUI().showTx(); 101 } else { 102 this.client.getGUI().showIdle(); 103 } 104 } 105 else { 106 break; 107 } 108 try { 109 Thread.sleep(500); 110 } catch (InterruptedException ex) { 111 log.info(Messages.getString("TXRXMonitor.interrupted")); break; 115 } 116 } 117 } catch (Throwable ex) { 118 Agent.log.info(Messages.getString("TXRXMonitor.failed"), ex); } 122 } 123 124 class TXIOStreamConnectorListener implements IOStreamConnectorListener { 125 public void connectorClosed(IOStreamConnector connector) { 126 } 127 128 public void dataTransfered(byte[] data, int count) { 129 lastTx = System.currentTimeMillis(); 130 } 131 } 132 133 class RXIOStreamConnectorListener implements IOStreamConnectorListener { 134 public void connectorClosed(IOStreamConnector connector) { 135 } 136 137 public void dataTransfered(byte[] data, int count) { 138 lastRx = System.currentTimeMillis(); 139 } 140 } 141 } | Popular Tags |