Mercurial > hg > RemoteEditor > REPSessionManager
changeset 304:75192c844a8d
*** empty log message ***
author | kono |
---|---|
date | Wed, 01 Oct 2008 20:55:40 +0900 (2008-10-01) |
parents | 41f05c8ff02b |
children | ffd8bb47b188 |
files | Todo rep/Editor.java rep/SessionManager.java test/sematest/TestEditor.java |
diffstat | 4 files changed, 34 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/Todo Wed Oct 01 18:32:38 2008 +0900 +++ b/Todo Wed Oct 01 20:55:40 2008 +0900 @@ -7,4 +7,7 @@ Todo: Editor quit, quit2 の実装 quit2 では、自分の送信したコマンドが戻ってくるまで待つ必要がある。 editor 毎の状態となる。 - Done: \ No newline at end of file + Done: + +Todo: Session ring 廻るcommand packetは、基本的に書き換えられるべきではない + eid, seq の組でuniqueになる。現状では、そここで書き換えが起きているらしい。 \ No newline at end of file
--- a/rep/Editor.java Wed Oct 01 18:32:38 2008 +0900 +++ b/rep/Editor.java Wed Oct 01 20:55:40 2008 +0900 @@ -4,6 +4,7 @@ import java.util.LinkedList; import java.util.List; +import rep.channel.REPLogger; import rep.channel.REPSocketChannel; import rep.optimizers.*; import rep.translater.TranslaterImp1; @@ -20,6 +21,7 @@ private REPCommandOptimizer optimizer; private List<REPCommand> writeQueue; private REPCommand quit2 = null; + private REPLogger ns = REPLogger.singleton(); public Editor(){ this(true); @@ -121,10 +123,11 @@ REPCommand cmd; if (writeQueue.size()>0) { cmd = writeQueue.remove(0); + ns.writeLog("SessionManager write to "+myChannel+" cmd="+cmd); myChannel.write(cmd); return true; } else if (quit2!=null && sentList.size()==0) { - myChannel.write(quit2); + //myChannel.write(quit2); quit2 = null; return true; } @@ -163,7 +166,7 @@ translater.setEid(eid); } public String toString(){ - return (host + ":" + file); + return ("Editor eid="+eid+" sid="+sid+" " + host + ":" + file); } public String getName() { @@ -175,7 +178,7 @@ } public void send(REPCommand command) { - myChannel.write(command); + writeQueue.add(command); } public void setChannel(REPSocketChannel<REPCommand> channel) {
--- a/rep/SessionManager.java Wed Oct 01 18:32:38 2008 +0900 +++ b/rep/SessionManager.java Wed Oct 01 20:55:40 2008 +0900 @@ -48,6 +48,7 @@ private SessionManagerList smList; private String myHost; private List<Editor> editorList; + // editorList は、sessionList に入っているeditorとは別なeditorのlistらしい。 private String maxHost; private List<PacketSet> waitingCommandInMerge; private BlockingQueue<SessionManagerEvent> waitingQueue = new LinkedBlockingQueue<SessionManagerEvent>();; @@ -95,8 +96,9 @@ while((e = waitingQueue.poll())!=null){ e.exec(); } - for(Editor editor:editorList) { - if (editor.doWaitingWrite()) break; + for(Session s:sessionList) { + for(Editor editor: s.getEditorList()) + if (editor.doWaitingWrite()) break; } if(checkSend()){ if(selector.selectNow() > 0){ @@ -383,18 +385,20 @@ Session session = getSession(receivedCommand.sid); if (session==null) throw new IOException(); //マージの処理と次のエディタへコマンドを送信する処理 + Editor editor = session.getEditor(channel); + boolean old = editor.isMerging(); session.translate(channel, receivedCommand); - - - Editor editor = session.getEditor(channel); - Editor prevEditor = session.getPrevEditor(editor); - - //マージ中のエディタはコマンドを受け取らない - if(editor.isMerging()){ - //Handlerを切り替える - setMergeState(prevEditor.getChannel(), session.getSID()); - }else { - setNormalState(prevEditor.getChannel(), session.getSID()); + boolean newState = editor.isMerging(); + if (old!=newState) { + Editor prevEditor = session.getPrevEditor(editor); + //マージ中のエディタはコマンドを受け取らない + // この代入は状態が変わったときだけ行えば良い。毎回、new するのは変 + if(editor.isMerging()){ + //Handlerを切り替える + setMergeState(prevEditor.getChannel(), session.getSID()); + }else { + setNormalState(prevEditor.getChannel(), session.getSID()); + } } } break; @@ -565,7 +569,7 @@ session.addEditor(editor); - System.out.println(session.hasOwner()); + System.out.println("SessionManager.session.hasOnwer="+session.hasOwner()); if(session.hasOwner()){ REPCommand sendCommand = new REPCommand(); sendCommand.setCMD(REP.SMCMD_JOIN_ACK);
--- a/test/sematest/TestEditor.java Wed Oct 01 18:32:38 2008 +0900 +++ b/test/sematest/TestEditor.java Wed Oct 01 20:55:40 2008 +0900 @@ -56,13 +56,13 @@ text = new Text(txts); cmds.add(new REPCommand(REP.SMCMD_PUT,0,0,0,0,name+"-file")); cmds.add(new REPCommand(REP.REPCMD_INSERT,0,0,0,0,"m0")); - cmds.add(new REPCommand(REP.REPCMD_DELETE,0,0,0,0,"m0")); - cmds.add(new REPCommand(REP.SMCMD_QUIT,0,0,0,0,"")); + //cmds.add(new REPCommand(REP.REPCMD_DELETE,0,0,0,0,"m0")); + //cmds.add(new REPCommand(REP.SMCMD_QUIT,0,0,0,0,"")); } else { text = new Text(new String[0]); cmds.add(new REPCommand(REP.SMCMD_JOIN,0,0,0,0,name)); - cmds.add(new REPCommand(REP.REPCMD_INSERT,0,0,0,0,"c0")); - cmds.add(new REPCommand(REP.REPCMD_DELETE,0,0,0,0,"c0")); + //cmds.add(new REPCommand(REP.REPCMD_INSERT,0,0,0,0,"c0")); + //cmds.add(new REPCommand(REP.REPCMD_DELETE,0,0,0,0,"c0")); } } @@ -237,11 +237,13 @@ inputLock = false; break; case SMCMD_QUIT : + if (false) { if (cmd.eid!=eid) sendCommand(cmd,cmd.seq); else sendCommand(new REPCommand(REP.SMCMD_QUIT_2, sid, eid, seq, 0, ""),seq++); + } cmds.clear(); break; case SMCMD_QUIT_ACK :