Mercurial > hg > RemoteEditor > REPSessionManager
view rep/handler/Forwarder.java @ 382:4b87f89b3afd
REP Session Manager (Java version)
new structure
author | one@firefly.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Mon, 10 Nov 2008 22:07:45 +0900 |
parents | |
children | 1fca50ce3508 |
line wrap: on
line source
package rep.handler; import java.io.IOException; import rep.PacketSet; import rep.REP; import rep.REPCommand; import rep.SessionManager; import rep.channel.REPLogger; import rep.channel.REPSelectionKey; import rep.channel.REPSocketChannel; /** * @author kono * Forward Editor Command to the other Session Manager * Basic send API is supported. */ public class Forwarder extends REPNode { int seq = 0; // REPCommands we sent to the next editor final int limit=100; // debugging purpose, assert check only final REPLogger ns = REPLogger.singleton(); SessionManager manager; public REP mode = null; public Forwarder(SessionManager manager) { this.manager = manager; } public int seq() { return seq++; } public void send(REPCommand command) { assert(command!=null); assert(channel!=null); REPCommand c = new REPCommand(command); manager.addWriteQueue(new PacketSet(channel,null, c)); } public void sendWithSeq(REPCommand command) { assert(command!=null); assert(channel!=null); REPCommand c = new REPCommand(command); c.setSEQID(seq()); 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 REPNode 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 IOException { assert false; } public boolean isMerging() { return false; } }