Mercurial > hg > RemoteEditor > REPSessionManager
comparison rep/SessionManager.java @ 328:6ceb222570cb
merge is working now.
author | kono |
---|---|
date | Sat, 11 Oct 2008 22:23:45 +0900 |
parents | 7b6dede07f4a |
children | a2624f6f7d0d |
comparison
equal
deleted
inserted
replaced
327:7b6dede07f4a | 328:6ceb222570cb |
---|---|
113 * one thread for each communication channel and GUI event. | 113 * one thread for each communication channel and GUI event. |
114 */ | 114 */ |
115 | 115 |
116 public void mainLoop() throws IOException { | 116 public void mainLoop() throws IOException { |
117 while(true){ | 117 while(true){ |
118 checkWaitingCommandInMerge(); | |
118 if (checkInputEvent() || | 119 if (checkInputEvent() || |
119 checkWaitingWrite() || | 120 checkWaitingWrite()) { |
120 checkWaitingCommandInMerge()) { | |
121 // try to do fair execution for waiting task | 121 // try to do fair execution for waiting task |
122 if(selector.selectNow() > 0) select(); | 122 if(selector.selectNow() > 0) select(); |
123 continue; | 123 continue; |
124 } | 124 } |
125 // now we can wait for input packet or event | 125 // now we can wait for input packet or event |
149 /** | 149 /** |
150 * Check waiting command in merge | 150 * Check waiting command in merge |
151 * @return true if there is a processed waiting command | 151 * @return true if there is a processed waiting command |
152 * @throws IOException | 152 * @throws IOException |
153 */ | 153 */ |
154 private boolean checkWaitingCommandInMerge() throws IOException { | 154 private void checkWaitingCommandInMerge() throws IOException { |
155 for(Iterator<PacketSet> it = waitingCommandInMerge.iterator(); it.hasNext();){ | 155 List<PacketSet> w = waitingCommandInMerge; |
156 PacketSet p = it.next(); | 156 waitingCommandInMerge = new LinkedList<PacketSet>(); |
157 if(p.getEditor().isMerging()) { // still merging do nothing | 157 for(PacketSet p: w) { |
158 continue; | 158 Editor e = p.getEditor(); |
159 }else{ | 159 if(e!=null &&e.isMerging()) { // still merging do nothing |
160 // process one command and return true | 160 waitingCommandInMerge.add(p); |
161 manage(p.channel, p.command); | 161 } else { |
162 it.remove(); | 162 manage(p.channel, p.command); |
163 } | |
164 } | |
165 } | |
166 | |
167 public boolean hasWaitingCommand(REPSocketChannel<REPCommand>c) { | |
168 for(PacketSet p:waitingCommandInMerge) { | |
169 if (p.channel==c) { | |
163 return true; | 170 return true; |
164 } | 171 } |
165 } | 172 } |
166 return false; | 173 return false; |
167 } | 174 } |
203 public void manage(REPSocketChannel<REPCommand> channel, REPCommand receivedCommand) throws IOException { | 210 public void manage(REPSocketChannel<REPCommand> channel, REPCommand receivedCommand) throws IOException { |
204 if (sessionManagerCommand(channel, receivedCommand)) return; | 211 if (sessionManagerCommand(channel, receivedCommand)) return; |
205 Session s = getSession(receivedCommand.sid); | 212 Session s = getSession(receivedCommand.sid); |
206 Editor e = s.getEditor(channel); | 213 Editor e = s.getEditor(channel); |
207 // if(e==null) throw new IOException(); | 214 // if(e==null) throw new IOException(); |
215 if (receivedCommand.eid!=REP.MERGE_EID.id && receivedCommand.eid!=e.eid ) { | |
216 if (hasWaitingCommand(channel)) { | |
217 addWaitingCommand(new PacketSet(channel, e, receivedCommand)); | |
218 return; | |
219 } | |
220 } | |
208 e.manage(receivedCommand); | 221 e.manage(receivedCommand); |
209 } | 222 } |
210 | 223 |
211 | 224 |
212 private boolean sessionManagerCommand(REPSocketChannel<REPCommand> channel, | 225 private boolean sessionManagerCommand(REPSocketChannel<REPCommand> channel, |