Mercurial > hg > RemoteEditor > REPSessionManager
changeset 484:7420dea70dd7
Direct Merge first try
author | one |
---|---|
date | Wed, 20 Oct 2010 21:19:24 +0900 |
parents | c792a1ebc0ff |
children | cc262a519b8a |
files | rep/REPCommand.java rep/Session.java rep/handler/Editor.java rep/handler/REPNode.java test/AutoSelectManager.java test/editortest/TestSimpleEditor.java test/mergertest/TestMerger.java |
diffstat | 7 files changed, 51 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/REPCommand.java Sat Oct 16 20:48:38 2010 +0900 +++ b/rep/REPCommand.java Wed Oct 20 21:19:24 2010 +0900 @@ -65,4 +65,8 @@ seq = i; } + public boolean isSameSeq(REPCommand commit) { + return seq==commit.seq && sid==commit.sid && eid==commit.eid; + } + }
--- a/rep/Session.java Sat Oct 16 20:48:38 2010 +0900 +++ b/rep/Session.java Wed Oct 20 21:19:24 2010 +0900 @@ -202,7 +202,7 @@ put(editor.eid,editor); } else { // update editor status - mine.merge(editor); + mine.mergeEditor(editor); } } }
--- a/rep/handler/Editor.java Sat Oct 16 20:48:38 2010 +0900 +++ b/rep/handler/Editor.java Wed Oct 20 21:19:24 2010 +0900 @@ -42,7 +42,7 @@ private boolean merging; static final boolean doOptimize = false; private LinkedList<REPCommand> writeQueue = new LinkedList<REPCommand>(); - static MergeMode mergeMode = MergeMode.Direct; + public static MergeMode mergeMode = MergeMode.Direct; public Editor(SessionManager manager,int editorNo){ // no translator case @@ -128,7 +128,7 @@ checkReturnedCommand(command); checkQuit(); return; - } + } // Second Phase が終わって同期が終了。 // SessionManager.logger.writeLog("Complete "+command); checkAck(command); @@ -212,12 +212,6 @@ // assert(count==0); // } - /** - * truncate sentList and unMergedCmds - */ - private void truncateSentList(REPCommand command) { - - } /** * Sending to Editor and waiting Queue @@ -301,7 +295,9 @@ * @param command */ void checkReturnedCommand(REPCommand command) { - if (mergeMode!=MergeMode.Direct) + if (mergeMode==MergeMode.Direct) { + truncateUnMergedCmds(command); + } else startMerge(command); } @@ -384,7 +380,6 @@ return ; } sortedEditCmds = null; - truncateUnMergedCmds(); checkAck(preMergeCommand); if (preMergeCommand.eid==eid) { if (mergeMode==MergeMode.Early) { @@ -398,16 +393,48 @@ preMergeCommand = null; } - public void truncateUnMergedCmds() { + /** + * User Editor Command Fix the command order of + * other editor commands except own command + * truncate sentList and unMergedCmds. + */ + private void truncateSentList(REPCommand commit) { LinkedList<REPCommand>u = new LinkedList<REPCommand>(); - boolean flag=true; for(REPCommand command:unMergedCmds) { - if (command.cmd==REP.REPCMD_MERGE_MARK) { - flag = false; + if (command.eid!=eid) break; + u.addLast(command); + } + unMergedCmds = u; + LinkedList<REPCommand>s = new LinkedList<REPCommand>(); + for(REPCommand command:sentList) { + if (command.eid!=eid) { + s.clear(); + continue; } - if (flag) u.addLast(command); + s.addLast(command); } + sentList = s; + } + + /** + * Returned command fixed command order. Remove from + * sentList and unMergedCmds + * @param commit + */ + public void truncateUnMergedCmds(REPCommand commit) { + LinkedList<REPCommand>u = new LinkedList<REPCommand>(); + for(REPCommand command:unMergedCmds) { + if (command.isSameSeq(commit)) break; + u.addLast(command); + } unMergedCmds = u; + boolean flag = false; + LinkedList<REPCommand>s = new LinkedList<REPCommand>(); + for(REPCommand command:sentList) { + if (command.isSameSeq(commit)) flag = true; + if (flag) s.addLast(command); + } + if (flag) sentList = s; } private void sendAck(REPCommand command) {
--- a/rep/handler/REPNode.java Sat Oct 16 20:48:38 2010 +0900 +++ b/rep/handler/REPNode.java Wed Oct 20 21:19:24 2010 +0900 @@ -96,7 +96,7 @@ this.channel = channel; } - public void merge(REPNode editor) { + public void mergeEditor(REPNode editor) { if (sid==-1) sid = editor.sid; if (file==null) file = editor.file; if (host==null) host = editor.host;
--- a/test/AutoSelectManager.java Sat Oct 16 20:48:38 2010 +0900 +++ b/test/AutoSelectManager.java Wed Oct 20 21:19:24 2010 +0900 @@ -21,7 +21,7 @@ port = Integer.parseInt(args[0]); port_s = Integer.parseInt(args[1]); } - Editor.noMergeMode = false; + Editor.mergeMode = Editor.MergeMode.Direct; SessionManager sm = new SessionManager(); sm.setReceivePort(port); sm.setParentPort(port_s);
--- a/test/editortest/TestSimpleEditor.java Sat Oct 16 20:48:38 2010 +0900 +++ b/test/editortest/TestSimpleEditor.java Wed Oct 20 21:19:24 2010 +0900 @@ -42,7 +42,7 @@ user.add(editor1); user.add(editor2); user.add(editor3); user.setVisible(true); - Editor.noMergeMode = false; + Editor.mergeMode = Editor.MergeMode.Direct; }
--- a/test/mergertest/TestMerger.java Sat Oct 16 20:48:38 2010 +0900 +++ b/test/mergertest/TestMerger.java Wed Oct 20 21:19:24 2010 +0900 @@ -49,7 +49,7 @@ trans.transReceiveCmd(null, command); } for(int i = 0; i < commandList.size(); i++){ - trans.merge(this,null); + trans.merge(commandList.get(i)); System.out.println(); } }