changeset 124:f18510fc40e2

refactor
author kent
date Tue, 25 Dec 2007 16:21:30 +0900
parents 286a8a1b33cd
children 34b15dfcb83e
files src/pathfinder/mergetest/EditorSimulator.java src/pathfinder/mergetest/TestMerger.java
diffstat 2 files changed, 21 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/pathfinder/mergetest/EditorSimulator.java	Sun Dec 23 18:17:31 2007 +0900
+++ b/src/pathfinder/mergetest/EditorSimulator.java	Tue Dec 25 16:21:30 2007 +0900
@@ -45,20 +45,19 @@
 			REPCommand cmd = cs.read();
 			REPCommand[] cmds;
 
-			//終了条件
-			if (cmd.eid==eid && cmd.cmd==REP.SMCMD_QUIT){
-				System.out.println("\tEditor"+eid+" catch QUIT command emited by itself.");
-				translater.transReceiveCmd(cmd);
-				running=false; break;
-			}
 			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++){
-					cmd = cmds[i];
+					REPCommand tmp = cmds[i];
 					System.out.println("\t\tEditor"+eid+" edit text. ");
-					text.edit(cmd);
+					text.edit(tmp);
+				}
+				/* 終了条件  */
+				if (cmd.cmd==REP.SMCMD_QUIT){
+					System.out.println("\tEditor"+eid+" catch QUIT command emited by itself.");
+					running=false; break;
 				}
 			} else {
 				cmds = translater.transReceiveCmd(cmd);
--- a/src/pathfinder/mergetest/TestMerger.java	Sun Dec 23 18:17:31 2007 +0900
+++ b/src/pathfinder/mergetest/TestMerger.java	Tue Dec 25 16:21:30 2007 +0900
@@ -16,12 +16,15 @@
 
 	public static void main(String[] args){
 		TestMerger tm;
+		/* get the number of Editors.  */
 		int i = (args.length>0) ? Integer.parseInt(args[0]) : 2;
 		System.out.println("number of Editor = "+i);
+		/* get the number of Command.  */
 		int j = (args.length>1) ? Integer.parseInt(args[1]) : 3;
-		System.out.println("number of Packet = "+i);
+		System.out.println("number of Packet = "+j);
+
+		/* create, initialize and start test.  */
 		tm = new TestMerger();
-
 		tm.init(false, i, j);
 		tm.startTest();
 
@@ -34,11 +37,14 @@
 	}
 
 	private void startTest() {
+		/* start all Editors.  */
 		for (EditorSimulator ee: editors){
 			ee.start();
 		}
+		/* start SessionManager if it exist.  */
 		if (sema!=null) sema.start();
 
+		/* wait Editors finish.  */
 		for (EditorSimulator ee: editors){
 			try {
 				ee.join();
@@ -46,10 +52,12 @@
 				e.printStackTrace();
 			}
 		}
+		/* inform SessionManager to finish.  */
 		if (sema!=null) sema.finish();
 	}
 
 	private void init(boolean sm, int ne, int np){
+		/* create NetworkSimulator, and SessionManager if it's required.   */
 		if (sm){
 			ns = new NetworkSimulatorwithSeMa<REPCommand>();
 			sema = new SeMaSimulator<REPCommand>(ns, ne);
@@ -58,10 +66,12 @@
 			sema = null;
 		}
 
+		/* create ne Editors and np commands.  */
 		for (int i=0; i<ne; i++){
 			LinkedList<REPCommand> cmds = new LinkedList<REPCommand>();
 			// 各エディタが送信するコマンド列を生成
 
+			/* create command list.  */
 			for (int j=0; j<np; j++){
 				String str = "created by Editor"+i+":"+j;
 				REPCommand cmd = new REPCommand(REP.REPCMD_INSERT,
@@ -71,6 +81,7 @@
 				cmds.add( cmd);
 			}
 
+			/* create a Editor, and pass command list to it.  */
 			EditorSimulator ee = new EditorSimulator(i, ns, cmds, "Editor"+i);
 			if(i==0) ee.setOwner(true);
 			editors.add(ee);