# HG changeset patch # User one # Date 1227535911 -32400 # Node ID 19705f4b80155b920d19ea1c3825a2d28f1a1490 # Parent 7de83b6a34e71f21e1af2804b852750bcb9f31a9 waitingCommandInMerge diff -r 7de83b6a34e7 -r 19705f4b8015 Todo --- a/Todo Sun Nov 23 18:38:52 2008 +0900 +++ b/Todo Mon Nov 24 23:11:51 2008 +0900 @@ -1,3 +1,8 @@ +Mon Nov 24 22:51:45 JST 2008 + +watingCommandInMerge のqueueを一旦0にしてから、manageを +呼ぶと、queueが既にあるのに、lockが外れた状態になってしまう。 + Wed Nov 19 19:21:47 JST 2008 ACK base に書き換えるのは良いが、途中でjoinして diff -r 7de83b6a34e7 -r 19705f4b8015 rep/ServerMainLoop.java --- a/rep/ServerMainLoop.java Sun Nov 23 18:38:52 2008 +0900 +++ b/rep/ServerMainLoop.java Mon Nov 24 23:11:51 2008 +0900 @@ -6,7 +6,6 @@ import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectionKey; import java.util.LinkedList; -import java.util.List; import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -28,7 +27,6 @@ public SessionManager manager; protected SessionManagerGUI gui; protected REPSelector selector; - protected List waitingCommandInMerge= new LinkedList(); private BlockingQueue waitingEventQueue = new LinkedBlockingQueue(); public String myHost; @@ -54,7 +52,7 @@ public void mainLoop() throws IOException { while(true){ - checkWaitingCommandInMerge(); + manager.checkWaitingCommandInMerge(); if (checkInputEvent() || checkWaitingWrite()) { // try to do fair execution for waiting task @@ -103,44 +101,8 @@ return false; } - /** - * Check waiting command in merge - * @return true if there is a processed waiting command - * @throws IOException - */ - public void checkWaitingCommandInMerge() { - List w = waitingCommandInMerge; - waitingCommandInMerge = new LinkedList(); - for(PacketSet p: w) { - REPNode e = p.getEditor(); - if(e.isMerging()) { // still merging do nothing - waitingCommandInMerge.add(p); - } else { - try { -// if (manager.sessionManage(e, p.command)) { // we don't need this -// assert false; -// return; -// } - e.manage(p.command); - } catch (Exception e1) { - // should be e.close()? - close(p.channel); - } - } - } - } - - public boolean hasWaitingCommand(REPSocketChannelc) { - for(PacketSet p:waitingCommandInMerge) { - if (p.channel==c) { - return true; - } - } - return false; - } - - private void close(REPSocketChannel channel) { + public void close(REPSocketChannel channel) { REPSelectionKeykey = channel.keyFor1(selector); REPNode handler = (REPNode)key.attachment(); key.cancel(); @@ -223,9 +185,6 @@ } } - public void addWaitingCommand(PacketSet set) { - waitingCommandInMerge.add(set); - } public void buttonPressed(SessionManagerEvent event) { try { diff -r 7de83b6a34e7 -r 19705f4b8015 rep/SessionManager.java --- a/rep/SessionManager.java Sun Nov 23 18:38:52 2008 +0900 +++ b/rep/SessionManager.java Mon Nov 24 23:11:51 2008 +0900 @@ -607,4 +607,11 @@ return smList.sessionManagerID(); } + public void checkWaitingCommandInMerge() { + for(REPNode e:editorList.values()) { + e.checkWaitingCommandInMerge(); + } + + } + } diff -r 7de83b6a34e7 -r 19705f4b8015 rep/handler/Editor.java --- a/rep/handler/Editor.java Sun Nov 23 18:38:52 2008 +0900 +++ b/rep/handler/Editor.java Mon Nov 24 23:11:51 2008 +0900 @@ -18,6 +18,7 @@ private Translator translator; // REPCommands we are going to send to the next editor private List sentList = new LinkedList(); + protected List waitingCommandInMerge= new LinkedList(); private REPCommand quit2=null; private boolean merging; private REPCommand preMergeCommand; @@ -74,8 +75,9 @@ if (waitingRequired(command)) return; keep = new REPCommand(command); sentList.add(keep); - ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList); - ((Editor) next).checkReturnedCommand(command); + checkDouble(sentList); + next.forwardedCommandManage(command); + // ((Editor) next).checkReturnedCommand(command); } else next.send(command); } else { @@ -91,23 +93,40 @@ return; } + private void checkDouble(List sentList) { + if (sentList.size()==0) return; + int count = 0; + REPCommand f = sentList.get(0); + for(REPCommand c:sentList) { + if (c.eid==f.eid&&c.seq==f.seq) { + count++; + } + } + assert(count==1); + } + private boolean waitingRequired(REPCommand command) { - if (manager.hasWaitingCommand(channel)) { + if (hasWaitingCommand()) { // We cannot do this operation before watingCommandQueue. - manager.addWaitingCommand(new PacketSet(channel, this, command)); + addWaitingCommand(new PacketSet(channel, this, command)); return true; } else if (isMerging()) { - manager.addWaitingCommand(new PacketSet(getChannel(), this, new REPCommand(command))); + addWaitingCommand(new PacketSet(getChannel(), this, new REPCommand(command))); return true; } ServerMainLoop.logger.writeLog("Editor eid:"+eid+" no waiting"); return false; } + public void addWaitingCommand(PacketSet set) { + waitingCommandInMerge.add(set); + } + private void sendEditorCommand(REPCommand command) { REPCommand keep = new REPCommand(command); sentList.add(keep); ServerMainLoop.logger.writeLog("Editor eid:"+eid+" sentList = "+sentList); + checkDouble(sentList); assert(sentList.size()