7
|
1 package rep;
|
|
2
|
|
3 import java.util.LinkedList;
|
356
|
4
|
|
5 public class SessionManagerList extends LinkedList<Forwarder>{
|
56
|
6
|
356
|
7 /**
|
|
8 *
|
|
9 */
|
|
10 private static final long serialVersionUID = 1L;
|
|
11 private int mySMID=0;
|
|
12 private int smid_root=0;
|
349
|
13 private Forwarder parent=null;
|
355
|
14 private LinkedList<Forwarder> waiting= new LinkedList<Forwarder>();
|
7
|
15
|
|
16
|
349
|
17 public void setMaster(Forwarder f) {
|
|
18 this.parent = f;
|
|
19 }
|
|
20
|
|
21 public void sendToMaster(REPCommand repCmd) {
|
|
22 parent.send(repCmd);
|
|
23 }
|
|
24
|
|
25 public void sendToSlaves(REPCommand repCmd) {
|
356
|
26 for(Forwarder channel : this){
|
349
|
27 channel.send(repCmd);
|
7
|
28 }
|
|
29 }
|
|
30
|
349
|
31 public boolean isMaster() {
|
|
32 return parent==null;
|
25
|
33 }
|
21
|
34
|
355
|
35 public int addNewSessionManager(Forwarder fw,REPCommand receivedCommand) {
|
356
|
36 add(fw);
|
|
37 int sid = ++smid_root;
|
355
|
38 fw.setSID(sid);
|
|
39 fw.setName(receivedCommand.string);
|
|
40 return sid;
|
31
|
41 }
|
|
42
|
56
|
43
|
355
|
44 public void setSessionManagerID(int sid) {
|
|
45 mySMID = sid;
|
|
46 }
|
|
47
|
|
48 public int sessionManagerID() {
|
|
49 return mySMID;
|
|
50 }
|
|
51
|
|
52 public void addWaitingSessionManager(Forwarder fw, REPCommand command) {
|
|
53 // SID assign 待ちのSessionManager Channelを登録する
|
|
54 waiting.add(fw);
|
|
55
|
|
56 }
|
|
57
|
|
58 public void assignSessionManagerIDtoWaitingSM(int sid) {
|
|
59 // 待っていたSession Manager ChannelにSession IDを登録し,Session Manager List
|
|
60 // に登録する。この次のsm_join_ackでSIDが確定する。
|
|
61 Forwarder waiter;
|
|
62 if ((waiter=waiting.poll())!=null) {
|
|
63 waiter.setSID(sid);
|
356
|
64 add(waiter);
|
355
|
65 return;
|
|
66 }
|
|
67 assert false;
|
|
68 }
|
|
69
|
56
|
70
|
349
|
71
|
78
|
72
|
7
|
73 }
|