Mercurial > hg > RemoteEditor > REPSessionManager
view rep/handler/Dispatcher.java @ 387:6f356d160e58
IPv6 any address
author | one@firefly.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Mon, 10 Nov 2008 22:21:52 +0900 |
parents | bba62c4ac323 |
children |
line wrap: on
line source
package rep.handler; import java.io.IOException; import rep.REPCommand; import rep.ServerMainLoop; import rep.Session; import rep.SessionManager; import rep.channel.REPSelectionKey; import rep.channel.REPSocketChannel; /** * @author kono * Handle SessionManager incoming Channel * SessionManager Command and Multiplexed Editor Command come here. * Dispatch Editor command according to the session and the channel. */ public class Dispatcher extends Forwarder { public Dispatcher(SessionManager manager, REPSocketChannel<REPCommand> channel) { super(manager, channel); } public void setQuit2(REPCommand cmd) { send(cmd); } public boolean manage(REPCommand command) { next.send(command); return true; } public String toString(){ return ("Dispatcher:" + channel); } @Override public void handle(REPCommand command, REPSelectionKey<REPCommand> key) throws IOException { /* * SessionManagerから来たコマンドは、Editor関係のコマンドは、 * sessionとeidを判定して、そのeditorにforwardしてやれば良い。 * 残りは、manager.manage() で処理する。 */ ServerMainLoop.logger.writeLog("REPHandlerImpl.handle() : command = " + command); if (manager.sessionManage(this, command)) return; distpatchToEditor(channel, command); } private void distpatchToEditor(REPSocketChannel<REPCommand> channel, REPCommand command) throws IOException { Session s = manager.getSession(command.sid); if (s==null) throw new IOException(); REPNode f = s.getForwarder(channel); if (f==null) throw new IOException(); if (!f.isDirect()) { // another forwarder, pass it to the next session manager f.send(command); return; } /* * local editor case. */ Editor editor = (Editor)f; editor.forwardedCommandManage(command); } public void setNext(REPNode f) { next = f; } public boolean isMerging() { return false; } }