Mercurial > hg > RemoteEditor > Eclipse
changeset 68:735e70091564
EditorSimulator1 in TestNetwork
author | kent |
---|---|
date | Thu, 08 Nov 2007 12:56:56 +0900 |
parents | 2e5bd7bffa4b |
children | 3c9b8371681d |
files | src/pathfinder/ChannelSimulator.java src/pathfinder/NetworkSimulator.java src/pathfinder/Test.java src/pathfinder/TestNetwork.java |
diffstat | 4 files changed, 38 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/pathfinder/ChannelSimulator.java Thu Nov 08 12:21:25 2007 +0900 +++ b/src/pathfinder/ChannelSimulator.java Thu Nov 08 12:56:56 2007 +0900 @@ -6,9 +6,6 @@ public class ChannelSimulator<P> { public NetworkSimulator<P> ns; public Queue<P>[] q; - - public ChannelSimulator() { - } /* public ChannelSimulator(NetworkSimulator<P> ns){ q = new Queue<P>[2];
--- a/src/pathfinder/NetworkSimulator.java Thu Nov 08 12:21:25 2007 +0900 +++ b/src/pathfinder/NetworkSimulator.java Thu Nov 08 12:56:56 2007 +0900 @@ -2,33 +2,34 @@ import java.util.ArrayList; import java.util.LinkedList; +import java.util.List; import java.util.Queue; public class NetworkSimulator<P> { - public LinkedList<ChannelSimulator<P>> acceptList; - public ArrayList<ChannelSimulator<P>> connectList; + public Queue<ChannelSimulator<P>> acceptList; + public Queue<ChannelSimulator<P>> connectList; public NetworkSimulator(){ acceptList = new LinkedList<ChannelSimulator<P>>(); - connectList = new ArrayList<ChannelSimulator<P>>(); + connectList = new LinkedList<ChannelSimulator<P>>(); } public ChannelSimulator<P> accept(){ ChannelSimulator<P> cs = acceptList.poll(); - connectList.add(cs); + connectList.offer(cs); return cs.getServerChannel(); } public void connect(ChannelSimulator<P> cs){ - acceptList.add(cs); + acceptList.offer(cs); } - + public synchronized P read(Queue<P>q) { return q.poll(); } public synchronized boolean write(Queue<P>q,P p) { - return q.add(p); + return q.offer(p); } }
--- a/src/pathfinder/Test.java Thu Nov 08 12:21:25 2007 +0900 +++ b/src/pathfinder/Test.java Thu Nov 08 12:56:56 2007 +0900 @@ -17,7 +17,7 @@ ns.connect(client); server = ns.accept(); - client.write("client write some thing"); + client.write("client0 write some thing"); System.out.println(server.read());
--- a/src/pathfinder/TestNetwork.java Thu Nov 08 12:21:25 2007 +0900 +++ b/src/pathfinder/TestNetwork.java Thu Nov 08 12:56:56 2007 +0900 @@ -1,7 +1,8 @@ package pathfinder; public class TestNetwork { - NetworkSimulator<String> ns; + private NetworkSimulator<String> ns; + private SeMaEmulator<String> sm; ChannelSimulator<String> client; ChannelSimulator<String> server; @@ -11,14 +12,18 @@ test.test(); } + public TestNetwork(){ + ns = new NetworkSimulator<String>(); + } + void test() { ns = new NetworkSimulator<String>(); client = new ChannelSimulator<String>(ns); ns.connect(client); server = ns.accept(); - + client.write("client write some thing"); - + System.out.println(server.read()); } @@ -27,3 +32,24 @@ } } + +class EditorEmulator1 implements Runnable { + private NetworkSimulator<String> ns; + private ChannelSimulator<String> cs; + + public EditorEmulator1(NetworkSimulator<String> _ns){ + ns = _ns; + } + public void init(){ + cs = new ChannelSimulator<String>(ns); + ns.connect(cs); + } + public void run(){ + String str; + while(true){ + str = cs.read(); + if (cs==null) continue; + System.out.println("Catch String: "+str); + } + } +}