Mercurial > hg > RemoteEditor > REPSessionManager
annotate 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 |
rev | line source |
---|---|
355 | 1 package rep; |
2 | |
3 import java.io.IOException; | |
4 | |
5 import rep.channel.REPSelectionKey; | |
6 import rep.channel.REPSocketChannel; | |
7 | |
8 public class FirstConnector extends Forwarder { | |
9 | |
10 public FirstConnector(SessionManager manager) { | |
11 super(manager); | |
12 } | |
13 | |
14 public void cancel(REPSocketChannel<REPCommand> socketChannel) { | |
15 manager.remove(socketChannel); | |
16 } | |
17 | |
358 | 18 public void handle(REPSelectionKey<REPCommand> key) throws IOException { |
355 | 19 /* |
20 * 接続要求は、EditorかSlave Editorで、 | |
21 * join, put, sm_join | |
22 * が来る。それ以外はエラー。master もありか? | |
23 * sm_join_ack | |
24 */ | |
25 Forwarder fw; | |
26 REPSocketChannel<REPCommand> channel = key.channel1(); | |
27 REPCommand command = channel.read(); | |
28 SessionManager.logger.writeLog("FirstConnector: command = " + command); | |
29 switch(command.cmd) { | |
30 case SMCMD_JOIN: | |
31 { | |
32 //どのSessionにも属さないエディタをリストに追加 | |
359
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
33 //エディタとchannelは1対1 (ではないかも) |
355 | 34 //エディタが新しくputする場合は新しくソケットを作る |
35 // 1対1でない場合は、multiplexerを挿めば良い | |
359
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
36 Editor editor = manager.newEditor(channel); |
355 | 37 editor.setHost(manager.myHost); |
38 fw = editor; | |
39 break; | |
40 } | |
41 case SMCMD_PUT: | |
42 { | |
359
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
43 // 新しいeditorとsessionをここで作る。eid,sidは、 |
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
44 // session manager IDが付いているので、global unique |
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
45 Editor editor = manager.newEditor(channel); |
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
46 Session session = manager.newSession(editor); |
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
47 editor.setSID(session.getSID()); |
355 | 48 editor.setHost(manager.myHost); |
49 fw = editor; | |
50 break; | |
51 } | |
52 case SMCMD_SM_JOIN: | |
53 { | |
54 fw = new Forwarder(manager); | |
55 manager.smList.addWaitingSessionManager(fw, command); | |
56 break; | |
57 } | |
58 case SMCMD_SM_JOIN_ACK: | |
59 manager.setSessionManagerID(command.sid); | |
60 fw = new Forwarder(manager); | |
61 break; | |
62 default: throw new IOException(); | |
63 } | |
64 //myHost を設定。 | |
65 //立ち上げ時にやるとlocalhostしか取れない | |
66 if(manager.myHost == null) manager.setMyHostName(getLocalHostName()); | |
67 | |
68 fw.setMode(command.cmd); | |
69 manager.registerChannel(channel, fw); | |
70 manager.sessionManage(fw, command); | |
71 | |
72 } | |
73 | |
74 } |