Mercurial > hg > RemoteEditor > REPSessionManager
changeset 397:149c9a53fc37
half done ACK protocol
author | one |
---|---|
date | Sun, 23 Nov 2008 16:35:20 +0900 |
parents | dc616339b00a |
children | 7de83b6a34e7 |
files | Todo rep/handler/Editor.java rep/handler/Translator.java |
diffstat | 3 files changed, 92 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/Todo Wed Nov 19 17:07:04 2008 +0900 +++ b/Todo Sun Nov 23 16:35:20 2008 +0900 @@ -1,3 +1,9 @@ +Wed Nov 19 19:21:47 JST 2008 + +ACK base に書き換えるのは良いが、途中でjoinして +きたeditorが、ACKだけを受け取った時には無視する必要が +ある。 + Fri Oct 31 20:34:35 JST 2008 Note:
--- a/rep/handler/Editor.java Wed Nov 19 17:07:04 2008 +0900 +++ b/rep/handler/Editor.java Sun Nov 23 16:35:20 2008 +0900 @@ -39,14 +39,22 @@ } - public void translate(REPCommand command){ + public void translate(REPCommand command){ + switch(command.cmd) { + case REPCMD_INSERT_ACK: + case REPCMD_DELETE_ACK: + if (command.eid==eid) { + // Second Phase が終わって同期が終了。 + return; + } + checkReturnedCommand(command); + return; + } if (command.eid == eid){ //エディタからの新たな編集コマンド if (next==this) return; // singleton case translator.transSendCmd(command); - sentList.add(new REPCommand(command)); - assert(sentList.size()<limit); - next.send(command); + sendEditorCommand(command); return; } else if (command.eid == REP.MERGE_EID.id){ //マージコマンドが返ってきた @@ -57,11 +65,27 @@ checkEndMerge(); } else if (command.eid == next.getEID()){ // 次のEditorで一周するコマンドが来た + // この方法、あんまり良くない... if (next==this) return; // singleton case // これは、distributed case では、うまくいかないので、送り先のforwarder で処理する。 - if (next.isDirect()) + if (next.isDirect()) { + REPCommand keep; + switch (command.cmd) { + case REPCMD_INSERT: + keep = new REPCommand(command); + keep.cmd = REP.REPCMD_INSERT_ACK; + sentList.add(keep); + ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList); + break; + case REPCMD_DELETE: + keep = new REPCommand(command); + keep.cmd = REP.REPCMD_DELETE_ACK; + sentList.add(keep); + ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList); + break; + } ((Editor) next).checkReturnedCommand(command); - else + } else next.send(command); } else { //他のエディタからの編集コマンド @@ -71,19 +95,33 @@ } else if (isMerging()) { manager.addWaitingCommand(new PacketSet(getChannel(), this, new REPCommand(command))); } else { - switch(command.cmd) { - case REPCMD_INSERT_ACK: - case REPCMD_DELETE_ACK: - startMerge(command); - break; - default: - translator.transReceiveCmd(next,command); + translator.transReceiveCmd(next,command); + if(command.cmd==REP.REPCMD_DELETE) { + // delete のundo用の文字列は、外に出す意味はない + command.string=null; } + sendEditorCommand(command); } } return; } + private void sendEditorCommand(REPCommand command) { + REPCommand keep = new REPCommand(command); + switch(command.cmd) { + case REPCMD_INSERT: + keep.cmd = REP.REPCMD_INSERT_ACK; + break; + case REPCMD_DELETE: + keep.cmd = REP.REPCMD_DELETE_ACK; + break; + } + sentList.add(keep); + ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList); + assert(sentList.size()<limit); + next.send(command); + } + boolean merge(REPCommand command) { //マージして送信 return translator.catchOwnCommand(this); @@ -101,24 +139,13 @@ ServerMainLoop.logger.writeLog(err); assert(false); } - switch (command.cmd) { - case REPCMD_INSERT_ACK: - case REPCMD_DELETE_ACK: - // Second Phase が終わって同期が終了。 - return; - case REPCMD_INSERT: - command.cmd = REP.REPCMD_INSERT_ACK; - break; - case REPCMD_DELETE: - command.cmd = REP.REPCMD_DELETE_ACK; - break; - } startMerge(command); return; } private void startMerge(REPCommand command) { - preMergeCommand = command; + preMergeCommand = new REPCommand(command); + preMergeCommand.string = ""; // merge は必須だが、EditorのCommand実装をテストするには邪魔なので、off に出来るようにする。 if (noMergeMode) { endMerge(); @@ -172,9 +199,25 @@ private void endMerge() { REPCommand mergeEnd = new REPCommand(REP.SMCMD_END_MERGE,sid,eid,seq(),0,""); send(mergeEnd); - // send INSERT_ACK/DELETE_ACK as next editor's merge trigger - sentList.add(new REPCommand(preMergeCommand)); - next.send(preMergeCommand); + if (preMergeCommand.eid==eid) { + // First Phase End, send ACK + REPCommand keep = new REPCommand(preMergeCommand); + switch(keep.cmd) { + case REPCMD_INSERT: + keep.cmd = REP.REPCMD_INSERT_ACK; + break; + case REPCMD_DELETE: + keep.cmd = REP.REPCMD_DELETE_ACK; + break; + } + sentList.add(keep); + ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList); + assert(sentList.size()<limit); + next.send(keep); + } else { + next.send(preMergeCommand); + } + preMergeCommand = null; } private boolean checkQuit() { @@ -295,10 +338,22 @@ } else if (command.eid==eid) { // if we handle in editor.manage(), this editor cannot distinguish this // and user input command from the editor. + REPCommand keep; switch(command.cmd) { + case REPCMD_DELETE_ACK: + case REPCMD_INSERT_ACK: + checkReturnedCommand(command); + return ; + case REPCMD_INSERT: + keep = new REPCommand(command); + keep.cmd = REP.REPCMD_INSERT_ACK; + sentList.add(keep); + checkReturnedCommand(command); + return; case REPCMD_DELETE: - case REPCMD_INSERT: - case REPCMD_NOP: + keep = new REPCommand(command); + keep.cmd = REP.REPCMD_DELETE_ACK; + sentList.add(keep); checkReturnedCommand(command); return; }
--- a/rep/handler/Translator.java Wed Nov 19 17:07:04 2008 +0900 +++ b/rep/handler/Translator.java Sun Nov 23 16:35:20 2008 +0900 @@ -156,14 +156,7 @@ */ public void transReceiveCmd(REPNode nextEditor,REPCommand cmd){ assert (cmd.eid != eid); - // nop command の挿入は Editor 側で行って、こちら側ではやらない unMergedCmds.add(cmd); - if(cmd.cmd==REP.REPCMD_DELETE) { - // delete のundo用の文字列は、外に出す意味はない - cmd = new REPCommand(cmd); - cmd.string=null; - } - nextEditor.send(cmd); } public void setEid(int _eid){