diff src/pathfinder/NetworkSimulator.java @ 67:2e5bd7bffa4b

JavaPathFinder—p‚̃eƒXƒgƒNƒ‰ƒX
author kent
date Thu, 08 Nov 2007 12:21:25 +0900
parents
children 735e70091564
line wrap: on
line diff
--- /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<P> {
+	
+	public LinkedList<ChannelSimulator<P>> acceptList;
+	public ArrayList<ChannelSimulator<P>> connectList;
+
+	public NetworkSimulator(){
+		acceptList = new LinkedList<ChannelSimulator<P>>();
+		connectList = new ArrayList<ChannelSimulator<P>>();
+	}
+
+	public ChannelSimulator<P> accept(){
+		ChannelSimulator<P> cs = acceptList.poll();
+		connectList.add(cs);
+		
+		return cs.getServerChannel();
+	}
+	public void connect(ChannelSimulator<P> cs){
+		acceptList.add(cs);
+	}
+	
+	public synchronized P read(Queue<P>q) {
+		return q.poll();
+	}
+
+	public synchronized boolean write(Queue<P>q,P p) {
+		return q.add(p);
+	}
+}