Mercurial > hg > RemoteEditor > Eclipse
view src/pathfinder/BlockingQnoSeMa/NetworkSimulator_withoutSeMa.java @ 108:2e649cd44078
*** empty log message ***
author | kent |
---|---|
date | Sun, 23 Dec 2007 11:26:10 +0900 |
parents | |
children |
line wrap: on
line source
package pathfinder.BlockingQnoSeMa; import java.util.LinkedList; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; public class NetworkSimulator_withoutSeMa<P> { /** Established connection */ private LinkedList<ChannelSimulator<P>> connectedList; public NetworkSimulator_withoutSeMa(){ connectedList = new LinkedList<ChannelSimulator<P>>(); } /** * Request to connect. * Client editor use this method to connect SeMa. * @param cs */ public ChannelSimulator<P> connect(){ ChannelSimulator<P> cs; if (connectedList.isEmpty()){ BlockingQueue<P> q = new LinkedBlockingQueue<P>(); cs = new ChannelSimulator<P>(q, q); }else{ BlockingQueue<P> rq = connectedList.getLast().getWriteQ(); BlockingQueue<P> wq = new LinkedBlockingQueue<P>(); connectedList.getFirst().setReadQ(wq); /* ChannelSimulator<P> lastcs = connectedList.getLast(); BlockingQueue<P> rq = lastcs.getWriteQ(); BlockingQueue<P> wq = new LinkedBlockingQueue<P>(); ChannelSimulator<P> firstcs = connectedList.getFirst(); firstcs.setReadQ(wq); */ cs = new ChannelSimulator<P>(rq, wq); } connectedList.addLast(cs); return cs; } public boolean checkAllCS(){ for(ChannelSimulator<P> cs: connectedList){ if(!cs.readQisEmpty()) return false; } return true; } }