diff src/pathfinder/mergetest/EditorSimulator.java @ 125:34b15dfcb83e

UsersSimulator
author kent
date Tue, 25 Dec 2007 20:07:37 +0900
parents f18510fc40e2
children b56b5950cb18
line wrap: on
line diff
--- a/src/pathfinder/mergetest/EditorSimulator.java	Tue Dec 25 16:21:30 2007 +0900
+++ b/src/pathfinder/mergetest/EditorSimulator.java	Tue Dec 25 20:07:37 2007 +0900
@@ -9,7 +9,7 @@
 public class EditorSimulator extends Thread{
 	private int eid;
 	private int seq;
-	private boolean isOwner;
+	//private boolean isOwner;
 	private NetworkSimulator<REPCommand> ns;
 	private ChannelSimulator<REPCommand> cs;
 	private Queue<REPCommand> CmdList;
@@ -28,7 +28,7 @@
 	}
 
 	public void setOwner(boolean f){
-		isOwner = f;
+		//isOwner = f;
 	}
 	synchronized public void finish(){
 		running = false;
@@ -38,32 +38,36 @@
 		System.out.println("Editor"+eid+" start.");
 
 		// Send All Command that is included CmdList.
-		sendAllCommand();
+		//sendAllCommand();
 
 		// MainLoop, 
 		while(running){
 			REPCommand cmd = cs.read();
 			REPCommand[] cmds;
 
-			System.out.println("\tEditor"+eid+" catch command from "+cmd.eid+" NO."+cmd.seq);
+			//System.out.println("\tEditor"+eid+" catch command from "+cmd.eid+" NO."+cmd.seq);
 
 			if (cmd.eid==eid){
 				cmds = translater.catchOwnCommand(cmd);
 				for (int i=0; i<cmds.length; i++){
 					REPCommand tmp = cmds[i];
-					System.out.println("\t\tEditor"+eid+" edit text. ");
+					//System.out.println("\t\tEditor"+eid+" edit text. ");
 					text.edit(tmp);
 				}
 				/* 終了条件  */
 				if (cmd.cmd==REP.SMCMD_QUIT){
-					System.out.println("\tEditor"+eid+" catch QUIT command emited by itself.");
+					//System.out.println("\tEditor"+eid+" catch QUIT command emited by itself.");
 					running=false; break;
 				}
+			} else if (cmd.eid==-1){
+				/* 制御プロセスからの指令  */
+				System.out.println("\tEditor"+eid+" send command.");
+				sendOneCommand(cmd);
 			} else {
 				cmds = translater.transReceiveCmd(cmd);
 				for (int i=0; i<cmds.length; i++){
 					cmd = cmds[i];
-					System.out.println("\t\tEditor"+eid+" edit text and pass Cmd. ");
+					//System.out.println("\t\tEditor"+eid+" edit text and pass Cmd. ");
 					text.edit(cmd);
 					cs.write(new REPCommand(cmd));
 				}
@@ -73,18 +77,21 @@
 		System.out.println("Editor"+eid+" finish.");
 	}
 
-	private void sendOneCommand() {
+	private void sendOneCommand(REPCommand cmd) {
 		REPCommand[] cmds;
-		REPCommand cmd = CmdList.poll();
+		if (cmd==null) cmd = CmdList.poll();
+		if (cmd==null) return;
+
 		cmd.eid = eid;
 		cmds = translater.transSendCmd(cmd);
-		cmd.setString("this is inserted or replaced by Editor"+cmd.eid+":"+cmd.seq);
+		cmd.setString("inserted by Editor"+cmd.eid+":"+cmd.seq);
 
-		if (isOwner) cmd.setThroughMaster(true);
+		//if (isOwner) cmd.setThroughMaster(true);
 		for (int i=0; i<cmds.length; i++){
 			text.edit(cmds[i]);
 			cs.write(new REPCommand(cmds[i]));
 		}
+		Thread.yield();
 	}
 	private void sendAllCommand() {
 		REPCommand[] cmds;