Mercurial > hg > RemoteEditor > Eclipse
comparison src/pathfinder/mergetest/SelectorSimulator.java @ 151:1768e68ba98e
*** empty log message ***
author | pin |
---|---|
date | Tue, 05 Aug 2008 15:09:39 +0900 (2008-08-05) |
parents | |
children | 6326e5ea4595 |
comparison
equal
deleted
inserted
replaced
150:e33871f4b39a | 151:1768e68ba98e |
---|---|
1 package pathfinder.mergetest; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.Set; | |
5 | |
6 public class SelectorSimulator<P> { | |
7 | |
8 private ArrayList<SelectionKeySimulator<P>> keyList; | |
9 private NetworkSimulator<P> ns; | |
10 private ArrayList<SelectionKeySimulator<P>> selectedKeys; | |
11 | |
12 public SelectorSimulator(NetworkSimulator<P> _ns) { | |
13 // TODO Auto-generated constructor stub | |
14 ns = _ns; | |
15 keyList = new ArrayList<SelectionKeySimulator<P>>(); | |
16 } | |
17 | |
18 public int select(){ | |
19 selectedKeys = new ArrayList<SelectionKeySimulator<P>>(); | |
20 | |
21 synchronized(ns){ | |
22 boolean empty = false; | |
23 for(SelectionKeySimulator<P> key : keyList){ | |
24 ChannelSimulator<P> channel = key.channel(); | |
25 if(channel.readQisEmpty()){ | |
26 empty = true; | |
27 }else{ | |
28 empty = false; | |
29 //selectedKeys = key; | |
30 selectedKeys.add(key); | |
31 break; | |
32 } | |
33 } | |
34 | |
35 try { | |
36 if(empty) ns.wait(); | |
37 } catch (InterruptedException e) { | |
38 // TODO Auto-generated catch block | |
39 e.printStackTrace(); | |
40 } | |
41 } | |
42 return selectedKeys.size(); | |
43 } | |
44 | |
45 public SelectionKeySimulator<P> register(ChannelSimulator<P> cs){ | |
46 SelectionKeySimulator<P> key = new SelectionKeySimulator<P>(cs); | |
47 keyList.add(new SelectionKeySimulator<P>(cs)); | |
48 return key; | |
49 } | |
50 | |
51 public ArrayList<SelectionKeySimulator<P>> selectedKeys() { | |
52 | |
53 return selectedKeys; | |
54 } | |
55 | |
56 } |