22
|
1 package rep;
|
|
2
|
23
|
3 import java.util.LinkedList;
|
|
4
|
131
|
5 import rep.channel.REPSocketChannel;
|
|
6
|
22
|
7 public class EditorList {
|
|
8
|
23
|
9 private int numberOfEditor;
|
|
10 private LinkedList<Editor> editorList = new LinkedList<Editor>();
|
|
11
|
22
|
12 public void sendJoinAck(REPCommand repCmd) {
|
23
|
13 Editor editor = null;
|
|
14 for(Editor editor2 : editorList){
|
24
|
15 error(String.valueOf(editor2.getEID()), String.valueOf(repCmd.eid));
|
23
|
16 if(editor2.getEID() == repCmd.eid){
|
|
17 editor = editor2;
|
24
|
18 break;
|
23
|
19 }
|
|
20 }
|
24
|
21 error(editor);
|
181
|
22 editor.getChannel().write(repCmd);
|
22
|
23 }
|
|
24
|
24
|
25
|
181
|
26 public void sendJoinAck(REPSocketChannel<REPCommand> channel, REPCommand repCmd) {
|
23
|
27 REPCommand command = repCmd;
|
|
28 command.setCMD(REP.SMCMD_JOIN_ACK);
|
181
|
29
|
|
30 channel.write(command);
|
23
|
31 }
|
|
32
|
132
|
33 public int addEditor(REPSocketChannel<REPCommand> channel, REPCommand repCmd) {
|
23
|
34 numberOfEditor++;
|
|
35 editorList.add(new Editor(numberOfEditor, channel));
|
|
36 return numberOfEditor;
|
|
37 }
|
|
38
|
132
|
39 public void addEditor(REPSocketChannel<REPCommand> channel) {
|
23
|
40 editorList.add(new Editor(0, channel));
|
|
41 }
|
|
42
|
|
43 public void setEID(REPCommand repCmd) {
|
|
44 for(Editor editor : editorList){
|
|
45 if(editor.getEID() == 0){
|
|
46 editor.setEID(repCmd.eid);
|
|
47 break;
|
|
48 }
|
|
49 }
|
22
|
50 }
|
24
|
51
|
|
52 private void error(Object obj) {
|
|
53 if(obj == null){
|
|
54 System.out.println("null!");
|
|
55 }
|
|
56 }
|
|
57 private void error(String str1, String str2){
|
|
58 if(str1.equals(str2)){
|
|
59 return;
|
|
60 }else{
|
|
61 System.out.println("Not equals! str1:str2");
|
|
62 }
|
|
63 }
|
22
|
64
|
31
|
65
|
132
|
66 public void sendPutAck(REPSocketChannel<REPCommand> channel, REPCommand repCmd) {
|
181
|
67 channel.write(repCmd);
|
31
|
68 }
|
|
69
|
132
|
70 public void send(REPSocketChannel<REPCommand> channel, REPCommand command){
|
181
|
71 channel.write(command);
|
31
|
72 }
|
|
73
|
76
|
74
|
|
75 public void setHost(String myHost) {
|
|
76 // TODO Auto-generated method stub
|
|
77 for(Editor editor : editorList) {
|
|
78 editor.setHost(myHost);
|
|
79 }
|
|
80 }
|
|
81
|
85
|
82
|
|
83 public Editor getEditor(String hostport) {
|
|
84 // TODO Auto-generated method stub
|
|
85 for(Editor editor : editorList){
|
86
|
86 String[] splited = hostport.split(":");
|
87
|
87 System.out.println(splited[0] + "," + editor.getHost());
|
86
|
88 if(splited[0].equals(editor.getHost())){
|
92
|
89 return editor;
|
85
|
90 }
|
92
|
91
|
86
|
92 //String hostandport = editor.getHost() + ":" + editor.getPort();
|
|
93 //if(hostport.equals(hostandport)){
|
|
94 // return editor;
|
|
95 //}
|
85
|
96 }
|
|
97 return null;
|
|
98 }
|
|
99
|
91
|
100
|
106
|
101 public int addEditor(Editor editor) {
|
|
102 numberOfEditor++;
|
91
|
103 editorList.add(editor);
|
106
|
104 return numberOfEditor;
|
91
|
105 }
|
|
106
|
122
|
107
|
181
|
108 public Editor getEditor(REPSocketChannel<REPCommand> channel) {
|
122
|
109 // TODO Auto-generated method stub
|
|
110 Editor editor1 = null;
|
|
111 for(Editor editor: editorList){
|
|
112 if(channel == editor.getChannel()){
|
|
113 editor1 = editor;
|
|
114 }
|
|
115 }
|
|
116 return editor1;
|
|
117 }
|
|
118
|
22
|
119 }
|