Mercurial > hg > RemoteEditor > REPSessionManager
comparison 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 |
comparison
equal
deleted
inserted
replaced
457:cf61ba25950b | 458:c22f6833d736 |
---|---|
3 import java.io.IOException; | 3 import java.io.IOException; |
4 import java.net.InetSocketAddress; | 4 import java.net.InetSocketAddress; |
5 import java.net.SocketException; | 5 import java.net.SocketException; |
6 import java.nio.channels.ClosedChannelException; | 6 import java.nio.channels.ClosedChannelException; |
7 import java.nio.channels.SelectionKey; | 7 import java.nio.channels.SelectionKey; |
8 import java.util.Collection; | |
8 import java.util.LinkedList; | 9 import java.util.LinkedList; |
9 import java.util.Set; | 10 import java.util.Set; |
10 import java.util.concurrent.BlockingQueue; | 11 import java.util.concurrent.BlockingQueue; |
11 import java.util.concurrent.LinkedBlockingQueue; | 12 import java.util.concurrent.LinkedBlockingQueue; |
12 | 13 |
15 import rep.channel.REPSelector; | 16 import rep.channel.REPSelector; |
16 import rep.channel.REPServerSocketChannel; | 17 import rep.channel.REPServerSocketChannel; |
17 import rep.channel.REPSocketChannel; | 18 import rep.channel.REPSocketChannel; |
18 import rep.gui.SessionManagerEvent; | 19 import rep.gui.SessionManagerEvent; |
19 import rep.gui.SessionManagerGUI; | 20 import rep.gui.SessionManagerGUI; |
21 import rep.handler.Editor; | |
20 import rep.handler.FirstConnector; | 22 import rep.handler.FirstConnector; |
21 import rep.handler.REPNode; | 23 import rep.handler.REPNode; |
22 | 24 |
23 /** | 25 /** |
24 * @author kono | 26 * @author kono |
111 * @throws IOException | 113 * @throws IOException |
112 */ | 114 */ |
113 private boolean checkWaitingWrite() throws IOException { | 115 private boolean checkWaitingWrite() throws IOException { |
114 PacketSet p = writeQueue.poll(); | 116 PacketSet p = writeQueue.poll(); |
115 if (p!=null) { | 117 if (p!=null) { |
116 // sendLog(p); | 118 sendLog(p); |
117 p.channel.write(p.command); | 119 p.channel.write(p.command); |
118 return true; | 120 return true; |
119 } | 121 } |
120 return false; | 122 return false; |
121 } | 123 } |
122 | 124 |
123 /** | 125 /** |
126 * Move all command to the editor from manager's writing queue to the editor's waiting queue | |
127 * @param editor | |
128 */ | |
129 public void getWriteQueue(Editor editor) { | |
130 LinkedList<PacketSet> w = new LinkedList<PacketSet>(); | |
131 for(PacketSet p:writeQueue) { | |
132 if (p.channel==editor) { | |
133 editor.addWaitingCommand(p); | |
134 } else { | |
135 w.addLast(p); | |
136 } | |
137 } | |
138 writeQueue = w; | |
139 } | |
140 /** | |
124 * Debug message | 141 * Debug message |
125 * @param p | 142 * @param p |
126 */ | 143 */ |
127 @SuppressWarnings("unused") | |
128 private void sendLog(PacketSet p) { | 144 private void sendLog(PacketSet p) { |
129 REPNode to; | 145 REPNode to; |
130 String s; | 146 String s; |
131 to = manager.editorList.editorByChannel(p.channel.channel); | 147 to = p.channel; // manager.editorList.editorByChannel(p.channel.channel); |
132 if (to==null) | 148 if (to==null) |
133 s = p.channel.toString(); | 149 s = p.channel.toString(); |
134 else | 150 else |
135 s = to.toString(); | 151 s = to.toString(); |
136 logger.writeLog("writing: "+p.command+" to: " + s); | 152 logger.writeLog("writing: "+p.command+" to: " + s); |