diff rep/handler/Editor.java @ 442:3819dec4641e

command waiting during merge
author one
date Sun, 12 Sep 2010 22:23:53 +0900
parents 5cbe1731f40c
children bd086be276d2
line wrap: on
line diff
--- a/rep/handler/Editor.java	Sun Sep 12 15:11:46 2010 +0900
+++ b/rep/handler/Editor.java	Sun Sep 12 22:23:53 2010 +0900
@@ -20,8 +20,8 @@
 	private LinkedList<REPCommand> sentList = new LinkedList<REPCommand>();
 	protected LinkedList<PacketSet> waitingCommandInMerge= new LinkedList<PacketSet>();
 	private REPCommand quit2=null;
+	private REPCommand preMergeCommand;
 	private boolean merging;
-	private REPCommand preMergeCommand;
 	public static boolean noMergeMode=false;
 	static final boolean doOptimize = true;
 
@@ -82,11 +82,11 @@
 		switch(command.cmd) {
 		case REPCMD_INSERT_ACK:
 		case REPCMD_DELETE_ACK:
-			if (waitingRequired(command)) return;
+			// if (waitingRequired(command)) return;
 			if (command.eid==eid) {
 				// Second Phase が終わって同期が終了。
 				checkAck(command);
-				SessionManager.logger.writeLog("Complete "+command);
+				// SessionManager.logger.writeLog("Complete "+command);
 				checkQuit();
 				return;
 			}
@@ -112,13 +112,13 @@
 				return;
 			} else if (command.eid == eid){ 
 				// 編集コマンドが一周して来た
-				if (waitingRequired(command)) return;
+				// if (waitingRequired(command)) return;
 				checkReturnedCommand(command);
 				return;
 			}
 
 			//他のエディタからの編集コマンド
-			if (waitingRequired(command)) return;
+			// if (waitingRequired(command)) return;
 			translator.transReceiveCmd(next,command);
 
 			sendEditorCommand(command);
@@ -171,13 +171,13 @@
 		return false;
 	}
 
-	public void addWaitingCommand(PacketSet set) {
-		if (preMergeCommand!=null) {
-			if (preMergeCommand.eid==set.command.eid
-					&& preMergeCommand.seq==set.command.seq) {
-				assert(false);
-			}
-		}
+    public void addWaitingCommand(PacketSet set) {
+//		if (preMergeCommand!=null) {
+//			if (preMergeCommand.eid==set.command.eid
+//					&& preMergeCommand.seq==set.command.seq) {
+//				assert(false);
+//			}
+//		}
 		waitingCommandInMerge.add(set);
 	}
 
@@ -228,23 +228,13 @@
 
 	private boolean checkAck(REPCommand command) {
 		assert(!merging);
-//		if (sentList.size()==0) {
-//			ServerMainLoop.logger.writeLog("Editor eid="+eid+" looped command not registered: "+command);
-//			assert(command.cmd==REP.REPCMD_DELETE_ACK||
-//					command.cmd==REP.REPCMD_INSERT_ACK);
-//			return false;
-//		}
 		REPCommand prev = sentList.pollFirst();
-//		// ServerMainLoop.logger.writeLog("Editor eid="+eid+" remove sentList:"+(prev==null?"null":prev));
 		if (prev==null || prev.seq != command.seq || prev.eid!=command.eid) {
 			String err = "Editor eid="+eid+" checkReturnedCommand() : command = " + command + " prev="+
 				(prev==null?"null":prev)+" sentList=";
 			err += sentList;
 			ServerMainLoop.logger.writeLog(err);
 			assert(false);
-//			assert(command.cmd==REP.REPCMD_DELETE_ACK||
-//					command.cmd==REP.REPCMD_INSERT_ACK);
-//			return false;
 		}
 		return true;
 	}
@@ -292,7 +282,6 @@
 		return translator.isMerging();
 	}
 
-	
 
 	void checkEndMerge() {
 		if (merging) {
@@ -303,6 +292,7 @@
 		if (quit2!=null) checkQuit();
 	}
 
+
 	private void endMerge() {
 		REPCommand mergeEnd = new REPCommand(REP.SMCMD_END_MERGE,sid,eid,seq(),0,"");
 		send(mergeEnd);
@@ -405,9 +395,18 @@
 	
 
 	@Override
+	public void send(REPCommand command) {
+		if (command.eid == REP.MERGE_EID.id || 
+				command.cmd==REP.SMCMD_END_MERGE ||
+				!waitingRequired(command)) {
+			super.send(command);
+		}
+	}
+	
+	@Override
 	public void handle(REPCommand command, REPSelectionKey<REPCommand> key) throws IOException {
-		ServerMainLoop.logger.writeLog("Manager "+manager.getId()+" read : command = " + command 
-				+" from "+manager.editorList.editorByChannel(channel));
+		//ServerMainLoop.logger.writeLog("Manager "+manager.getId()+" read : command = " + command 
+				// +" from "+manager.editorList.editorByChannel(channel));
 		if (command.cmd==REP.SMCMD_JOIN||command.cmd==REP.SMCMD_PUT) {
 			// assert false;
 			// 一つのエディタ上に複数のセッションが作られた場合。