# HG changeset patch # User kent # Date 1194492085 -32400 # Node ID 2e5bd7bffa4b6274f23d6927a987f4957fe49f4a # Parent 4ef0f4f472402bae76ef7ce66af36822d943e435 JavaPathFinderpÌeXgNX diff -r 4ef0f4f47240 -r 2e5bd7bffa4b src/pathfinder/ChannelSimulator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pathfinder/ChannelSimulator.java Thu Nov 08 12:21:25 2007 +0900 @@ -0,0 +1,41 @@ +package pathfinder; + +import java.util.LinkedList; +import java.util.Queue; + +public class ChannelSimulator
{ + public NetworkSimulator
ns; + public Queue
[] q; + + public ChannelSimulator() { + } +/* + public ChannelSimulator(NetworkSimulator
ns){ + q = new Queue
[2]; + q[0] = new LinkedList
(); + q[1] = new LinkedList
(); + this.ns = ns; + } +*/ + public ChannelSimulator(NetworkSimulator
_ns){ + this(new LinkedList
(), new LinkedList
(), _ns); + } + public ChannelSimulator(Queue
_a, Queue
_b, NetworkSimulator
ns){ + q = new Queue[2]; + q[0] = _a; + q[1] = _b; + this.ns = ns; + } + + public P read(){ + return ns.read(q[0]); + } + + public boolean write(P p){ + return ns.write(q[1],p); + } + + public ChannelSimulator
getServerChannel() { + return new ChannelSimulator
(q[1], q[0],ns); + } +} diff -r 4ef0f4f47240 -r 2e5bd7bffa4b src/pathfinder/NetworkSimulator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pathfinder/NetworkSimulator.java Thu Nov 08 12:21:25 2007 +0900 @@ -0,0 +1,34 @@ +package pathfinder; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Queue; + +public class NetworkSimulator
{
+
+ public LinkedList accept(){
+ ChannelSimulator cs = acceptList.poll();
+ connectList.add(cs);
+
+ return cs.getServerChannel();
+ }
+ public void connect(ChannelSimulator cs){
+ acceptList.add(cs);
+ }
+
+ public synchronized P read(Queue q) {
+ return q.poll();
+ }
+
+ public synchronized boolean write(Queue q,P p) {
+ return q.add(p);
+ }
+}
diff -r 4ef0f4f47240 -r 2e5bd7bffa4b src/pathfinder/SeMaEmulator.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pathfinder/SeMaEmulator.java Thu Nov 08 12:21:25 2007 +0900
@@ -0,0 +1,32 @@
+package pathfinder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SeMaEmulator implements Runnable {
+ private List addChannelSimulator(ChannelSimulator cs){
+ csList.add(cs);
+ return cs;
+ }
+
+ public void run(){
+ int i=0;
+ P packet;
+ ChannelSimulator cs = csList.get(1);
+
+ /* Main Loop */
+ while(true){
+ packet=cs.read();
+ i = (i+1)%csList.size();
+ cs = csList.get(i+1);
+ if (packet!=null) cs.write(packet);
+ }
+ }
+
+}
diff -r 4ef0f4f47240 -r 2e5bd7bffa4b src/pathfinder/Test.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pathfinder/Test.java Thu Nov 08 12:21:25 2007 +0900
@@ -0,0 +1,29 @@
+package pathfinder;
+
+public class Test {
+ NetworkSimulator