Mercurial > hg > RemoteEditor > Eclipse
view src/pathfinder/mergetest/EditorSimulatorWithoutMerger.java @ 154:6a3c982bd72a
*** empty log message ***
author | pin |
---|---|
date | Sun, 24 Aug 2008 13:43:50 +0900 |
parents | 6326e5ea4595 |
children | 0dfb6413a31e |
line wrap: on
line source
package pathfinder.mergetest; import remoteeditor.command.REPCommand; import remoteeditor.network.REP; public class EditorSimulatorWithoutMerger extends EditorSimulator { public EditorSimulatorWithoutMerger(int _eid, NetworkSimulator<REPCommand> _ns, String[] strings, String _name) { super(_eid, _ns, strings, _name); } public void run(){ ns.writeLog("Editor" + eid + " start.", 1); while(running){ // MainLoop while(running){ REPCommand cmd = cs.read(); /* received Command */ ns.writeLog("\tEditor"+eid+" catch command from "+cmd.eid+" NO."+cmd.seq, 3); //if (eid == 0) ns.writeLog("\tEditor"+eid+" catch command from "+cmd.eid+" :"+cmd, 1); //manage(cmd); if(cmd.cmd == REP.SMCMD_QUIT_2){ cs.write(new REPCommand(cmd)); running = false; break; } if (cmd.eid==eid){ //発行したコマンドが戻ってきた場合 cs.write(new REPCommand(cmd)); } else if (cmd.eid==-1){ /* 制御プロセスからの指令 */ ns.writeLog("\tEditor"+eid+" send command.", 2); if (cmd.cmd==REP.SMCMD_QUIT) { //sendOneCommand(cmd); cs.write(cmd); synchronized(ns){ ns.writeLog("send Quit cmd.", 1); } continue; } //if(lock) continue; String replacedText = text.edit(cmd); sendOneCommand(cmd, replacedText); }else if(cmd.eid == -2){ // Merged Commands. String replacedText = text.edit(cmd); //sendOneCommand(cmd, replacedText); /* 終了条件 */ if (cmd.cmd==REP.SMCMD_QUIT){ ns.writeLog("\tEditor"+eid+" catch QUIT command emited by itself.", 3); running=false; break; }else{ cs.write(new REPCommand(cmd)); } } else { ns.writeLog("\t\tEditor"+eid+" edit text and pass Cmd. " + " : " + cmd, 3); text.edit(cmd); cs.write(new REPCommand(cmd)); } } ns.writeLog("Editor"+eid+" finish.", 1); } } private void manage(REPCommand cmd) { // TODO Auto-generated method stub switch(cmd.cmd){ case REP.SMCMD_START_MERGE: lockEdit(true); break; case REP.SMCMD_END_MERGE: lockEdit(false); break; default: break; } } private void lockEdit(boolean b) { } protected void sendOneCommand(REPCommand cmd, String replacedText){ if (cmd==null) return; cmd.eid = eid; cmd.seq = seq++; if(cmd.cmd == REP.REPCMD_INSERT){ //cmd.setString("inserted by Editor"+cmd.eid+":"+cmd.seq); cs.write(cmd); }else if(cmd.cmd == REP.REPCMD_DELETE){ ///String line = text.get(cmd.lineno); //cmd.setString(line); cmd.setString(replacedText); cs.write(cmd); }else if(cmd.cmd == REP.REPCMD_REPLACE){ REPCommand deleteCmd = new REPCommand(REP.REPCMD_DELETE, 0, eid, seq-1, cmd.lineno, 0, ""); //undoCmd.setString(text.get(cmd.lineno)); deleteCmd.setString(replacedText); cs.write(deleteCmd); //cmd.setString("replaced by Editor"+cmd.eid+":"+cmd.seq); cmd.setCMD(REP.REPCMD_INSERT); cs.write(cmd); }else if(cmd.cmd == REP.SMCMD_QUIT){ //cmd.setString("sent by Editor"+cmd.eid+":"+cmd.seq); cs.write(cmd); } //text.edit(cmd); //Thread.yield(); } }