Mercurial > hg > RemoteEditor > REPSessionManager
view rep/handler/REPNode.java @ 384:bcdf5476b8e4
restructured-version
author | one@firefly.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Mon, 10 Nov 2008 22:16:37 +0900 |
parents | 4b87f89b3afd |
children | bba62c4ac323 |
line wrap: on
line source
package rep.handler; import java.io.IOException; import rep.REP; import rep.REPCommand; import rep.channel.REPSelectionKey; import rep.channel.REPSocketChannel; /** * @author kono * Abstract class for all REP node * Sub classes: * FirstConnector waiting first connection and determines its type. * Editor editor direct connect or no connection (master/slave) * Forwarder send command to the other session manager * base class for other communication node * Dispatcher Session Manager entry, dispatch commands to editors. * NullForwarder REP node with no connection */ public abstract class REPNode { public int eid; // globally unique (contains SessionManagerID) public int sid=-1; // globally unique public String host; public String file; public REP mode; public REPSocketChannel<REPCommand> channel; public REPNode next; public REPNode() { } public REPNode(int eid, REPSocketChannel<REPCommand> channel) { this.eid = eid; this.channel = channel; } public String getName() { return file; } public void setName(String string) { file = string; } public void setSID(int sid) { this.sid = sid; } public int getSID() { return sid; } public boolean hasSession() { return sid != -1; } public String toString(){ return ("Editor:" + eid); } public void setEID(int eid) { this.eid = eid; } public int getEID(){ return eid; } public void setHost(String host){ if (channel!=null) this.host = host; } public String getHost(){ return host; } public REPSocketChannel<REPCommand> getChannel(){ return channel; } public void setChannel(REPSocketChannel<REPCommand> channel) { this.channel = channel; } public void merge(REPNode editor) { if (sid==-1) sid = editor.sid; if (file==null) file = editor.file; if (host==null) host = editor.host; } public abstract void handle(REPSelectionKey<REPCommand> key) throws IOException; public abstract void cancel(REPSocketChannel<REPCommand> channel1) ; public abstract String getLocalHostName(); public abstract void send(REPCommand command) ; public abstract void setQuit2(REPCommand receivedCommand) ; public abstract int seq() ; public abstract boolean isMerging() ; public abstract boolean manage(REPCommand command) ; public void setMode(REP cmd) { mode = cmd; } public boolean isEditor() { return mode==REP.SMCMD_JOIN||mode==REP.SMCMD_PUT; } public boolean isForwarder() { return mode==REP.SMCMD_SM_JOIN||mode==REP.SMCMD_SM_JOIN_ACK; } public boolean isDirect() { return isEditor(); } public REPNode getNextForwarder() { return next; } public void setNext(REPNode f) { next = f; } }