Mercurial > hg > RemoteEditor > REPSessionManager
view rep/FirstConnector.java @ 359:fa041bae35f1
all code written for distributed session except gather.
author | kono |
---|---|
date | Sun, 19 Oct 2008 19:24:38 +0900 |
parents | 034acadc0cdc |
children | b25f832f875d |
line wrap: on
line source
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 IOException { /* * 接続要求は、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を挿めば良い Editor editor = manager.newEditor(channel); editor.setHost(manager.myHost); fw = editor; break; } case SMCMD_PUT: { // 新しいeditorとsessionをここで作る。eid,sidは、 // session manager IDが付いているので、global unique Editor editor = manager.newEditor(channel); Session session = manager.newSession(editor); editor.setSID(session.getSID()); editor.setHost(manager.myHost); 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); } }