22
|
1 package rep;
|
|
2
|
23
|
3 import java.nio.channels.SocketChannel;
|
|
4 import java.util.LinkedList;
|
|
5
|
22
|
6 public class EditorList {
|
|
7
|
23
|
8 private int numberOfEditor;
|
|
9 private LinkedList<Editor> editorList = new LinkedList<Editor>();
|
|
10
|
22
|
11 public void sendJoinAck(REPCommand repCmd) {
|
23
|
12 Editor editor = null;
|
|
13 for(Editor editor2 : editorList){
|
24
|
14 error(String.valueOf(editor2.getEID()), String.valueOf(repCmd.eid));
|
23
|
15 if(editor2.getEID() == repCmd.eid){
|
|
16 editor = editor2;
|
24
|
17 break;
|
23
|
18 }
|
|
19 }
|
24
|
20 error(editor);
|
23
|
21 REPPacketSend send = new REPPacketSend(editor.getChannel());
|
|
22 send.send(repCmd);
|
22
|
23 }
|
|
24
|
24
|
25
|
23
|
26 public void sendJoinAck(SocketChannel channel, REPCommand repCmd) {
|
|
27 REPCommand command = repCmd;
|
|
28 command.setCMD(REP.SMCMD_JOIN_ACK);
|
22
|
29
|
23
|
30 REPPacketSend send = new REPPacketSend(channel);
|
|
31 send.send(command);
|
|
32 }
|
|
33
|
|
34 public int addEditor(SocketChannel channel, REPCommand repCmd) {
|
|
35 numberOfEditor++;
|
|
36 editorList.add(new Editor(numberOfEditor, channel));
|
|
37 return numberOfEditor;
|
|
38 }
|
|
39
|
|
40 public void addEditor(SocketChannel channel) {
|
|
41 editorList.add(new Editor(0, channel));
|
|
42 }
|
|
43
|
|
44 public void setEID(REPCommand repCmd) {
|
|
45 for(Editor editor : editorList){
|
|
46 if(editor.getEID() == 0){
|
|
47 editor.setEID(repCmd.eid);
|
|
48 break;
|
|
49 }
|
|
50 }
|
22
|
51 }
|
24
|
52
|
|
53 private void error(Object obj) {
|
|
54 if(obj == null){
|
|
55 System.out.println("null!");
|
|
56 }
|
|
57 }
|
|
58 private void error(String str1, String str2){
|
|
59 if(str1.equals(str2)){
|
|
60 return;
|
|
61 }else{
|
|
62 System.out.println("Not equals! str1:str2");
|
|
63 }
|
|
64 }
|
22
|
65
|
31
|
66
|
|
67 public void sendPutAck(SocketChannel channel, REPCommand repCmd) {
|
|
68 REPPacketSend send = new REPPacketSend(channel);
|
|
69 send.send(repCmd);
|
|
70 }
|
|
71
|
|
72 public void send(SocketChannel channel, REPCommand command){
|
|
73 REPPacketSend send = new REPPacketSend(channel);
|
|
74 send.send(command);
|
|
75 }
|
|
76
|
76
|
77
|
|
78 public void setHost(String myHost) {
|
|
79 // TODO Auto-generated method stub
|
|
80 for(Editor editor : editorList) {
|
|
81 editor.setHost(myHost);
|
|
82 }
|
|
83 }
|
|
84
|
22
|
85 }
|