Mercurial > hg > RemoteEditor > REPSessionManager
comparison rep/SessionManagerList.java @ 356:b18c24dcc5d2
Before chaning put/join scheme for ditributed select.
author | kono |
---|---|
date | Sat, 18 Oct 2008 19:01:40 +0900 |
parents | 98607350f7d1 |
children | b25f832f875d |
comparison
equal
deleted
inserted
replaced
355:98607350f7d1 | 356:b18c24dcc5d2 |
---|---|
1 package rep; | 1 package rep; |
2 | 2 |
3 import java.util.LinkedList; | 3 import java.util.LinkedList; |
4 import rep.channel.REPSocketChannel; | |
5 | 4 |
6 public class SessionManagerList { | 5 public class SessionManagerList extends LinkedList<Forwarder>{ |
7 | 6 |
8 private LinkedList<Forwarder> list = new LinkedList<Forwarder>(); | 7 /** |
9 private int mySMID; | 8 * |
9 */ | |
10 private static final long serialVersionUID = 1L; | |
11 private int mySMID=0; | |
12 private int smid_root=0; | |
10 private Forwarder parent=null; | 13 private Forwarder parent=null; |
11 private LinkedList<Forwarder> waiting= new LinkedList<Forwarder>(); | 14 private LinkedList<Forwarder> waiting= new LinkedList<Forwarder>(); |
12 | 15 |
13 public void add(Forwarder channel) { | |
14 list.add(channel); | |
15 } | |
16 | 16 |
17 public void setMaster(Forwarder f) { | 17 public void setMaster(Forwarder f) { |
18 this.parent = f; | 18 this.parent = f; |
19 } | 19 } |
20 | 20 |
21 public void sendToMaster(REPCommand repCmd) { | 21 public void sendToMaster(REPCommand repCmd) { |
22 parent.send(repCmd); | 22 parent.send(repCmd); |
23 } | 23 } |
24 | 24 |
25 public void sendToSlaves(REPCommand repCmd) { | 25 public void sendToSlaves(REPCommand repCmd) { |
26 for(Forwarder channel : list){ | 26 for(Forwarder channel : this){ |
27 channel.send(repCmd); | 27 channel.send(repCmd); |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 public boolean isMaster() { | 31 public boolean isMaster() { |
32 return parent==null; | 32 return parent==null; |
33 } | 33 } |
34 | 34 |
35 public int addNewSessionManager(Forwarder fw,REPCommand receivedCommand) { | 35 public int addNewSessionManager(Forwarder fw,REPCommand receivedCommand) { |
36 list.add(fw); | 36 add(fw); |
37 int sid = list.size(); | 37 int sid = ++smid_root; |
38 fw.setSID(sid); | 38 fw.setSID(sid); |
39 fw.setName(receivedCommand.string); | 39 fw.setName(receivedCommand.string); |
40 return sid; | 40 return sid; |
41 } | 41 } |
42 | 42 |
43 public boolean isSessionManagerChannel(REPSocketChannel<REPCommand> channel) { | |
44 for(Forwarder f : list){ | |
45 if (f.channel==channel) return true; | |
46 } | |
47 return false; | |
48 } | |
49 | 43 |
50 public void setSessionManagerID(int sid) { | 44 public void setSessionManagerID(int sid) { |
51 mySMID = sid; | 45 mySMID = sid; |
52 } | 46 } |
53 | 47 |
65 // 待っていたSession Manager ChannelにSession IDを登録し,Session Manager List | 59 // 待っていたSession Manager ChannelにSession IDを登録し,Session Manager List |
66 // に登録する。この次のsm_join_ackでSIDが確定する。 | 60 // に登録する。この次のsm_join_ackでSIDが確定する。 |
67 Forwarder waiter; | 61 Forwarder waiter; |
68 if ((waiter=waiting.poll())!=null) { | 62 if ((waiter=waiting.poll())!=null) { |
69 waiter.setSID(sid); | 63 waiter.setSID(sid); |
70 list.add(waiter); | 64 add(waiter); |
71 return; | 65 return; |
72 } | 66 } |
73 assert false; | 67 assert false; |
74 } | 68 } |
75 | 69 |