# HG changeset patch # User kono # Date 1223714631 -32400 # Node ID be0831086e634bd5541d9dbde0f8ce78071f6f80 # Parent e235998427a6f3ad6bae1962239064ad11889345 *** empty log message *** diff -r e235998427a6 -r be0831086e63 rep/Editor.java --- a/rep/Editor.java Sat Oct 11 16:31:03 2008 +0900 +++ b/rep/Editor.java Sat Oct 11 17:43:51 2008 +0900 @@ -5,11 +5,12 @@ import rep.channel.REPSocketChannel; import rep.handler.PacketSet; import rep.optimizers.*; +import rep.translator.Translator; import rep.translator.TranslatorImpl; public class Editor extends Forwarder { - private TranslatorImpl translator; + private Translator translator; private List sentList = new LinkedList(); // REPCommands we are going to send to the next editor private REPCommandOptimizer optimizer; @@ -35,24 +36,14 @@ public void translate(Editor nextEditor, REPCommand command){ if(command.eid == nextEditor.getEID()){ - if(nextEditor.checkReturnedCommand(command)){ - // エディタからのコマンドが元のエディタに戻ってきた - // START_MERGE を送る - REPCommand cmd = new REPCommand(REP.SMCMD_START_MERGE,command.sid,REP.SM_EID.id,seq(),0,""); - nextEditor.send(cmd); - // Session Manager 側で、このeditorへの他のeditorからの - // 入力を止めて、merge にそなえる。merge は、eidtor 側から - // ACKが来てから始まる。 - translator.startMerge(cmd); - return; - } else assert(false); + nextEditor.checkReturnedCommand(command); } else if(command.eid == eid){ - //エディタからの新たな編集コマンド - sentList.add(command); - assert(sentList.size() 0){ if(sentList.get(0).seq == command.seq){ sentList.remove(0); @@ -90,13 +81,19 @@ send(quit2); manager.remove(this); } - return true; }else{ System.out.println("Editor.checkReturnedCommand() : command = " + command); assert(false); } } - return false; + // START_MERGE を送る + REPCommand cmd = new REPCommand(REP.SMCMD_START_MERGE,command.sid,REP.SM_EID.id,seq(),0,""); + send(cmd); + // Session Manager 側で、このeditorへの他のeditorからの + // 入力を止めて、merge にそなえる。merge は、eidtor 側から + // ACKが来てから始まる。 + translator.startMerge(cmd); + return; } @Override diff -r e235998427a6 -r be0831086e63 rep/translator/Translator.java --- a/rep/translator/Translator.java Sat Oct 11 16:31:03 2008 +0900 +++ b/rep/translator/Translator.java Sat Oct 11 17:43:51 2008 +0900 @@ -1,35 +1,55 @@ package rep.translator; +import java.util.LinkedList; + import rep.Editor; import rep.Forwarder; import rep.REPCommand; public interface Translator { + /* + * Interface で分離する意味が良くわからない。Application毎に + * Transltorを換えるつもりなのか? + */ /** * Translate command When the editor send REPCommand to remote editor. * @param command which the editor want to send. * @return translated command which should be sent by the editor. */ - abstract public REPCommand transSendCmd(REPCommand cmd); + public REPCommand transSendCmd(REPCommand cmd); /** * Inform translater about that the editor receive own command which it sent. * but in this case, you can use also transReceiveCmd() * @param command which the editor sent. */ - abstract public boolean catchOwnCommand(Editor editor); + public boolean catchOwnCommand(Editor editor); /** * Translate Command cmd that was received from SeMa. * @param cmd the command to be translated. * @return translated command. */ - abstract public void transReceiveCmd(Forwarder nextEditor,REPCommand cmd); + public void transReceiveCmd(Forwarder nextEditor,REPCommand cmd); /** * set the editor's id. * @param editor's id. */ - abstract public void setEid(int _eid); + public void setEid(int _eid); + + boolean checkMergeConflict(REPCommand command); + + public LinkedList getMergeAgain(); + + public void startMerge(REPCommand cmd); + + public REPCommand prev(); + + public boolean isMerging(); + + public void endMerge(); + + public void mergeAck(); } diff -r e235998427a6 -r be0831086e63 rep/translator/TranslatorImpl.java --- a/rep/translator/TranslatorImpl.java Sat Oct 11 16:31:03 2008 +0900 +++ b/rep/translator/TranslatorImpl.java Sat Oct 11 17:43:51 2008 +0900 @@ -50,8 +50,9 @@ return cmd; } /** - * My command is returned from the session ring. At this - * stage writeQueue is empty, our editor is waiting for me. + * My command is returned from the session ring, and START_MERGE_ACK + * is returned. At this + * stage my writeQueue is empty, our editor is waiting for me. * Start merge process. * @param cmd */ @@ -154,17 +155,14 @@ } public Stack getList() { - // TODO Auto-generated method stub return unMergedCmds; } public LinkedList getSentCmds() { - // TODO Auto-generated method stub return sentCmds; } public void setUndoCommand(REPCommand command) { - // TODO Auto-generated method stub undoReplaceList.add(command); } @@ -223,7 +221,8 @@ } public void endMerge() { - merge_mode = false; + if(isFinished()) + merge_mode = false; }