annotate src/pathfinder/mergetest/EditorSimulatorWithoutMerger.java @ 164:5c458f1a7679

*** empty log message ***
author tkaito
date Thu, 28 Aug 2008 22:18:28 +0900
parents e9047957acc2
children bf0ca6c43834
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
148
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
1 package pathfinder.mergetest;
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
2
160
e9047957acc2 merge with pathfinder.simulator.*
kent
parents: 156
diff changeset
3 import pathfinder.mergetest.channels.NetworkSimulator;
148
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
4 import remoteeditor.command.REPCommand;
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
5 import remoteeditor.network.REP;
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
6
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
7 public class EditorSimulatorWithoutMerger extends EditorSimulator {
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
8
153
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
9 public EditorSimulatorWithoutMerger(int _eid, NetworkSimulator<REPCommand> _ns, String[] strings, String _name) {
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
10 super(_eid, _ns, strings, _name);
148
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
11 }
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
12
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
13 public void run(){
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
14 ns.writeLog("Editor" + eid + " start.", 1);
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
15
148
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
16 while(running){
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
17
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
18 // MainLoop
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
19 while(running){
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
20
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
21 REPCommand cmd = cs.read();
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
22 /* received Command */
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
23
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
24 ns.writeLog("\tEditor"+eid+" catch command from "+cmd.eid+" NO."+cmd.seq, 3);
154
6a3c982bd72a *** empty log message ***
pin
parents: 153
diff changeset
25 //if (eid == 0) ns.writeLog("\tEditor"+eid+" catch command from "+cmd.eid+" :"+cmd, 1);
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
26
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
27 //manage(cmd);
154
6a3c982bd72a *** empty log message ***
pin
parents: 153
diff changeset
28
6a3c982bd72a *** empty log message ***
pin
parents: 153
diff changeset
29 if(cmd.cmd == REP.SMCMD_QUIT_2){
6a3c982bd72a *** empty log message ***
pin
parents: 153
diff changeset
30 cs.write(new REPCommand(cmd));
6a3c982bd72a *** empty log message ***
pin
parents: 153
diff changeset
31 running = false;
6a3c982bd72a *** empty log message ***
pin
parents: 153
diff changeset
32 break;
6a3c982bd72a *** empty log message ***
pin
parents: 153
diff changeset
33 }
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
34
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
35 if (cmd.eid==eid){
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
36 //発行したコマンドが戻ってきた場合
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
37 cs.write(new REPCommand(cmd));
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
38
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
39 } else if (cmd.eid==-1){
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
40 /* 制御プロセスからの指令 */
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
41 ns.writeLog("\tEditor"+eid+" send command.", 2);
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
42 if (cmd.cmd==REP.SMCMD_QUIT) {
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
43 //sendOneCommand(cmd);
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
44 cs.write(cmd);
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
45 synchronized(ns){ ns.writeLog("send Quit cmd.", 1); }
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
46 continue;
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
47 }
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
48
153
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
49 //if(lock) continue;
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
50 String replacedText = text.edit(cmd);
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
51 sendOneCommand(cmd, replacedText);
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
52
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
53 }else if(cmd.eid == -2){
151
1768e68ba98e *** empty log message ***
pin
parents: 149
diff changeset
54
1768e68ba98e *** empty log message ***
pin
parents: 149
diff changeset
55 /* 終了条件 */
1768e68ba98e *** empty log message ***
pin
parents: 149
diff changeset
56 if (cmd.cmd==REP.SMCMD_QUIT){
1768e68ba98e *** empty log message ***
pin
parents: 149
diff changeset
57 ns.writeLog("\tEditor"+eid+" catch QUIT command emited by itself.", 3);
1768e68ba98e *** empty log message ***
pin
parents: 149
diff changeset
58 running=false; break;
1768e68ba98e *** empty log message ***
pin
parents: 149
diff changeset
59 }else{
155
0dfb6413a31e *** empty log message ***
pin
parents: 154
diff changeset
60 // Merged Commands.
0dfb6413a31e *** empty log message ***
pin
parents: 154
diff changeset
61 String replacedText = text.edit(cmd);
0dfb6413a31e *** empty log message ***
pin
parents: 154
diff changeset
62 returnMergedCommand(cmd, replacedText);
151
1768e68ba98e *** empty log message ***
pin
parents: 149
diff changeset
63 }
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
64 } else {
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
65
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
66 ns.writeLog("\t\tEditor"+eid+" edit text and pass Cmd. " + " : " + cmd, 3);
156
7ebd30e5e385 *** empty log message ***
pin
parents: 155
diff changeset
67 //if(eid == 2)ns.writeLog("\t\tEditor"+eid+" edit text and pass Cmd. " + " : " + cmd, 1);
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
68 text.edit(cmd);
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
69 cs.write(new REPCommand(cmd));
148
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
70 }
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
71 }
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
72
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
73 ns.writeLog("Editor"+eid+" finish.", 1);
148
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
74 }
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
75 }
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
76
155
0dfb6413a31e *** empty log message ***
pin
parents: 154
diff changeset
77 private void returnMergedCommand(REPCommand cmd, String replacedText) {
0dfb6413a31e *** empty log message ***
pin
parents: 154
diff changeset
78 REPCommand command = new REPCommand(cmd);
0dfb6413a31e *** empty log message ***
pin
parents: 154
diff changeset
79 if(command.cmd == REP.REPCMD_DELETE)command.setString(replacedText);
0dfb6413a31e *** empty log message ***
pin
parents: 154
diff changeset
80 cs.write(command);
0dfb6413a31e *** empty log message ***
pin
parents: 154
diff changeset
81 }
0dfb6413a31e *** empty log message ***
pin
parents: 154
diff changeset
82
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
83 private void manage(REPCommand cmd) {
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
84 // TODO Auto-generated method stub
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
85 switch(cmd.cmd){
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
86 case REP.SMCMD_START_MERGE:
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
87 lockEdit(true);
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
88 break;
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
89 case REP.SMCMD_END_MERGE:
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
90 lockEdit(false);
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
91 break;
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
92 default:
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
93 break;
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
94 }
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
95 }
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
96
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
97 private void lockEdit(boolean b) {
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
98 }
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
99
153
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
100 protected void sendOneCommand(REPCommand cmd, String replacedText){
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
101
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
102 if (cmd==null) return;
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
103
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
104 cmd.eid = eid;
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
105 cmd.seq = seq++;
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
106
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
107 if(cmd.cmd == REP.REPCMD_INSERT){
153
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
108 //cmd.setString("inserted by Editor"+cmd.eid+":"+cmd.seq);
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
109 cs.write(cmd);
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
110
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
111 }else if(cmd.cmd == REP.REPCMD_DELETE){
153
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
112 ///String line = text.get(cmd.lineno);
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
113 //cmd.setString(line);
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
114 cmd.setString(replacedText);
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
115 cs.write(cmd);
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
116
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
117 }else if(cmd.cmd == REP.REPCMD_REPLACE){
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
118
153
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
119 REPCommand deleteCmd = new REPCommand(REP.REPCMD_DELETE, 0, eid, seq-1, cmd.lineno, 0, "");
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
120 //undoCmd.setString(text.get(cmd.lineno));
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
121 deleteCmd.setString(replacedText);
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
122 cs.write(deleteCmd);
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
123
153
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
124 //cmd.setString("replaced by Editor"+cmd.eid+":"+cmd.seq);
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
125 cmd.setCMD(REP.REPCMD_INSERT);
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
126 cs.write(cmd);
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
127
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
128 }else if(cmd.cmd == REP.SMCMD_QUIT){
153
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
129 //cmd.setString("sent by Editor"+cmd.eid+":"+cmd.seq);
152
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
130 cs.write(cmd);
09ad66f62f4a *** empty log message ***
pin
parents: 151
diff changeset
131 }
148
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
132
153
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
133 //text.edit(cmd);
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
134
153
6326e5ea4595 *** empty log message ***
pin
parents: 152
diff changeset
135 //Thread.yield();
148
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
136 }
149
5942e0e3c632 *** empty log message ***
pin
parents: 148
diff changeset
137
148
bc162b1a7ebf *** empty log message ***
pin
parents:
diff changeset
138 }