annotate src/pathfinder/mergetest/EditorSimulatorWithoutMerger.java @ 149:5942e0e3c632

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