Mercurial > hg > RemoteEditor > REPSessionManager
annotate rep/FirstConnector.java @ 367:1bde894edd83
*** empty log message ***
author | kono |
---|---|
date | Tue, 21 Oct 2008 18:46:04 +0900 |
parents | c432755c3555 |
children |
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); |
360 | 38 command.eid = editor.eid; |
39 command.sid = -1; | |
40 editor.setSID(-1); | |
355 | 41 fw = editor; |
42 break; | |
43 } | |
44 case SMCMD_PUT: | |
45 { | |
359
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
46 // 新しいeditorとsessionをここで作る。eid,sidは、 |
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
47 // session manager IDが付いているので、global unique |
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
48 Editor editor = manager.newEditor(channel); |
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
49 Session session = manager.newSession(editor); |
360 | 50 session.setName(command.string); |
51 editor.setName(command.string); | |
359
fa041bae35f1
all code written for distributed session except gather.
kono
parents:
358
diff
changeset
|
52 editor.setSID(session.getSID()); |
360 | 53 command.eid = editor.eid; |
54 command.sid = editor.sid; | |
355 | 55 fw = editor; |
56 break; | |
57 } | |
58 case SMCMD_SM_JOIN: | |
59 { | |
60 fw = new Forwarder(manager); | |
61 manager.smList.addWaitingSessionManager(fw, command); | |
62 break; | |
63 } | |
365
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
64 case SMCMD_SM_JOIN_ACK: |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
65 manager.setSessionManagerID(command.sid); |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
66 manager.afterConnect(); |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
67 fw = new Forwarder(manager); |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
68 manager.setParent(fw); |
c432755c3555
distributed session debug continue... SELECT/SELECT_ACK loop
kono
parents:
364
diff
changeset
|
69 break; |
355 | 70 default: throw new IOException(); |
71 } | |
72 //myHost を設定。 | |
73 //立ち上げ時にやるとlocalhostしか取れない | |
74 if(manager.myHost == null) manager.setMyHostName(getLocalHostName()); | |
367 | 75 fw.setMode(command.cmd); |
360 | 76 fw.setHost(manager.myHost); |
355 | 77 manager.registerChannel(channel, fw); |
78 manager.sessionManage(fw, command); | |
79 | |
80 } | |
81 | |
82 } |