changeset 457:cf61ba25950b

merging flag handling fix
author one
date Fri, 24 Sep 2010 01:12:26 +0900
parents 629211b606e4
children c22f6833d736
files rep/handler/Editor.java
diffstat 1 files changed, 26 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/rep/handler/Editor.java	Thu Sep 23 23:51:39 2010 +0900
+++ b/rep/handler/Editor.java	Fri Sep 24 01:12:26 2010 +0900
@@ -115,7 +115,8 @@
 				}
 				checkEndMerge();
 				return;
-			} else if (command.eid == eid){ 
+			} 
+			if (command.eid == eid){ 
 				// 編集コマンドが一周して来た
 				checkReturnedCommand(command);
 				return;
@@ -229,21 +230,6 @@
 		return;
 	}
 
-	private boolean checkAck(REPCommand command) {
-		assert(!isMerging());
-		REPCommand prev;
-		if (sentList.getFirst()==mergeMark) prev=sentList.remove(1); else prev=sentList.remove(0);		
-		if (prev==null || prev.seq != command.seq || prev.eid!=command.eid) {
-			// should be more robust to allow communication failure
-			String err = "Editor eid="+eid+" checkReturnedCommand() : command = " + command + " prev="+
-				(prev==null?"null":prev)+" sentList=";
-			err += sentList;
-			ServerMainLoop.logger.writeLog(err);
-			assert(false);
-		}
-		return true;
-	}
-
 	private void startMerge(REPCommand command) {
 		ServerMainLoop.logger.writeLog("Editor"+eid+": startMerge "+command);
 		preMergeCommand = new REPCommand(command);
@@ -263,6 +249,22 @@
 		// ACKが来てから始まる。
 		translator.startMerge(command);
 	}
+	
+	private boolean checkAck(REPCommand command) {
+		assert(!isMerging());
+		REPCommand prev;
+		if (sentList.getFirst()==mergeMark) prev=sentList.remove(1); else prev=sentList.remove(0);		
+		if (prev==null || prev.seq != command.seq || prev.eid!=command.eid) {
+			// should be more robust to allow communication failure
+			String err = "Editor eid="+eid+" checkReturnedCommand() : command = " + command + " prev="+
+				(prev==null?"null":prev)+" sentList=";
+			err += sentList;
+			ServerMainLoop.logger.writeLog(err);
+			assert(false);
+		}
+		return true;
+	}
+
 
 	@Override
 	public void setQuit2(REPCommand cmd) {
@@ -324,7 +326,7 @@
 	}
 
 	private boolean checkQuit() {
-		if (quit2!=null && sentList.size()==1&&!isMerging()) {
+		if (quit2!=null && sentList.size()==1&&!isMerging() && !hasWaitingCommand()) {
 			sendToEditor(quit2);
 			quit2 = null;
 			return true;
@@ -407,7 +409,7 @@
 	 */
 	@Override
 	public void write(REPCommand command) {
-		if (merging) {
+		if (merging || waitingCommandInMerge.size()>0) {
 				addWaitingCommand(new PacketSet(this, new REPCommand(command)));
 				return;
 		}
@@ -485,22 +487,15 @@
 	public void checkWaitingCommandInMerge() {
 		if (translator==null||isMerging()) return;
 		while(waitingCommandInMerge.size()>0) {
-			if (merging || isMerging()) {
-				return;
-			}
+			if (merging||isMerging()) return;
 			PacketSet p = waitingCommandInMerge.remove(0);
 			REPCommand command = p.command;
 			try {
-				if (p.channel!=null) {
-					ServerMainLoop.logger.writeLog("Editor"+eid+": resend after merge comand="+command);
-					toEditor.send(command);
-					if (isMergeCommand(command)) {
-						merging = true;
-						return;
-					}
-				} else {
-					assert(false);
-					manage(command);
+				ServerMainLoop.logger.writeLog("Editor"+eid+": resend after merge comand="+command);
+				toEditor.send(command);
+				if (isMergeCommand(command)) {
+					merging = true;
+					return;
 				}
 			} catch (Exception e1) {
 				assert false;