Mercurial > hg > RemoteEditor > REPSessionManager
changeset 458:c22f6833d736
synchronize Editor's waiting queue and Manager's writing queue
author | one |
---|---|
date | Fri, 24 Sep 2010 02:41:13 +0900 |
parents | cf61ba25950b |
children | 66c4f6b29baf |
files | rep/ServerMainLoop.java rep/SessionManager.java rep/handler/Editor.java |
diffstat | 3 files changed, 25 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/ServerMainLoop.java Fri Sep 24 01:12:26 2010 +0900 +++ b/rep/ServerMainLoop.java Fri Sep 24 02:41:13 2010 +0900 @@ -5,6 +5,7 @@ import java.net.SocketException; import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectionKey; +import java.util.Collection; import java.util.LinkedList; import java.util.Set; import java.util.concurrent.BlockingQueue; @@ -17,6 +18,7 @@ import rep.channel.REPSocketChannel; import rep.gui.SessionManagerEvent; import rep.gui.SessionManagerGUI; +import rep.handler.Editor; import rep.handler.FirstConnector; import rep.handler.REPNode; @@ -113,7 +115,7 @@ private boolean checkWaitingWrite() throws IOException { PacketSet p = writeQueue.poll(); if (p!=null) { - // sendLog(p); + sendLog(p); p.channel.write(p.command); return true; } @@ -121,14 +123,28 @@ } /** + * Move all command to the editor from manager's writing queue to the editor's waiting queue + * @param editor + */ + public void getWriteQueue(Editor editor) { + LinkedList<PacketSet> w = new LinkedList<PacketSet>(); + for(PacketSet p:writeQueue) { + if (p.channel==editor) { + editor.addWaitingCommand(p); + } else { + w.addLast(p); + } + } + writeQueue = w; + } + /** * Debug message * @param p */ - @SuppressWarnings("unused") private void sendLog(PacketSet p) { REPNode to; String s; - to = manager.editorList.editorByChannel(p.channel.channel); + to = p.channel; // manager.editorList.editorByChannel(p.channel.channel); if (to==null) s = p.channel.toString(); else
--- a/rep/SessionManager.java Fri Sep 24 01:12:26 2010 +0900 +++ b/rep/SessionManager.java Fri Sep 24 02:41:13 2010 +0900 @@ -4,6 +4,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.nio.channels.ClosedChannelException; +import java.util.Collection; import java.util.LinkedList; import org.xml.sax.SAXException; @@ -645,4 +646,5 @@ serverMainLoop.gui.invokeLater(doRun); } + }
--- a/rep/handler/Editor.java Fri Sep 24 01:12:26 2010 +0900 +++ b/rep/handler/Editor.java Fri Sep 24 02:41:13 2010 +0900 @@ -182,7 +182,10 @@ // assert(false); // } // } - waitingCommandInMerge.add(set); + waitingCommandInMerge.addLast(set); + // to preserve command order, move all elements from manager's writing queue + manager.getWriteQueue(this); + ServerMainLoop.logger.writeLog("Editor eid:"+eid+" waitingCommandInMerge = "+waitingCommandInMerge); } /**