Mercurial > hg > RemoteEditor > REPSessionManager
view rep/Forwarder.java @ 353:0d47ff22ee0e
*** empty log message ***
author | kono |
---|---|
date | Thu, 16 Oct 2008 14:25:45 +0900 |
parents | ef4afcae0c92 |
children | 98607350f7d1 |
line wrap: on
line source
package rep; import java.io.IOException; import rep.channel.REPLogger; import rep.channel.REPSelectionKey; import rep.channel.REPSocketChannel; import rep.handler.PacketSet; import rep.handler.REPHandler; public class Forwarder extends EditorPlus implements REPHandler { int seq = 0; Forwarder next; // REPCommands we sent to the next editor final int limit=100; REPLogger ns = REPLogger.singleton(); SessionManager manager; public Forwarder(SessionManager manager) { this.manager = manager; } public int seq() { return seq++; } public void send(REPCommand command) { assert(command!=null); REPCommand c = new REPCommand(command); manager.addWriteQueue(new PacketSet(channel,null, c)); } public REPSocketChannel<REPCommand> getChannel() { return channel; } public void setChannel(REPSocketChannel<REPCommand> channel) { this.channel = channel; } public void setQuit2(REPCommand cmd) { send(cmd); } public void setNext(Forwarder next) { this.next = next; } public Forwarder getNextForwarder() { return next; } public boolean manage(REPCommand command) { next.send(command); return true; } public String toString(){ return ("Forwarder:" + channel); } public String getLocalHostName() { return channel.getLocalHostName(); } public void cancel(REPSocketChannel<REPCommand> socketChannel) { manager.remove(socketChannel); } public void handle(REPSelectionKey<REPCommand> key) throws Exception { /* * SessionManagerから来たコマンドは、Editor関係のコマンドは、 * sessionとeidを判定して、そのeditorにforwardしてやれば良い。 * 残りは、manager.manage() で処理する。 */ REPSocketChannel<REPCommand> channel = key.channel1(); REPCommand command = channel.read(); SessionManager.logger.writeLog("REPHandlerImpl.handle() : command = " + command); if (manager.sessionManage(this, command)) return; Session s = manager.getSession(command.sid); Forwarder editor = s.getFirstForwarder(); if (editor!=null) { editor.manage(command); } else throw new IOException(); } }