Mercurial > hg > RemoteEditor > REPSessionManager
diff rep/FirstConnector.java @ 355:98607350f7d1
*** empty log message ***
author | kono |
---|---|
date | Fri, 17 Oct 2008 22:11:34 +0900 |
parents | |
children | 034acadc0cdc |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/FirstConnector.java Fri Oct 17 22:11:34 2008 +0900 @@ -0,0 +1,75 @@ +package rep; + +import java.io.IOException; + +import rep.channel.REPSelectionKey; +import rep.channel.REPSocketChannel; + +public class FirstConnector extends Forwarder { + + public FirstConnector(SessionManager manager) { + super(manager); + } + + public void cancel(REPSocketChannel<REPCommand> socketChannel) { + manager.remove(socketChannel); + } + + public void handle(REPSelectionKey<REPCommand> key) throws Exception { + /* + * 接続要求は、EditorかSlave Editorで、 + * join, put, sm_join + * が来る。それ以外はエラー。master もありか? + * sm_join_ack + */ + Forwarder fw; + REPSocketChannel<REPCommand> channel = key.channel1(); + REPCommand command = channel.read(); + SessionManager.logger.writeLog("FirstConnector: command = " + command); + switch(command.cmd) { + case SMCMD_JOIN: + { + //どのSessionにも属さないエディタをリストに追加 + //エディタとchannelは1対1 (ではない) + //エディタが新しくputする場合は新しくソケットを作る + // 1対1でない場合は、multiplexerを挿めば良い + // ここのeditorList はsessionのとは別物 + Editor editor = new Editor(manager,-1,channel); + editor.setHost(manager.myHost); + manager.editorList.add(editor); + fw = editor; + break; + } + case SMCMD_PUT: + { + // put の場合でも、eid は、masterまで聞きにいく必要が + // ある。 + Editor editor = new Editor(manager,0,channel); + editor.setHost(manager.myHost); + manager.editorList.add(editor); + fw = editor; + break; + } + case SMCMD_SM_JOIN: + { + fw = new Forwarder(manager); + manager.smList.addWaitingSessionManager(fw, command); + break; + } + case SMCMD_SM_JOIN_ACK: + manager.setSessionManagerID(command.sid); + fw = new Forwarder(manager); + break; + default: throw new IOException(); + } + //myHost を設定。 + //立ち上げ時にやるとlocalhostしか取れない + if(manager.myHost == null) manager.setMyHostName(getLocalHostName()); + + fw.setMode(command.cmd); + manager.registerChannel(channel, fw); + manager.sessionManage(fw, command); + + } + +}