Mercurial > hg > RemoteEditor > Eclipse
view src/pathfinder/NetworkSimulator.java @ 68:735e70091564
EditorSimulator1 in TestNetwork
author | kent |
---|---|
date | Thu, 08 Nov 2007 12:56:56 +0900 |
parents | 2e5bd7bffa4b |
children | 3c9b8371681d |
line wrap: on
line source
package pathfinder; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; public class NetworkSimulator<P> { public Queue<ChannelSimulator<P>> acceptList; public Queue<ChannelSimulator<P>> connectList; public NetworkSimulator(){ acceptList = new LinkedList<ChannelSimulator<P>>(); connectList = new LinkedList<ChannelSimulator<P>>(); } public ChannelSimulator<P> accept(){ ChannelSimulator<P> cs = acceptList.poll(); connectList.offer(cs); return cs.getServerChannel(); } public void connect(ChannelSimulator<P> 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.offer(p); } }