changeset 401:2cf5392b2a9f

add INSERT_USER, DELETE_USER JOIN_ACK fix
author one
date Tue, 25 Nov 2008 03:07:05 +0900
parents 29f01a7ce71f
children bcb61819cbbc
files rep/ServerMainLoop.java rep/SessionManagerList.java rep/handler/Editor.java rep/handler/Forwarder.java test/sematest/TestEditor.java test/sematest/TestInterManagerSession.java
diffstat 6 files changed, 53 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/rep/ServerMainLoop.java	Tue Nov 25 01:41:11 2008 +0900
+++ b/rep/ServerMainLoop.java	Tue Nov 25 03:07:05 2008 +0900
@@ -93,14 +93,24 @@
 	private boolean checkWaitingWrite() throws IOException {
 		PacketSet p = writeQueue.poll();
 		if (p!=null) {
-			logger.writeLog("writing: "+p.command+" to: "
-					+manager.editorList.editorByChannel(p.channel));
+			sendLog(p);
 			p.channel.write(p.command);
 			return true;
 		}
 		return false;
 	}
 
+	private void sendLog(PacketSet p) {
+		REPNode to;
+		String s;
+		to = manager.editorList.editorByChannel(p.channel);
+		if (to==null)
+			s = p.channel.toString();
+		else
+			s = to.toString();
+		logger.writeLog("writing: "+p.command+" to: " + s);
+	}
+
 
 	public void close(REPSocketChannel<REPCommand> channel) {
 		REPSelectionKey<REPCommand>key = channel.keyFor1(selector);
--- a/rep/SessionManagerList.java	Tue Nov 25 01:41:11 2008 +0900
+++ b/rep/SessionManagerList.java	Tue Nov 25 03:07:05 2008 +0900
@@ -2,6 +2,7 @@
 
 import java.util.LinkedList;
 
+import rep.channel.REPSocketChannel;
 import rep.handler.REPNode;
 import rep.handler.NullForwarder;
 
@@ -78,7 +79,12 @@
 		return parent;
 	}
 
-
-
+	public REPNode managerByChannel(REPSocketChannel<REPCommand> channel) {
+		for(REPNode e:this) {
+			if (e.channel==channel)
+				return e;
+		}
+		return null;
+	}
 
 }
--- a/rep/handler/Editor.java	Tue Nov 25 01:41:11 2008 +0900
+++ b/rep/handler/Editor.java	Tue Nov 25 03:07:05 2008 +0900
@@ -59,42 +59,38 @@
 			command.cmd = REP.REPCMD_INSERT;
 			userEditorCommand(command);
 			return;
