218
|
1 package test.sematest;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.net.InetSocketAddress;
|
|
5 import java.net.SocketAddress;
|
|
6
|
|
7 import rep.REPCommand;
|
|
8 import rep.REPCommandPacker;
|
|
9 import rep.channel.REPLogger;
|
|
10 import rep.channel.REPSocketChannel;
|
|
11 import test.channeltest.StringPacker;
|
|
12
|
|
13 public abstract class Tester extends Thread{
|
|
14 private SocketAddress semaIP;
|
|
15 private REPLogger ns;
|
|
16
|
|
17 public Tester(String name, String _host,int _port){
|
|
18 super(name);
|
|
19 semaIP = new InetSocketAddress(_host, _port);
|
|
20 ns = REPLogger.singleton();
|
|
21 ns.setLogLevel(5);
|
|
22 }
|
|
23
|
|
24 public void run(){
|
|
25 try {
|
|
26 REPSocketChannel<REPCommand> channel;
|
|
27 channel = REPSocketChannel.<REPCommand>create(new REPCommandPacker());
|
|
28 channel.configureBlocking(true);
|
|
29
|
|
30 ns.writeLog("try to connect to SessionManager whose ip is "+semaIP, 1);
|
|
31 while (!channel.connect(semaIP)){
|
|
32 ns.writeLog("SeMa not listen to socket yet, wait", 1);
|
|
33 Thread.yield();
|
|
34 }
|
|
35 ns.writeLog("successes to connect", 1);
|
|
36
|
|
37 sendCommand(channel);
|
|
38 ns.writeLog("wrote packet", 1);
|
|
39
|
|
40 REPCommand packet = channel.read();
|
|
41
|
|
42 ns.writeLog("gets return string==> `"+packet+"\'", 1);
|
|
43
|
|
44 ns.writeLog("testEditor exits.", 1);
|
|
45
|
|
46 channel.close1();
|
|
47
|
|
48 } catch (IOException e) {}
|
|
49 }
|
|
50
|
|
51 public abstract void sendCommand(REPSocketChannel<REPCommand> channel) throws IOException;
|
|
52 }
|