Mercurial > hg > RemoteEditor > REPSessionManager
view rep/FirstConnector.java @ 365:c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
author | kono |
---|---|
date | Mon, 20 Oct 2008 17:00:42 +0900 |
parents | c965ef2b5fd6 |
children | 1bde894edd83 |
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); command.eid = editor.eid; command.sid = -1; editor.setSID(-1); 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); session.setName(command.string); editor.setName(command.string); editor.setSID(session.getSID()); command.eid = editor.eid; command.sid = editor.sid; 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); manager.afterConnect(); fw = new Forwarder(manager); manager.setParent(fw); break; default: throw new IOException(); } //myHost を設定。 //立ち上げ時にやるとlocalhostしか取れない if(manager.myHost == null) manager.setMyHostName(getLocalHostName()); fw.setHost(manager.myHost); fw.setMode(command.cmd); manager.registerChannel(channel, fw); manager.sessionManage(fw, command); } }