Mercurial > hg > RemoteEditor > REPSessionManager
view rep/handler/REPNode.java @ 484:7420dea70dd7
Direct Merge first try
author | one |
---|---|
date | Wed, 20 Oct 2010 21:19:24 +0900 |
parents | 87ae0424a62a |
children | cc262a519b8a |
line wrap: on
line source
package rep.handler; import java.io.IOException; import rep.REP; import rep.REPCommand; import rep.Session; import rep.SessionManager; 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 SessionManager manager; public REPNode() { } public REPNode(int eid, SessionManager manager, REPSocketChannel<REPCommand> channel) { this.eid = eid; this.channel = channel; this.manager = manager; } public REPNode(SessionManager manager, REPSocketChannel<REPCommand> channel) { this.channel = channel; this.manager = manager; } 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 mergeEditor(REPNode editor) { if (sid==-1) sid = editor.sid; if (file==null) file = editor.file; if (host==null) host = editor.host; } public abstract void handle(REPCommand command, REPSelectionKey<REPCommand> key) throws IOException; public abstract void cancel(REPSocketChannel<REPCommand> channel1) ; public abstract String getLocalHostName(); /** * Send to the next REPNode (with possible blocking) * @param command */ public abstract void send(REPCommand command) ; /** * write command to the socket channel * @param command */ public abstract void write(REPCommand command) ; public abstract void sendWithSeq(REPCommand command) ; public abstract void setQuit2(REPCommand receivedCommand) ; public abstract int seq() ; public abstract boolean manage(REPCommand command) ; public abstract void selectSession(REPCommand sendCommand,Session session) ; 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; } public void sendSync(REPCommand sync) { next.sendWithSeq(sync); } public abstract void joinAck(REPCommand sendCommand, int sid) ; public abstract void forwardedCommandManage(REPCommand command) ; public abstract void checkWaitingCommandInMerge(); public void sendToEditor(REPCommand m) { send(m); } }