Mercurial > hg > RemoteEditor > REPSessionManager
diff rep/ServerMainLoop.java @ 458:c22f6833d736
synchronize Editor's waiting queue and Manager's writing queue
author | one |
---|---|
date | Fri, 24 Sep 2010 02:41:13 +0900 |
parents | 21cb16b7f3df |
children | 66c4f6b29baf |
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