Mercurial > hg > RemoteEditor > REPSessionManager
view test/sematest/Tester.java @ 281:c3969dd625b2
GUIless test routine.
author | kono |
---|---|
date | Sat, 27 Sep 2008 22:55:13 +0900 |
parents | f9b1a9ba1a73 |
children | 90965a3bd4f3 |
line wrap: on
line source
package test.sematest; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.List; import rep.REP; import rep.REPCommand; import rep.REPCommandPacker; import rep.channel.REPLogger; import rep.channel.REPServerSocketChannel; import rep.channel.REPSocketChannel; public class Tester extends Thread{ private SocketAddress semaIP; protected REPLogger ns; private boolean running = true; protected REPSocketChannel<REPCommand> channel; protected List<REPCommand> commandList; public Tester(String name, String _host,int _port){ super(name); // REPServerSocketChannel.isSimulation = false; semaIP = new InetSocketAddress(_host, _port); ns = REPLogger.singleton(); ns.setLogLevel(5); } public void run(){ try { channel = REPSocketChannel.<REPCommand>create(new REPCommandPacker()); channel.configureBlocking(true); ns.writeLog("try to connect to SessionManager whose ip is "+semaIP, 1); while (!channel.connect(semaIP)){ ns.writeLog("SeMa not listen to socket yet, wait", 1); Thread.yield(); } ns.writeLog("successes to connect", 1); sendCommands(); while(running){ REPCommand packet = channel.read(); ns.writeLog("gets return string==> `"+packet+"\'", 1); if(packet.cmd == REP.SMCMD_QUIT){ running = false; } } ns.writeLog("testEditor exits.", 1); channel.close1(); } catch (IOException e) {} } public void sendCommands(){ if(commandList == null) return; if(channel == null) return; for(REPCommand command: commandList){ channel.write(command); } } public void setCommands(List<REPCommand> commands){ commandList = commands; } }