# HG changeset patch # User kono # Date 1223731425 -32400 # Node ID 6ceb222570cb1f46095c09133d406f06ce54d9e1 # Parent 7b6dede07f4afd2bccd2052c5fccdad0ad6acc75 merge is working now. diff -r 7b6dede07f4a -r 6ceb222570cb rep/Editor.java --- a/rep/Editor.java Sat Oct 11 19:31:13 2008 +0900 +++ b/rep/Editor.java Sat Oct 11 22:23:45 2008 +0900 @@ -33,15 +33,15 @@ this.channel = channel; } - public void translate(Editor nextEditor, REPCommand command){ - if(command.eid == nextEditor.getEID()){ - nextEditor.checkReturnedCommand(command); + public void translate(REPCommand command){ + if(command.eid == next.getEID()){ + ((Editor) next).checkReturnedCommand(command); } else if(command.eid == eid){ //エディタからの新たな編集コマンド translator.transSendCmd(command); sentList.add(new REPCommand(command)); assert(sentList.size() getChannel() { diff -r 7b6dede07f4a -r 6ceb222570cb rep/SessionManager.java --- a/rep/SessionManager.java Sat Oct 11 19:31:13 2008 +0900 +++ b/rep/SessionManager.java Sat Oct 11 22:23:45 2008 +0900 @@ -115,9 +115,9 @@ public void mainLoop() throws IOException { while(true){ + checkWaitingCommandInMerge(); if (checkInputEvent() || - checkWaitingWrite() || - checkWaitingCommandInMerge()) { + checkWaitingWrite()) { // try to do fair execution for waiting task if(selector.selectNow() > 0) select(); continue; @@ -151,15 +151,22 @@ * @return true if there is a processed waiting command * @throws IOException */ - private boolean checkWaitingCommandInMerge() throws IOException { - for(Iterator it = waitingCommandInMerge.iterator(); it.hasNext();){ - PacketSet p = it.next(); - if(p.getEditor().isMerging()) { // still merging do nothing - continue; - }else{ - // process one command and return true - manage(p.channel, p.command); - it.remove(); + private void checkWaitingCommandInMerge() throws IOException { + List w = waitingCommandInMerge; + waitingCommandInMerge = new LinkedList(); + for(PacketSet p: w) { + Editor e = p.getEditor(); + if(e!=null &&e.isMerging()) { // still merging do nothing + waitingCommandInMerge.add(p); + } else { + manage(p.channel, p.command); + } + } + } + + public boolean hasWaitingCommand(REPSocketChannelc) { + for(PacketSet p:waitingCommandInMerge) { + if (p.channel==c) { return true; } } @@ -205,6 +212,12 @@ Session s = getSession(receivedCommand.sid); Editor e = s.getEditor(channel); // if(e==null) throw new IOException(); + if (receivedCommand.eid!=REP.MERGE_EID.id && receivedCommand.eid!=e.eid ) { + if (hasWaitingCommand(channel)) { + addWaitingCommand(new PacketSet(channel, e, receivedCommand)); + return; + } + } e.manage(receivedCommand); } diff -r 7b6dede07f4a -r 6ceb222570cb test/sematest/TestEditor.java --- a/test/sematest/TestEditor.java Sat Oct 11 19:31:13 2008 +0900 +++ b/test/sematest/TestEditor.java Sat Oct 11 22:23:45 2008 +0900 @@ -246,11 +246,13 @@ case SMCMD_JOIN_ACK : sid = cmd.sid; eid = cmd.eid; + name += "(eid="+eid+",sid="+sid+")"; inputLock = false; break; case SMCMD_PUT_ACK : sid = cmd.sid; eid = cmd.eid; + name += "(eid="+eid+",sid="+sid+")"; inputLock = false; break; case SMCMD_QUIT :