148
|
1 package pathfinder.mergetest;
|
|
2
|
|
3 import java.util.Queue;
|
|
4
|
|
5 import remoteeditor.command.REPCommand;
|
|
6 import remoteeditor.network.REP;
|
|
7
|
|
8 public class EditorSimulatorWithoutMerger extends EditorSimulator {
|
|
9
|
|
10 public EditorSimulatorWithoutMerger(int _eid, NetworkSimulator<REPCommand> _ns, Queue<REPCommand> q, String _name) {
|
|
11 super(_eid, _ns, q, _name);
|
|
12 }
|
|
13
|
|
14 public void run(){
|
149
|
15 ns.writeLog("Editor" + eid + " start.", 1);
|
|
16
|
148
|
17 while(running){
|
149
|
18
|
|
19 // MainLoop
|
|
20 while(running){
|
|
21
|
|
22 REPCommand cmd = cs.read();
|
|
23 /* received Command */
|
|
24
|
|
25 ns.writeLog("\tEditor"+eid+" catch command from "+cmd.eid+" NO."+cmd.seq, 3);
|
|
26 //if (cmd.eid != -2 && eid == 0) ns.writeLog("\tEditor"+eid+" catch command from "+cmd.eid+" :"+cmd, 1);
|
|
27
|
|
28 //System.out.println(eid + ":" + cmd.eid);
|
|
29
|
|
30 if (cmd.eid==eid){
|
|
31
|
|
32 text.edit(cmd);
|
|
33 cs.write(new REPCommand(cmd));
|
|
34
|
|
35 /* 終了条件 */
|
|
36 if (cmd.cmd==REP.SMCMD_QUIT){
|
|
37 ns.writeLog("\tEditor"+eid+" catch QUIT command emited by itself.", 3);
|
|
38 running=false; break;
|
|
39 }
|
|
40 } else if (cmd.eid==-1){
|
|
41 /* 制御プロセスからの指令 */
|
|
42 ns.writeLog("\tEditor"+eid+" send command.", 2);
|
|
43 if (cmd.cmd==REP.SMCMD_QUIT)
|
|
44 synchronized(ns){ ns.writeLog("send Quit cmd.", 1); }
|
|
45
|
|
46 sendOneCommand(cmd);
|
|
47
|
|
48 }else if(cmd.eid == -2){
|
|
49 // Merged Commands.
|
|
50 text.edit(cmd);
|
|
51 } else {
|
|
52
|
|
53 ns.writeLog("\t\tEditor"+eid+" edit text and pass Cmd. " + " : " + cmd, 3);
|
|
54 text.edit(cmd);
|
|
55 cs.write(new REPCommand(cmd));
|
148
|
56 }
|
|
57 }
|
149
|
58
|
|
59 ns.writeLog("Editor"+eid+" finish.", 1);
|
148
|
60 }
|
|
61 }
|
|
62
|
149
|
63 protected void sendOneCommand(REPCommand cmd){
|
|
64
|
|
65 if (cmd==null) cmd = CmdList.poll();
|
|
66 if (cmd==null) return;
|
|
67
|
|
68 cmd.eid = eid;
|
|
69 cmd.seq = seq++;
|
148
|
70 cmd.setString("inserted by Editor"+cmd.eid+":"+cmd.seq);
|
|
71
|
149
|
72 text.edit(cmd);
|
|
73 cs.write(new REPCommand(cmd));
|
|
74
|
148
|
75 Thread.yield();
|
|
76 }
|
149
|
77
|
148
|
78 }
|