# HG changeset patch # User kono # Date 1224613197 -32400 # Node ID c4ffdac261327d9760c5a40081052f6ce37c6fe4 # Parent 34642bc65c2172995e95fd8f274f8cb1290c2f8f *** empty log message *** diff -r 34642bc65c21 -r c4ffdac26132 rep/Forwarder.java --- a/rep/Forwarder.java Wed Oct 22 02:59:08 2008 +0900 +++ b/rep/Forwarder.java Wed Oct 22 03:19:57 2008 +0900 @@ -79,17 +79,32 @@ SessionManager.logger.writeLog("REPHandlerImpl.handle() : command = " + command); if (manager.sessionManage(this, command)) return; + distpatchToEditor(channel, command); + } + + private void distpatchToEditor(REPSocketChannel channel, + REPCommand command) throws IOException { Session s = manager.getSession(command.sid); if (s==null) throw new IOException(); - Forwarder editor = s.getFirstForwarder(channel); + Forwarder editor = s.getForwarder(channel); if (editor==null) throw new IOException(); if (!editor.isDirect()) { - editor.send(command); + editor.send(command); return; } + /* + * local editor case. Handle special case first, usually these cases + * are handled in the next Editor in a session manager, but + * it is forwarded here. + */ if (command.cmd==REP.SMCMD_QUIT_2) { + // we have to wait next editor's finishing before sending this. + // this is odd, but the editor itself does not know it's merging + // state. Only this session manager knows it. editor.setQuit2(command); } else if (command.eid==editor.eid) { + // if we handle in editor.manage(), this editor cannot distinguish this + // and user input command from the editor. ((Editor)editor).checkReturnedCommand(command); } else { editor.manage(command); diff -r 34642bc65c21 -r c4ffdac26132 rep/Session.java --- a/rep/Session.java Wed Oct 22 02:59:08 2008 +0900 +++ b/rep/Session.java Wed Oct 22 03:19:57 2008 +0900 @@ -15,7 +15,7 @@ private String sessionName; // isOnwer means this session has active channels(forwarders). private boolean isOwner = false; - private Forwarder firstForwarder; + private Forwarder first; private Forwarder last; public Session(int sid, String name, Forwarder editor) { @@ -32,7 +32,7 @@ editor.setSID(sid); put(editor.eid,editor); if(editor.channel!=null) { - firstForwarder = editor; + first = editor; masterEditor.setNext(masterEditor); isOwner = true; } @@ -50,9 +50,9 @@ last = forwarder; put(forwarder.eid,forwarder); isOwner = true; - if(firstForwarder==null) firstForwarder = forwarder; + if(first==null) first = forwarder; - printSessionDetail(); + // printSessionDetail(); } public void addEditor(Editor editor) { @@ -106,7 +106,7 @@ if (f.channel!=null) hasOwner=true; } } - if(firstForwarder==e) firstForwarder=null; + if(first==e) first=null; if(masterEditor==e) masterEditor=null; isOwner = hasOwner; } @@ -132,14 +132,14 @@ public void closeSession() { - Forwarder first = firstForwarder; + Forwarder f = first; REPCommand command = new REPCommand(REP.REPCMD_CLOSE, sessionID, REP.SM_EID.id, 0, 0, ""); - if (first!=null) - first.send(command); + if (f!=null) + f.send(command); } - public Forwarder getFirstForwarder(REPSocketChannel channel) { - Forwarder f = firstForwarder; + public Forwarder getForwarder(REPSocketChannel channel) { + Forwarder f = first; while(f.channel!=channel) f = f.next; SessionManager.logger.writeLog("getFirstForwarder="+f.next+"=>"+f.next.channel); return f.next; @@ -183,17 +183,17 @@ f.setSID(sessionID); put(f.eid,f); f.setNext(f); - firstForwarder = last = f; + first = last = f; } public void printSessionDetail() { - Forwarder f = firstForwarder; + Forwarder f = first; if (f==null) return; String log = "Session Detail "; while (f!=null) { log += ","+f+"="+f.channel+"->"+f.next; f = f.next; - if (f==firstForwarder) { + if (f==first) { log += "*"; break; } diff -r 34642bc65c21 -r c4ffdac26132 rep/SessionManager.java --- a/rep/SessionManager.java Wed Oct 22 02:59:08 2008 +0900 +++ b/rep/SessionManager.java Wed Oct 22 03:19:57 2008 +0900 @@ -680,7 +680,7 @@ { // Sessionが見つかったので、select したeditorに教える。 Session session = sessionList.get(command.sid); - searchSelectedEditor(command,session.getFirstForwarder(forwarder.channel)); + searchSelectedEditor(command,session.getForwarder(forwarder.channel)); } break;