annotate rep/SessionManagerList.java @ 82:4bb583553a42

*** empty log message ***
author pin
date Tue, 11 Dec 2007 14:26:13 +0900
parents 8a4f92f31c58
children 8dce4348966c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
1 package rep;
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
2
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
3 import java.nio.channels.SocketChannel;
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
4 import java.util.LinkedList;
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
5 import java.util.List;
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
6
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
7 import rep.xml.SessionXMLEncoder;
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
8
7
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
9 public class SessionManagerList {
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
10
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
11 private List<SocketChannel> list = new LinkedList<SocketChannel>();
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
12 private int mySMID;
25
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
13 private SocketChannel master;
7
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
14
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
15 public void add(SocketChannel channel) {
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
16 list.add(channel);
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
17 }
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
18
21
2d4bab638a71 *** empty log message ***
pin
parents: 7
diff changeset
19 public void sendUpdate(int sessionID, String string) {
7
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
20 for(SocketChannel channel : list){
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
21 REPPacketSend send = new REPPacketSend(channel);
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
22 send.send(new REPCommand(REP.SMCMD_UPDATE, 0, mySMID, 0, 0, string.length(), string));
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
23 }
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
24 }
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
25
21
2d4bab638a71 *** empty log message ***
pin
parents: 7
diff changeset
26 public void sendJoin(REPCommand command) {
2d4bab638a71 *** empty log message ***
pin
parents: 7
diff changeset
27 for(SocketChannel channel : list){
2d4bab638a71 *** empty log message ***
pin
parents: 7
diff changeset
28 REPPacketSend send = new REPPacketSend(channel);
2d4bab638a71 *** empty log message ***
pin
parents: 7
diff changeset
29 send.send(command);
2d4bab638a71 *** empty log message ***
pin
parents: 7
diff changeset
30 }
2d4bab638a71 *** empty log message ***
pin
parents: 7
diff changeset
31 }
25
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
32
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
33 public void sendUpdateUp(REPCommand command){
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
34 REPPacketSend send = new REPPacketSend(master);
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
35 command.setCMD(REP.SMCMD_UPDATE_UP);
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
36 send.send(command);
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
37 }
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
38
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
39 public void sendUpdateDown(REPCommand command){
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
40 command.setCMD(REP.SMCMD_UPDATE_DOWN);
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
41 for(SocketChannel channel : list){
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
42 if(channel == master) continue;
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
43 REPPacketSend send = new REPPacketSend(channel);
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
44 send.send(command);
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
45 }
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
46 }
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
47
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
48 public void setMaster(SocketChannel channel){
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
49 this.master = channel;
2b4863af8804 *** empty log message ***
pin
parents: 21
diff changeset
50 }
21
2d4bab638a71 *** empty log message ***
pin
parents: 7
diff changeset
51
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
52 public void sendSessionList(SessionList sessionlist, REPCommand command) {
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
53 SessionXMLEncoder encoder = new SessionXMLEncoder(sessionlist);
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
54 command.setString(encoder.sessionListToXML());
31
593f915dd6ff for JOIN and PUT Testing
pin
parents: 25
diff changeset
55
593f915dd6ff for JOIN and PUT Testing
pin
parents: 25
diff changeset
56 for(SocketChannel channel : list){
593f915dd6ff for JOIN and PUT Testing
pin
parents: 25
diff changeset
57 REPPacketSend send = new REPPacketSend(channel);
593f915dd6ff for JOIN and PUT Testing
pin
parents: 25
diff changeset
58 send.send(command);
593f915dd6ff for JOIN and PUT Testing
pin
parents: 25
diff changeset
59 }
593f915dd6ff for JOIN and PUT Testing
pin
parents: 25
diff changeset
60 }
593f915dd6ff for JOIN and PUT Testing
pin
parents: 25
diff changeset
61
38
de8638eb0edd *** empty log message ***
pin
parents: 31
diff changeset
62 public void send(SocketChannel channel, REPCommand repCmd) {
de8638eb0edd *** empty log message ***
pin
parents: 31
diff changeset
63
de8638eb0edd *** empty log message ***
pin
parents: 31
diff changeset
64 }
de8638eb0edd *** empty log message ***
pin
parents: 31
diff changeset
65
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
66 public void sendToMaster(REPCommand repCmd) {
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
67 REPPacketSend send = new REPPacketSend(master);
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
68 send.send(repCmd);
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
69 }
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
70
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
71 public void sendToSlave(REPCommand repCmd) {
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
72 for(SocketChannel channel : list){
58
fca7217dab1e *** empty log message ***
pin
parents: 56
diff changeset
73 if(channel.equals(master)) continue;
56
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
74 REPPacketSend send = new REPPacketSend(channel);
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
75 send.send(repCmd);
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
76 }
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
77 }
6ead43b2475e *** empty log message ***
pin
parents: 39
diff changeset
78
78
8a4f92f31c58 *** empty log message ***
pin
parents: 58
diff changeset
79 public void sendExcept(SocketChannel exceptChannel, REPCommand command) {
8a4f92f31c58 *** empty log message ***
pin
parents: 58
diff changeset
80 for(SocketChannel channel : list){
8a4f92f31c58 *** empty log message ***
pin
parents: 58
diff changeset
81 if(channel.equals(exceptChannel)) continue;
8a4f92f31c58 *** empty log message ***
pin
parents: 58
diff changeset
82 REPPacketSend send = new REPPacketSend(channel);
8a4f92f31c58 *** empty log message ***
pin
parents: 58
diff changeset
83 send.send(command);
8a4f92f31c58 *** empty log message ***
pin
parents: 58
diff changeset
84 }
8a4f92f31c58 *** empty log message ***
pin
parents: 58
diff changeset
85 }
8a4f92f31c58 *** empty log message ***
pin
parents: 58
diff changeset
86
7
5067a6a93d01 *** empty log message ***
pin
parents:
diff changeset
87 }