Mercurial > hg > RemoteEditor > Eclipse
changeset 74:d44d734502da
change connect method in NetworkSimulator to it return ChannelSimulator
author | kent |
---|---|
date | Thu, 08 Nov 2007 18:59:09 +0900 |
parents | bb5db6a67c7b |
children | ea4a1eec3b36 |
files | src/pathfinder/NetworkSimulator.java src/pathfinder/SeMaEmulator.java src/pathfinder/Test.java src/pathfinder/TestNetwork.java src/pathfinder/Text.java |
diffstat | 5 files changed, 42 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/pathfinder/NetworkSimulator.java Thu Nov 08 16:27:56 2007 +0900 +++ b/src/pathfinder/NetworkSimulator.java Thu Nov 08 18:59:09 2007 +0900 @@ -32,9 +32,16 @@ * Client editor use this method to connect SeMa. * @param cs */ + public ChannelSimulator<P> connect(){ + ChannelSimulator<P> cs = new ChannelSimulator<P>(this); + acceptList.offer(cs); + return cs; + } +/* public void connect(ChannelSimulator<P> cs){ acceptList.offer(cs); } +*/ public synchronized P read(Queue<P>q) { return q.poll();
--- a/src/pathfinder/SeMaEmulator.java Thu Nov 08 16:27:56 2007 +0900 +++ b/src/pathfinder/SeMaEmulator.java Thu Nov 08 18:59:09 2007 +0900 @@ -30,19 +30,24 @@ public void run(){ int i=0; + int count=0; P packet; waitClient(); - System.out.println("SessionManager was initialized."); + System.out.println("SessionManager start."); /* Main Loop */ ChannelSimulator<P> cs = csList.get(i); while(true){ - packet=cs.read(); // [i]からread - i = (i+1)%csList.size(); // i++ - cs = csList.get(i); // 次のChennelをゲット - if (packet!=null) cs.write(packet); // readできていたならそれを書き込む - if (i==0) checkAccept(); //全部回ったらaccept待ちをチェック + packet=cs.read(); // [i]からread + i = (i+1)%csList.size(); // i++ + cs = csList.get(i); // 次のChennelをゲット + if (packet!=null) { + cs.write(packet); // readできていたならそれを書き込む + }else count++; + if (i==0) checkAccept(); //全部回ったらaccept待ちをチェック + if (count>=100) break; } + System.out.println("SessionManager finish."); } }
--- a/src/pathfinder/Test.java Thu Nov 08 16:27:56 2007 +0900 +++ b/src/pathfinder/Test.java Thu Nov 08 18:59:09 2007 +0900 @@ -10,11 +10,10 @@ Test test = new Test(); test.test(); } - + void test() { ns = new NetworkSimulator<String>(); - client = new ChannelSimulator<String>(ns); - ns.connect(client); + client = ns.connect(); server = ns.accept(); client.write("client0 write some thing"); @@ -22,7 +21,7 @@ System.out.println(server.read()); } - + void thread() { }
--- a/src/pathfinder/TestNetwork.java Thu Nov 08 16:27:56 2007 +0900 +++ b/src/pathfinder/TestNetwork.java Thu Nov 08 18:59:09 2007 +0900 @@ -11,7 +11,7 @@ private int N_editor; public static void main(String [] arg) { - TestNetwork test = new TestNetwork(4); + TestNetwork test = new TestNetwork(2); test.startTest(); } @@ -32,14 +32,13 @@ ee.start(); } sm.start(); - - for (EditorEmulator1 ee: editors){ - try { + + try { + for (EditorEmulator1 ee: editors) ee.join(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + sm.join(); + } catch (InterruptedException e) { + e.printStackTrace(); } } /* @@ -63,10 +62,10 @@ private ChannelSimulator<String> cs; static private String[] text0 = { "aaa", "bbb", "ccc", "ddd", "eee", - "fff", "ggg", "hhh", "iii", "jjj", - "kkk", "lll", "mmm", "nnn", "ooo", - "ppp", "qqq", "rrr", "sss", "ttt", - "uuu", "vvv", "www", "xxx", "yyy", "zzz" + "fff", "ggg", "hhh", "iii", "jjj" + //"kkk", "lll", "mmm", "nnn", "ooo", + //"ppp", "qqq", "rrr", "sss", "ttt", + //"uuu", "vvv", "www", "xxx", "yyy", "zzz" }; @@ -79,19 +78,19 @@ } public void init(){ - cs = new ChannelSimulator<String>(ns); - ns.connect(cs); + cs = ns.connect(); } public void run(){ int count=0; String str; sendPackets(); System.out.println("thread "+name+" start."); - while(count<10){ + while(count<8){ str = cs.read(); if (str==null) continue; System.out.println(name+": Catch String '"+str+"'"); count++; } + System.out.println("thread "+name+" finish."); } public void sendPackets(){
--- a/src/pathfinder/Text.java Thu Nov 08 16:27:56 2007 +0900 +++ b/src/pathfinder/Text.java Thu Nov 08 18:59:09 2007 +0900 @@ -21,18 +21,25 @@ } public void insert(int i, String str){ + assert 0<i && i<strList.size(); strList.add(i, str); } public void delete(int i){ + assert 0<i && i<strList.size(); strList.remove(i); } public void replace(int i, String str){ + assert 0<i && i<strList.size(); strList.set(i, str); } public String get(int i){ + assert 0<i && i<strList.size(); return strList.get(i); } + public int size(){ + return strList.size(); + } public void printAllText(){ for( String str: strList){ System.out.println(str);