comparison src/pathfinder/BlockingQnoSeMa/NetworkSimulator_withoutSeMa.java @ 108:2e649cd44078

*** empty log message ***
author kent
date Sun, 23 Dec 2007 11:26:10 +0900
parents
children
comparison
equal deleted inserted replaced
107:823a45f843a9 108:2e649cd44078
1 package pathfinder.BlockingQnoSeMa;
2
3 import java.util.LinkedList;
4 import java.util.concurrent.BlockingQueue;
5 import java.util.concurrent.LinkedBlockingQueue;
6
7 public class NetworkSimulator_withoutSeMa<P> {
8 /** Established connection */
9 private LinkedList<ChannelSimulator<P>> connectedList;
10
11 public NetworkSimulator_withoutSeMa(){
12 connectedList = new LinkedList<ChannelSimulator<P>>();
13 }
14
15 /**
16 * Request to connect.
17 * Client editor use this method to connect SeMa.
18 * @param cs
19 */
20 public ChannelSimulator<P> connect(){
21 ChannelSimulator<P> cs;
22 if (connectedList.isEmpty()){
23 BlockingQueue<P> q = new LinkedBlockingQueue<P>();
24 cs = new ChannelSimulator<P>(q, q);
25 }else{
26 BlockingQueue<P> rq = connectedList.getLast().getWriteQ();
27 BlockingQueue<P> wq = new LinkedBlockingQueue<P>();
28 connectedList.getFirst().setReadQ(wq);
29
30 /* ChannelSimulator<P> lastcs = connectedList.getLast();
31 BlockingQueue<P> rq = lastcs.getWriteQ();
32
33 BlockingQueue<P> wq = new LinkedBlockingQueue<P>();
34 ChannelSimulator<P> firstcs = connectedList.getFirst();
35 firstcs.setReadQ(wq);
36 */
37 cs = new ChannelSimulator<P>(rq, wq);
38 }
39
40 connectedList.addLast(cs);
41 return cs;
42 }
43
44 public boolean checkAllCS(){
45 for(ChannelSimulator<P> cs: connectedList){
46 if(!cs.readQisEmpty()) return false;
47 }
48 return true;
49 }
50 }