7
|
1 package rep;
|
|
2
|
|
3 import java.nio.channels.SocketChannel;
|
|
4 import java.util.LinkedList;
|
|
5 import java.util.List;
|
|
6
|
56
|
7 import rep.xml.SessionXMLEncoder;
|
|
8
|
7
|
9 public class SessionManagerList {
|
|
10
|
|
11 private List<SocketChannel> list = new LinkedList<SocketChannel>();
|
|
12 private int mySMID;
|
25
|
13 private SocketChannel master;
|
7
|
14
|
|
15 public void add(SocketChannel channel) {
|
|
16 list.add(channel);
|
|
17 }
|
|
18
|
21
|
19 public void sendUpdate(int sessionID, String string) {
|
7
|
20 for(SocketChannel channel : list){
|
|
21 REPPacketSend send = new REPPacketSend(channel);
|
|
22 send.send(new REPCommand(REP.SMCMD_UPDATE, 0, mySMID, 0, 0, string.length(), string));
|
|
23 }
|
|
24 }
|
|
25
|
21
|
26 public void sendJoin(REPCommand command) {
|
|
27 for(SocketChannel channel : list){
|
|
28 REPPacketSend send = new REPPacketSend(channel);
|
|
29 send.send(command);
|
|
30 }
|
|
31 }
|
25
|
32
|
|
33 public void sendUpdateUp(REPCommand command){
|
|
34 REPPacketSend send = new REPPacketSend(master);
|
|
35 command.setCMD(REP.SMCMD_UPDATE_UP);
|
|
36 send.send(command);
|
|
37 }
|
|
38
|
|
39 public void sendUpdateDown(REPCommand command){
|
|
40 command.setCMD(REP.SMCMD_UPDATE_DOWN);
|
|
41 for(SocketChannel channel : list){
|
|
42 if(channel == master) continue;
|
|
43 REPPacketSend send = new REPPacketSend(channel);
|
|
44 send.send(command);
|
|
45 }
|
|
46 }
|
|
47
|
|
48 public void setMaster(SocketChannel channel){
|
|
49 this.master = channel;
|
|
50 }
|
21
|
51
|
56
|
52 public void sendSessionList(SessionList sessionlist, REPCommand command) {
|
|
53 SessionXMLEncoder encoder = new SessionXMLEncoder(sessionlist);
|
|
54 command.setString(encoder.sessionListToXML());
|
31
|
55
|
|
56 for(SocketChannel channel : list){
|
|
57 REPPacketSend send = new REPPacketSend(channel);
|
|
58 send.send(command);
|
|
59 }
|
|
60 }
|
|
61
|
38
|
62 public void send(SocketChannel channel, REPCommand repCmd) {
|
|
63
|
|
64 }
|
|
65
|
56
|
66 public void sendToMaster(REPCommand repCmd) {
|
|
67 REPPacketSend send = new REPPacketSend(master);
|
|
68 send.send(repCmd);
|
|
69 }
|
|
70
|
|
71 public void sendToSlave(REPCommand repCmd) {
|
|
72 for(SocketChannel channel : list){
|
58
|
73 if(channel.equals(master)) continue;
|
56
|
74 REPPacketSend send = new REPPacketSend(channel);
|
|
75 send.send(repCmd);
|
|
76 }
|
|
77 }
|
|
78
|
78
|
79 public void sendExcept(SocketChannel exceptChannel, REPCommand command) {
|
|
80 for(SocketChannel channel : list){
|
|
81 if(channel.equals(exceptChannel)) continue;
|
|
82 REPPacketSend send = new REPPacketSend(channel);
|
|
83 send.send(command);
|
|
84 }
|
|
85 }
|
|
86
|
7
|
87 }
|