7
|
1 package rep;
|
|
2
|
|
3 import java.util.LinkedList;
|
|
4 import java.util.List;
|
|
5
|
133
|
6 import rep.channel.REPSocketChannel;
|
56
|
7 import rep.xml.SessionXMLEncoder;
|
|
8
|
7
|
9 public class SessionManagerList {
|
|
10
|
133
|
11 private List<REPSocketChannel<REPCommand>> list = new LinkedList<REPSocketChannel<REPCommand>>();
|
7
|
12 private int mySMID;
|
133
|
13 private REPSocketChannel<REPCommand> master;
|
7
|
14
|
133
|
15 public void add(REPSocketChannel<REPCommand> channel) {
|
7
|
16 list.add(channel);
|
|
17 }
|
|
18
|
21
|
19 public void sendUpdate(int sessionID, String string) {
|
133
|
20 for(REPSocketChannel<REPCommand> channel : list){
|
183
|
21 channel.write(new REPCommand(REP.SMCMD_UPDATE, 0, mySMID, 0, 0, string.length(), string));
|
7
|
22 }
|
|
23 }
|
|
24
|
21
|
25 public void sendJoin(REPCommand command) {
|
133
|
26 for(REPSocketChannel<REPCommand> channel : list){
|
183
|
27 channel.write(command);
|
25
|
28 }
|
|
29 }
|
|
30
|
133
|
31 public void setMaster(REPSocketChannel<REPCommand> channel){
|
25
|
32 this.master = channel;
|
|
33 }
|
21
|
34
|
56
|
35 public void sendSessionList(SessionList sessionlist, REPCommand command) {
|
|
36 SessionXMLEncoder encoder = new SessionXMLEncoder(sessionlist);
|
|
37 command.setString(encoder.sessionListToXML());
|
31
|
38
|
133
|
39 for(REPSocketChannel<REPCommand> channel : list){
|
183
|
40 channel.write(command);
|
31
|
41 }
|
|
42 }
|
|
43
|
133
|
44 public void send(REPSocketChannel<REPCommand> channel, REPCommand repCmd) {
|
38
|
45
|
|
46 }
|
|
47
|
56
|
48 public void sendToMaster(REPCommand repCmd) {
|
183
|
49 master.write(repCmd);
|
56
|
50 }
|
|
51
|
|
52 public void sendToSlave(REPCommand repCmd) {
|
133
|
53 for(REPSocketChannel<REPCommand> channel : list){
|
58
|
54 if(channel.equals(master)) continue;
|
183
|
55 channel.write(repCmd);
|
56
|
56 }
|
|
57 }
|
|
58
|
138
|
59 public void sendExcept(REPSocketChannel<REPCommand> channel2, REPCommand command) {
|
133
|
60 for(REPSocketChannel<REPCommand> channel : list){
|
138
|
61 if(channel.equals(channel2)) continue;
|
183
|
62 channel.write(command);
|
78
|
63 }
|
|
64 }
|
|
65
|
7
|
66 }
|