Mercurial > hg > RemoteEditor > REPSessionManager
comparison test/sematest/TestEditor.java @ 407:de4ef4313adc current-release
looks like working...
author | one |
---|---|
date | Tue, 25 Nov 2008 17:54:54 +0900 |
parents | 8009dd7b2013 |
children | 2724cf17e9f3 |
comparison
equal
deleted
inserted
replaced
406:8009dd7b2013 | 407:de4ef4313adc |
---|---|
6 import java.util.LinkedList; | 6 import java.util.LinkedList; |
7 | 7 |
8 import rep.REP; | 8 import rep.REP; |
9 import rep.REPCommand; | 9 import rep.REPCommand; |
10 import rep.REPCommandPacker; | 10 import rep.REPCommandPacker; |
11 import rep.SessionManager; | |
11 import rep.channel.REPLogger; | 12 import rep.channel.REPLogger; |
12 import rep.channel.REPSelectionKey; | 13 import rep.channel.REPSelectionKey; |
13 import rep.channel.REPSelector; | 14 import rep.channel.REPSelector; |
14 import rep.channel.REPSocketChannel; | 15 import rep.channel.REPSocketChannel; |
15 import test.Text; | 16 import test.Text; |
59 cmds = cmdList; | 60 cmds = cmdList; |
60 if (master) { | 61 if (master) { |
61 this.master=true; | 62 this.master=true; |
62 text = new Text(txts); | 63 text = new Text(txts); |
63 cmds.add(new REPCommand(REP.SMCMD_PUT,0,0,0,0,name+"-file")); | 64 cmds.add(new REPCommand(REP.SMCMD_PUT,0,0,0,0,name+"-file")); |
64 //cmds.add(new REPCommand(REP.REPCMD_INSERT_USER,0,0,0,0,"m0")); | 65 cmds.add(new REPCommand(REP.REPCMD_INSERT_USER,0,0,0,0,"m0")); |
65 //cmds.add(new REPCommand(REP.REPCMD_DELETE_USER,0,0,0,0,"m0")); | 66 cmds.add(new REPCommand(REP.REPCMD_DELETE_USER,0,0,0,0,"m0")); |
66 //cmds.add(new REPCommand(REP.SMCMD_QUIT,0,0,0,0,"")); | 67 //cmds.add(new REPCommand(REP.SMCMD_QUIT,0,0,0,0,"")); |
67 } else { | 68 } else { |
68 text = new Text(new String[0]); | 69 text = new Text(new String[0]); |
69 cmds.add(new REPCommand(REP.SMCMD_JOIN,0,0,0,0,name)); | 70 cmds.add(new REPCommand(REP.SMCMD_JOIN,0,0,0,0,name)); |
70 cmds.add(new REPCommand(REP.REPCMD_INSERT_USER,0,0,0,0,"c0")); | 71 cmds.add(new REPCommand(REP.REPCMD_INSERT_USER,0,0,0,0,"c0")); |
148 /* | 149 /* |
149 * Send delete/insert one at a time to synchronize | 150 * Send delete/insert one at a time to synchronize |
150 * all clients. SYNC is requested by the session manager. | 151 * all clients. SYNC is requested by the session manager. |
151 */ | 152 */ |
152 if (syncCounter>text.size()) { | 153 if (syncCounter>text.size()) { |
154 SessionManager.logger.writeLog("Sync Completed."); | |
153 syncCounter=0; | 155 syncCounter=0; |
154 } else { | 156 } else { |
155 int i=syncCounter-1; | 157 int i=syncCounter-1; |
156 REPCommand del = new REPCommand(REP.REPCMD_DELETE_USER,sid,eid,0,i, text.get(i)); | 158 REPCommand del = new REPCommand(REP.REPCMD_DELETE_USER,sid,eid,0,i, text.get(i)); |
157 REPCommand ins = new REPCommand(REP.REPCMD_INSERT_USER,sid,eid,0,i, text.get(i)); | 159 REPCommand ins = new REPCommand(REP.REPCMD_INSERT_USER,sid,eid,0,i, text.get(i)); |
225 channel.write(cmd); | 227 channel.write(cmd); |
226 } | 228 } |
227 | 229 |
228 private void handle(REPCommand cmd) { | 230 private void handle(REPCommand cmd) { |
229 if (cmd==null) return; | 231 if (cmd==null) return; |
230 ns.writeLog(name +": read "+cmd); | 232 ns.writeLog(name +": read "+cmd + " textsize="+text.size()); |
231 switch(cmd.cmd) { | 233 switch(cmd.cmd) { |
232 case REPCMD_INSERT : | 234 case REPCMD_INSERT : |
233 if (cmd.eid!=eid) { | 235 if (cmd.eid!=eid) { |
234 text.insert(cmd.lineno, cmd.string); | 236 text.insert(cmd.lineno, cmd.string); |
235 } | 237 } |
236 forwardCommand(cmd); | 238 forwardCommand(cmd); |
237 break; | 239 break; |
238 case REPCMD_DELETE : | 240 case REPCMD_DELETE : |
239 if (cmd.eid!=eid) { | 241 if (cmd.eid!=eid) { |
240 String del=""; | 242 String del=""; |
241 if(cmd.lineno>text.size()) { | 243 if(cmd.lineno<text.size()) { |
242 del = text.delete(cmd.lineno); | 244 del = text.delete(cmd.lineno); |
243 } | 245 } |
244 cmd.setString(del); | 246 cmd.setString(del); |
245 } | 247 } |
246 forwardCommand(cmd); | 248 forwardCommand(cmd); |