Mercurial > hg > RemoteEditor > REPSessionManager
comparison rep/handler/Editor.java @ 404:4bb04d5a9bbf
minor fix
author | one |
---|---|
date | Tue, 25 Nov 2008 03:29:47 +0900 |
parents | 2cf5392b2a9f |
children | 8009dd7b2013 |
comparison
equal
deleted
inserted
replaced
403:e94a3820c13a | 404:4bb04d5a9bbf |
---|---|
61 return; | 61 return; |
62 case REPCMD_INSERT: | 62 case REPCMD_INSERT: |
63 case REPCMD_DELETE: | 63 case REPCMD_DELETE: |
64 if (command.eid == REP.MERGE_EID.id){ | 64 if (command.eid == REP.MERGE_EID.id){ |
65 //マージコマンドが返ってきた | 65 //マージコマンドが返ってきた |
66 checkDouble(sentList); | |
67 if(translator.checkMergeConflict(command)){ | 66 if(translator.checkMergeConflict(command)){ |
68 //マージ中にエディタからの割り込みがあった場合 | 67 //マージ中にエディタからの割り込みがあった場合 |
69 translator.getMergeAgain(this); | 68 translator.getMergeAgain(this); |
70 } | 69 } |
71 checkEndMerge(); | 70 checkEndMerge(); |
72 checkDouble(sentList); | |
73 return; | 71 return; |
74 } else if (command.eid == eid){ | 72 } else if (command.eid == eid){ |
75 // 編集コマンドが一周して来た | 73 // 編集コマンドが一周して来た |
76 if (waitingRequired(command)) return; | 74 if (waitingRequired(command)) return; |
77 checkReturnedCommand(command); | 75 checkReturnedCommand(command); |
78 checkDouble(sentList); | |
79 return; | 76 return; |
80 } | 77 } |
81 | 78 |
82 //他のエディタからの編集コマンド | 79 //他のエディタからの編集コマンド |
83 if (waitingRequired(command)) return; | 80 if (waitingRequired(command)) return; |
96 private void userEditorCommand(REPCommand command) { | 93 private void userEditorCommand(REPCommand command) { |
97 //エディタからの新たな編集コマンド | 94 //エディタからの新たな編集コマンド |
98 if (next==this) return; // singleton case | 95 if (next==this) return; // singleton case |
99 translator.transSendCmd(command); | 96 translator.transSendCmd(command); |
100 sendEditorCommand(command); | 97 sendEditorCommand(command); |
101 checkDouble(sentList); | |
102 return; | 98 return; |
103 } | 99 } |
104 | 100 |
105 private void checkDouble(List<REPCommand> sentList) { | 101 // private void checkDouble(List<REPCommand> sentList) { |
106 if (sentList.size()==0) return; | 102 // if (sentList.size()==0) return; |
107 int count = 0; | 103 // int count = 0; |
108 REPCommand f = sentList.get(0); | 104 // REPCommand f = sentList.get(0); |
109 for(REPCommand c:sentList) { | 105 // for(REPCommand c:sentList) { |
110 if (c.eid==f.eid&&c.seq==f.seq) { | 106 // if (c.eid==f.eid&&c.seq==f.seq) { |
111 count++; | 107 // count++; |
112 } | 108 // } |
113 } | 109 // } |
114 assert(count==1); | 110 // assert(count==1); |
115 if (true) return; | 111 // if (true) return; |
116 count = 0; | 112 // count = 0; |
117 for(PacketSet c:waitingCommandInMerge) { | 113 // for(PacketSet c:waitingCommandInMerge) { |
118 for(REPCommand g:sentList) { | 114 // for(REPCommand g:sentList) { |
119 if (c.command.eid==g.eid&&c.command.seq==g.seq) { | 115 // if (c.command.eid==g.eid&&c.command.seq==g.seq) { |
120 count++; | 116 // count++; |
121 } | 117 // } |
122 } | 118 // } |
123 } | 119 // } |
124 assert(count==0); | 120 // assert(count==0); |
125 } | 121 // } |
126 | 122 |
127 private boolean waitingRequired(REPCommand command) { | 123 private boolean waitingRequired(REPCommand command) { |
128 if (hasWaitingCommand()) { | 124 if (hasWaitingCommand()) { |
129 // We cannot do this operation before watingCommandQueue. | 125 // We cannot do this operation before watingCommandQueue. |
130 addWaitingCommand(new PacketSet(channel, this, new REPCommand(command))); | 126 addWaitingCommand(new PacketSet(channel, this, new REPCommand(command))); |
131 checkDouble(sentList); | |
132 return true; | 127 return true; |
133 } else if (isMerging()) { | 128 } else if (isMerging()) { |
134 addWaitingCommand(new PacketSet(getChannel(), this, new REPCommand(command))); | 129 addWaitingCommand(new PacketSet(getChannel(), this, new REPCommand(command))); |
135 checkDouble(sentList); | |
136 return true; | 130 return true; |
137 } | 131 } |
138 checkDouble(sentList); | |
139 ServerMainLoop.logger.writeLog("Editor eid:"+eid+" no waiting"); | 132 ServerMainLoop.logger.writeLog("Editor eid:"+eid+" no waiting"); |
140 return false; | 133 return false; |
141 } | 134 } |
142 | 135 |
143 public void addWaitingCommand(PacketSet set) { | 136 public void addWaitingCommand(PacketSet set) { |
152 | 145 |
153 private void sendEditorCommand(REPCommand command) { | 146 private void sendEditorCommand(REPCommand command) { |
154 REPCommand keep = new REPCommand(command); | 147 REPCommand keep = new REPCommand(command); |
155 sentList.add(keep); | 148 sentList.add(keep); |
156 ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList); | 149 ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList); |
157 checkDouble(sentList); | |
158 assert(sentList.size()<limit); | 150 assert(sentList.size()<limit); |
159 next.send(command); | 151 next.send(command); |
160 } | 152 } |
161 | 153 |
162 boolean merge(REPCommand command) { | 154 boolean merge(REPCommand command) { |
164 return translator.catchOwnCommand(this); | 156 return translator.catchOwnCommand(this); |
165 } | 157 } |
166 | 158 |
167 /** | 159 /** |
168 * 一周して来たcommandの処理。 | 160 * 一周して来たcommandの処理。 |
161 * | |
162 * INSERT/DELETEを受け取った時に、sentListに登録 | |
163 * INSERT_ACK/DELETE_ACKが来たら一周。そこで、Mergeする。 | |
164 * | |
165 * 自分が出したINSERT/DELETEが戻って来たら、ACKに変更して、Merge。 | |
166 * | |
167 * 途中から参加した場合、自分が受けとってないcommandのACKが先に来ることが | |
168 * ある。それは、無視して良い。 | |
169 * @param command | 169 * @param command |
170 */ | 170 */ |
171 void checkReturnedCommand(REPCommand command) { | 171 void checkReturnedCommand(REPCommand command) { |
172 assert(!merging); | 172 assert(!merging); |
173 if (sentList.size()==0) { | 173 if (sentList.size()==0) { |
174 ServerMainLoop.logger.writeLog("Editor eid="+eid+" looped command not registered: "+command); | 174 ServerMainLoop.logger.writeLog("Editor eid="+eid+" looped command not registered: "+command); |
175 assert(false); | 175 assert(command.cmd==REP.REPCMD_DELETE_ACK|| |
176 command.cmd==REP.REPCMD_INSERT_ACK); | |
177 return; | |
176 } | 178 } |
177 REPCommand prev = sentList.remove(0); | 179 REPCommand prev = sentList.remove(0); |
178 ServerMainLoop.logger.writeLog("Editor eid="+eid+" remove sentList:"+(prev==null?"null":prev)); | 180 // ServerMainLoop.logger.writeLog("Editor eid="+eid+" remove sentList:"+(prev==null?"null":prev)); |
179 if (prev==null || prev.seq != command.seq || prev.eid!=command.eid) { | 181 if (prev==null || prev.seq != command.seq || prev.eid!=command.eid) { |
180 String err = "Editor eid="+eid+" checkReturnedCommand() : command = " + command + " prev="+ | 182 String err = "Editor eid="+eid+" checkReturnedCommand() : command = " + command + " prev="+ |
181 (prev==null?"null":prev)+" sentList="; | 183 (prev==null?"null":prev)+" sentList="; |
182 err += sentList; | 184 err += sentList; |
183 ServerMainLoop.logger.writeLog(err); | 185 ServerMainLoop.logger.writeLog(err); |
184 assert(false); | 186 assert(command.cmd==REP.REPCMD_DELETE_ACK|| |
187 command.cmd==REP.REPCMD_INSERT_ACK); | |
188 sentList.add(0,prev); | |
189 return; | |
185 } | 190 } |
186 startMerge(command); | 191 startMerge(command); |
187 return; | 192 return; |
188 } | 193 } |
189 | 194 |
190 private void startMerge(REPCommand command) { | 195 private void startMerge(REPCommand command) { |
191 preMergeCommand = new REPCommand(command); | 196 preMergeCommand = new REPCommand(command); |
192 preMergeCommand.string = ""; | 197 preMergeCommand.string = ""; |
193 checkDouble(sentList); | |
194 // merge は必須だが、EditorのCommand実装をテストするには邪魔なので、off に出来るようにする。 | 198 // merge は必須だが、EditorのCommand実装をテストするには邪魔なので、off に出来るようにする。 |
195 if (noMergeMode) { | 199 if (noMergeMode) { |
196 endMerge(); | 200 endMerge(); |
197 return; | 201 return; |
198 } | 202 } |
202 send(cmd); | 206 send(cmd); |
203 merging = true; | 207 merging = true; |
204 // Session Manager 側で、このeditorへの他のeditorからの | 208 // Session Manager 側で、このeditorへの他のeditorからの |
205 // 入力を止めて、merge にそなえる。merge は、eidtor 側から | 209 // 入力を止めて、merge にそなえる。merge は、eidtor 側から |
206 // ACKが来てから始まる。 | 210 // ACKが来てから始まる。 |
207 checkDouble(sentList); | |
208 translator.startMerge(cmd); | 211 translator.startMerge(cmd); |
209 } | 212 } |
210 | 213 |
211 @Override | 214 @Override |
212 public void setQuit2(REPCommand cmd) { | 215 public void setQuit2(REPCommand cmd) { |
253 case REPCMD_DELETE: keep.cmd = REP.REPCMD_DELETE_ACK;break; | 256 case REPCMD_DELETE: keep.cmd = REP.REPCMD_DELETE_ACK;break; |
254 } | 257 } |
255 sentList.add(keep); | 258 sentList.add(keep); |
256 ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList); | 259 ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList); |
257 assert(sentList.size()<limit); | 260 assert(sentList.size()<limit); |
258 checkDouble(sentList); | |
259 next.send(keep); | 261 next.send(keep); |
260 } else { | 262 } else { |
261 next.send(preMergeCommand); | 263 next.send(preMergeCommand); |
262 } | 264 } |
263 preMergeCommand = null; | 265 preMergeCommand = null; |
345 @Override | 347 @Override |
346 public void handle(REPCommand command, REPSelectionKey<REPCommand> key) throws IOException { | 348 public void handle(REPCommand command, REPSelectionKey<REPCommand> key) throws IOException { |
347 ServerMainLoop.logger.writeLog("Manager "+manager.getId()+" read : command = " + command | 349 ServerMainLoop.logger.writeLog("Manager "+manager.getId()+" read : command = " + command |
348 +" from "+manager.editorList.editorByChannel(channel)); | 350 +" from "+manager.editorList.editorByChannel(channel)); |
349 if (command.cmd==REP.SMCMD_JOIN||command.cmd==REP.SMCMD_PUT) { | 351 if (command.cmd==REP.SMCMD_JOIN||command.cmd==REP.SMCMD_PUT) { |
350 assert false; | 352 // assert false; |
351 // 若干問題があるらしい | 353 // 若干問題があるらしい |
352 next = new Forwarder(manager,next.channel); | 354 next = new Forwarder(manager,next.channel); |
353 REPNode first = new FirstConnector(manager,channel); | 355 REPNode first = new FirstConnector(manager,channel); |
354 first.handle(command, key); | 356 first.handle(command, key); |
355 key.attach(new Dispatcher(manager,channel)); | 357 key.attach(new Dispatcher(manager,channel)); |
356 return; | 358 return; |
357 } | 359 } |
358 if (manager.sessionManage(this, command)) return; | 360 if (manager.sessionManage(this, command)) return; |
359 checkDouble(sentList); | |
360 manage(command); | 361 manage(command); |
361 checkDouble(sentList); | |
362 } | 362 } |
363 | 363 |
364 @Override | 364 @Override |
365 public void cancel(REPSocketChannel<REPCommand> socketChannel) { | 365 public void cancel(REPSocketChannel<REPCommand> socketChannel) { |
366 manager.remove(socketChannel); | 366 manager.remove(socketChannel); |