-		}
-		if (command.eid == REP.MERGE_EID.id){
-			//マージコマンドが返ってきた
-			checkDouble(sentList);
-			if(translator.checkMergeConflict(command)){
-				//マージ中にエディタからの割り込みがあった場合
-				translator.getMergeAgain(this);
-			}
-			checkEndMerge();
-			checkDouble(sentList);
-			return;
-		} else if (command.eid == next.getEID()){
-			// 次のEditorで一周するコマンドが来た
-			if (next==this) return; // singleton case
-			// これは、distributed case では、うまくいかないので、送り先のforwarder で処理する。
-			if (next.isDirect()&&command.cmd==REP.SMCMD_QUIT_2) {
-				next.forwardedCommandManage(command);
+		case REPCMD_INSERT:
+		case REPCMD_DELETE:
+			if (command.eid == REP.MERGE_EID.id){
+				//マージコマンドが返ってきた
+				checkDouble(sentList);
+				if(translator.checkMergeConflict(command)){
+					//マージ中にエディタからの割り込みがあった場合
+					translator.getMergeAgain(this);
+				}
+				checkEndMerge();
+				checkDouble(sentList);
+				return;
+			} else if (command.eid == eid){ 
+				// 編集コマンドが一周して来た
+				if (waitingRequired(command)) return;
+				checkReturnedCommand(command);
+				checkDouble(sentList);
 				return;
 			}
-		} else if (command.eid == eid){ 
-			// 編集コマンドが一周して来た
+
+			//他のエディタからの編集コマンド
 			if (waitingRequired(command)) return;
-			checkReturnedCommand(command);
-			checkDouble(sentList);
+			translator.transReceiveCmd(next,command);
+			if(command.cmd==REP.REPCMD_DELETE) {
+				// delete のundo用の文字列は、外に出す意味はない
+				command.string=null;
+			}
+			sendEditorCommand(command);
 			return;
+		default:
+			assert(false);
 		}
-
-		//他のエディタからの編集コマンド
-		if (waitingRequired(command)) return;
-		translator.transReceiveCmd(next,command);
-		if(command.cmd==REP.REPCMD_DELETE) {
-			// delete のundo用の文字列は、外に出す意味はない
-			command.string=null;
-		}
-		sendEditorCommand(command);
-		return;
 	}
 
 	private void userEditorCommand(REPCommand command) {
@@ -289,7 +285,6 @@
 		case REPCMD_INSERT_USER:
 		case REPCMD_DELETE_ACK:
 		case REPCMD_INSERT_ACK:
-		case REPCMD_NOP:
 		{
 			translate(command);
 			break;
@@ -349,7 +344,7 @@
 
 	@Override
 	public void handle(REPCommand command, REPSelectionKey<REPCommand> key) throws IOException {
-		ServerMainLoop.logger.writeLog("Manager "+manager.getId()+"read : command = " + command 
+		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;
@@ -386,6 +381,7 @@
 			// this is odd, but the editor itself does not know it's merging
 			// state. Only this session manager knows it.
 			setQuit2(command);
+			return;
 		} 
 		send(command);
 	}
--- a/rep/handler/Forwarder.java	Tue Nov 25 01:41:11 2008 +0900
+++ b/rep/handler/Forwarder.java	Tue Nov 25 03:07:05 2008 +0900
@@ -126,6 +126,7 @@
 	public void joinAck(REPCommand sendCommand, int sid) {
 		manager.sendUpdate(sid);
 		sendCommand.setCMD(REP.SMCMD_JOIN_ACK);
+		send(sendCommand);
 		if (manager.sync) {
 			REPCommand sync = new REPCommand(sendCommand);
 			sync.setCMD(REP.SMCMD_SYNC);
--- a/test/sematest/TestEditor.java	Tue Nov 25 01:41:11 2008 +0900
+++ b/test/sematest/TestEditor.java	Tue Nov 25 03:07:05 2008 +0900
@@ -226,7 +226,7 @@
 
 	private void handle(REPCommand cmd) {
 		if (cmd==null) return;
-		ns.writeLog(name +": read "+cmd);
+		ns.writeLog(name +"(eid="+eid+",sid="+sid+")"+": read "+cmd);
 		switch(cmd.cmd) {
 		case REPCMD_INSERT	:
 			text.insert(cmd.lineno, cmd.string);
--- a/test/sematest/TestInterManagerSession.java	Tue Nov 25 01:41:11 2008 +0900
+++ b/test/sematest/TestInterManagerSession.java	Tue Nov 25 03:07:05 2008 +0900
@@ -119,8 +119,8 @@
 		LinkedList<REPCommand>cmds = new LinkedList<REPCommand>();
 		//cmds.add(new REPCommand(REP.SMCMD_JOIN,0,0,0,0,"Editor0-file"));
 		cmds.add(new REPCommand(REP.SMCMD_PUT,0,0,0,0,"Editor0-file"));
-		cmds.add(new REPCommand(REP.REPCMD_INSERT,0,0,0,0,"m0"));
-		cmds.add(new REPCommand(REP.REPCMD_DELETE,0,0,0,0,"m0"));
+		cmds.add(new REPCommand(REP.REPCMD_INSERT_USER,0,0,0,0,"m0"));
+		cmds.add(new REPCommand(REP.REPCMD_DELETE_USER,0,0,0,0,"m0"));
 		editorStartCmds = cmds;
 		LinkedList<REPCommand>nullcmds = new LinkedList<REPCommand>();
 		editors[0].setCommand(nullcmds);