0
|
1 package rep;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.net.InetSocketAddress;
|
11
|
5 import java.net.SocketAddress;
|
2
|
6 import java.nio.channels.SelectableChannel;
|
0
|
7 import java.nio.channels.SelectionKey;
|
|
8 import java.nio.channels.Selector;
|
|
9 import java.nio.channels.ServerSocketChannel;
|
|
10 import java.nio.channels.SocketChannel;
|
83
|
11 import java.util.LinkedList;
|
15
|
12 import java.util.StringTokenizer;
|
0
|
13
|
56
|
14 import rep.xml.SessionXMLDecoder;
|
45
|
15 import rep.xml.SessionXMLEncoder;
|
|
16
|
1
|
17 //+-------+--------+--------+-------+--------+---------+------+
|
|
18 //| cmd | session| editor | seqid | lineno | textsiz | text |
|
|
19 //| | id | id | | | | |
|
|
20 //+-------+--------+--------+-------+--------+---------+------+
|
|
21 //o-------header section (network order)-------------o
|
|
22 /*int cmd; // command
|
101
|
23 int sid; // session ID : uniqu to editing file
|
|
24 int eid; // editor ID : owner editor ID = 1。Session に対してユニーク
|
|
25 int seqno; // Sequence number : sequence number はエディタごとに管理
|
1
|
26 int lineno; // line number
|
101
|
27 int textsize; // textsize : bytesize
|
1
|
28 byte[] text;*/
|
|
29
|
8
|
30 public class SessionManager implements ConnectionListener, REPActionListener{
|
0
|
31
|
|
32
|
|
33 private SessionList sessionlist;
|
5
|
34 //SocketChannel sessionchannel;
|
83
|
35 private SessionManagerGUI gui;
|
2
|
36 private Selector selector;
|
7
|
37 private SessionManagerList smList;
|
17
|
38 private String myHost;
|
21
|
39 private boolean isMaster = true;
|
77
|
40 private EditorList allEditorList;
|
78
|
41 private String maxHost;
|
76
|
42 //private boolean addressIsGlobal;
|
6
|
43 //private SocketChannel sessionchannel;
|
7
|
44 //private boolean co;
|
95
|
45 private static int temp_port;
|
|
46 private static int send_port;
|
101
|
47
|
|
48 static final int DEFAULT_PORT = 8766;
|
|
49
|
2
|
50 public SessionManager(int port) {
|
83
|
51 gui = new SessionManagerGUI();
|
2
|
52 }
|
|
53
|
|
54 public void openSelector() throws IOException{
|
|
55 selector = Selector.open();
|
|
56 }
|
0
|
57
|
|
58 public void sessionManagerNet(int port) throws InterruptedException, IOException {
|
2
|
59
|
0
|
60 ServerSocketChannel ssc = ServerSocketChannel.open();
|
101
|
61 ssc.configureBlocking(false); //reuse address 必須
|
|
62
|
|
63 ssc.socket().setReuseAddress(true);
|
|
64
|
0
|
65 ssc.socket().bind(new InetSocketAddress(port));
|
|
66 ssc.register(selector, SelectionKey.OP_ACCEPT);
|
6
|
67
|
|
68
|
0
|
69 sessionlist = new SessionList();
|
7
|
70 smList = new SessionManagerList();
|
77
|
71 allEditorList = new EditorList();
|
0
|
72
|
|
73 while(true){
|
|
74 selector.select();
|
|
75 for(SelectionKey key : selector.selectedKeys()){
|
|
76 if(key.isAcceptable()){
|
28
|
77 /*** serverChannelはenableになったSelectionKeyのchannel ***/
|
|
78 ServerSocketChannel serverChannel = (ServerSocketChannel)key.channel();
|
9
|
79 /*** EditorChannel を用いない記述 ***/
|
28
|
80 SocketChannel channel = serverChannel.accept(); //keyからchannelを取って、accept
|
2
|
81 registerChannel (selector, channel, SelectionKey.OP_READ);
|
0
|
82 channel = null;
|
9
|
83
|
|
84 /*** EditorChannel を用いた記述 ****/
|
|
85 //EditorChannel echannel = (EditorChannel) ssc.accept();
|
|
86 //echannel.setIO();
|
|
87 //registerChannel(selector, echannel, SelectionKey.OP_READ);
|
|
88 //echannel = null;
|
|
89
|
|
90 /*** SelectableEditorChannel ***/
|
|
91 //SocketChannel channel = ssc.accept();
|
|
92 //SelectableEditorChannel echannel2 = new SelectableEditorChannel(channel);
|
|
93 //registerChannel(selector, echannel2, SelectionKey.OP_READ);
|
|
94 //channel = null;
|
|
95 //echannel2 = null;
|
|
96
|
6
|
97 }else if(key.isReadable()){
|
9
|
98
|
|
99 /*** EditorChannel を用いない記述 ***/
|
0
|
100 SocketChannel channel = (SocketChannel)key.channel();
|
75
|
101 REPPacketReceive receive = new REPPacketReceive(channel); //getPacket(), putPacket() にする。
|
|
102 receive.setkey(key);
|
53
|
103 //REPCommand repCom = repRec.unpackUConv();
|
75
|
104 REPCommand receivedCommand = receive.unpack();
|
|
105 manager(channel, receivedCommand);
|
9
|
106
|
|
107 /*** EditorChannel を用いた記述 ****/
|
|
108 //EditorChannel echannel = (EditorChannel) key.channel();
|
|
109 //REPCommand command = echannel.getPacket();
|
|
110 //manager(echannel, command);
|
|
111
|
6
|
112 }else if(key.isConnectable()){
|
|
113 System.out.println("Connectable");
|
21
|
114 }
|
0
|
115 }
|
|
116 }
|
|
117 }
|
1
|
118
|
2
|
119 private synchronized void registerChannel(Selector selector, SelectableChannel channel, int ops) throws IOException {
|
|
120 if(channel == null) {
|
|
121 return;
|
|
122 }
|
9
|
123 //System.out.println("registerChannel()");
|
2
|
124 channel.configureBlocking(false);
|
6
|
125 selector.wakeup();
|
2
|
126 channel.register(selector, ops);
|
|
127 }
|
|
128
|
75
|
129 private void manager(SocketChannel channel, REPCommand receivedCommand) {
|
|
130 if(receivedCommand == null) return;
|
69
|
131 Editor editor;
|
|
132 Session session;
|
75
|
133 REPCommand sendCommand = receivedCommand.clone();
|
78
|
134 REPPacketSend send = new REPPacketSend(channel);
|
|
135 //SessionXMLEncoder encoder = new SessionXMLEncoder();
|
75
|
136
|
|
137 switch(receivedCommand.cmd){
|
38
|
138
|
0
|
139 case REP.SMCMD_JOIN:
|
105
|
140 editor = new Editor(channel);
|
106
|
141 editor.setHost(myHost);
|
105
|
142 int tempeid = allEditorList.addEditor(editor);
|
83
|
143 gui.setComboEditor(tempeid, channel);
|
|
144
|
38
|
145 break;
|
31
|
146
|
1
|
147 case REP.SMCMD_JOIN_ACK:
|
31
|
148 // editorList.setEID(repCmd);
|
|
149 // editorList.sendJoinAck(repCmd);
|
|
150 // sessionmanagerGUI.setComboEditor(repCmd.eid, channel);
|
1
|
151 break;
|
31
|
152
|
0
|
153 case REP.SMCMD_PUT:
|
69
|
154 editor = new Editor(channel);
|
90
|
155 editor.setHost(myHost);
|
92
|
156 allEditorList.addEditor(editor);
|
56
|
157 editor.setEID(1);
|
75
|
158 editor.setName(receivedCommand.string);
|
69
|
159 session = new Session(editor);
|
67
|
160 session.setOwner(true);
|
63
|
161 session.addEditor(editor);
|
56
|
162 sessionlist.addSession(session);
|
83
|
163 gui.setComboSession(session.getSID(), session.getName());
|
|
164 gui.setComboEditor(editor.getEID(), editor.getChannel());
|
56
|
165 session.addToRoutingTable(editor);
|
84
|
166 sendCommand.setCMD(REP.SMCMD_PUT_ACK);
|
|
167 sendCommand.setEID(1);
|
|
168 sendCommand.setSID(session.getSID());
|
|
169 editor.send(sendCommand);
|
56
|
170
|
|
171 //if(isMaster){
|
78
|
172 SessionXMLEncoder sessionEncoder = new SessionXMLEncoder(session);
|
56
|
173 REPCommand command = new REPCommand();
|
|
174 command.setSID(session.getSID());
|
78
|
175 command.setString(sessionEncoder.sessionListToXML());
|
98
|
176
|
|
177 command.setCMD(REP.SMCMD_UPDATE);
|
|
178 smList.sendExcept(channel, command);
|
|
179
|
|
180
|
|
181 // if(isMaster){
|
|
182 // command.setCMD(REP.SMCMD_UPDATE_ACK);
|
|
183 // smList.sendToSlave(command);
|
|
184 // }else{
|
|
185 // command.setCMD(REP.SMCMD_UPDATE);
|
|
186 // smList.sendToMaster(command);
|
|
187 // }
|
38
|
188 break;
|
31
|
189
|
9
|
190 // case REP.SMCMD_PUT_ACK:
|
|
191 // break;
|
31
|
192
|
0
|
193 case REP.SMCMD_SELECT:
|
66
|
194 // sessionlist.addEditor(channel, repCmd.sid, repCmd); //sessionlistへ追加
|
70
|
195 editor = new Editor(channel);
|
94
|
196
|
75
|
197 session = sessionlist.getSession(receivedCommand.sid);
|
94
|
198
|
70
|
199 if(session.isOwner()){
|
83
|
200 int eid2 = session.addEditor(editor);
|
|
201 editor.setEID(eid2);
|
78
|
202 //REPPacketSend send = new REPPacketSend(channel);
|
84
|
203 //receivedCommand.setCMD(REP.SMCMD_SELECT_ACK);
|
|
204 //receivedCommand.setEID(eid2);
|
|
205 sendCommand.setCMD(REP.SMCMD_SELECT_ACK);
|
|
206 sendCommand.setEID(eid2);
|
|
207 send.send(sendCommand);
|
66
|
208 }else {
|
85
|
209 Editor master = session.getMaster();
|
|
210 master.send(receivedCommand);
|
94
|
211 session.addEditor(editor);
|
66
|
212 }
|
|
213
|
8
|
214 break;
|
38
|
215
|
8
|
216 case REP.SMCMD_SELECT_ACK:
|
85
|
217
|
|
218 String hostport = receivedCommand.string;
|
|
219 Editor editor2 = allEditorList.getEditor(hostport);
|
|
220 if(editor2 != null) {
|
|
221 REPCommand command2 = new REPCommand();
|
|
222 command2.setCMD(REP.SMCMD_JOIN_ACK);
|
93
|
223 command2.setSID(receivedCommand.sid);
|
85
|
224 command2.setEID(receivedCommand.eid);
|
|
225 editor2.send(command2);
|
|
226 }else{
|
|
227 smList.sendExcept(channel, receivedCommand);
|
|
228 }
|
|
229
|
|
230 //receivedCommand.setCMD(REP.SMCMD_JOIN_ACK);
|
|
231 //receivedCommand.setEID(receivedCommand.eid);
|
|
232 //session = sessionlist.getSession(receivedCommand.sid);
|
|
233 //session.sendToEditor(receivedCommand);
|
69
|
234 //Editor editor3 = session3.getEditorList().get(0);
|
|
235 //REPPacketSend send = new REPPacketSend(editor3.getChannel());
|
|
236 //send.send(repCmd);
|
1
|
237 break;
|
38
|
238
|
8
|
239 case REP.SMCMD_SM_JOIN:
|
78
|
240
|
83
|
241 //SessionManagerのリストへ追加
|
|
242 smList.add(channel);
|
|
243
|
78
|
244 //XMLからSessionListオブジェクトを生成する。
|
77
|
245 SessionXMLDecoder decoder = new SessionXMLDecoder();
|
79
|
246 SessionList receivedSessionList = decoder.decode(receivedCommand.string);
|
78
|
247
|
83
|
248 //SessionListへ追加し変換テーブルを生成する。
|
|
249 sessionlist.update(channel, receivedSessionList);
|
|
250
|
78
|
251 //myHost を設定。
|
76
|
252 if(myHost == null) setMyHostName(getLocalHostName(channel));
|
78
|
253
|
79
|
254 //maxHost を設定。
|
95
|
255 if(setMaxHost(channel, receivedSessionList.getMaxHost())){
|
|
256 sendCommand = new REPCommand();
|
|
257 sendCommand.setCMD(REP.SMCMD_CH_MASTER);
|
|
258 sendCommand.setString(maxHost);
|
|
259 smList.sendExcept(channel, sendCommand);
|
|
260 }
|
77
|
261
|
78
|
262 //SessionListからXMLを生成。
|
|
263 //joinしてきたSessionManagerに対してACKを送信。
|
|
264 SessionXMLEncoder sessionlistEncoder = new SessionXMLEncoder(sessionlist);
|
|
265 sendCommand = new REPCommand();
|
|
266 sendCommand.setCMD(REP.SMCMD_SM_JOIN_ACK);
|
|
267 sendCommand.setString(sessionlistEncoder.sessionListToXML());
|
|
268 send.send(sendCommand);
|
|
269
|
83
|
270 //その他の SessionManager に対して SMCMD_UPDATEを 送信。
|
78
|
271 sendCommand = new REPCommand();
|
83
|
272 sendCommand.setCMD(REP.SMCMD_UPDATE);
|
78
|
273 sendCommand.setString(receivedCommand.string);
|
|
274 smList.sendExcept(channel, sendCommand);
|
|
275
|
83
|
276 //その他のSessionManagerに対してSMCMD_SM_JOINを送信。
|
|
277 //sendCommand = new REPCommand();
|
|
278 //sendCommand.setCMD(REP.SMCMD_SM_JOIN);
|
|
279 //sendCommand.setString(receivedCommand.string);
|
|
280 //smList.sendExcept(channel, sendCommand);
|
|
281
|
31
|
282 if(isMaster){
|
45
|
283 }else {
|
31
|
284 }
|
78
|
285
|
8
|
286 break;
|
38
|
287
|
8
|
288 case REP.SMCMD_SM_JOIN_ACK:
|
82
|
289
|
|
290 //XMLからSessionListオブジェクトを生成。
|
|
291 SessionXMLDecoder decoder2 = new SessionXMLDecoder();
|
|
292 SessionList receivedSessionList2 = decoder2.decode(receivedCommand.string);
|
|
293
|
|
294 //maxHostを決定。
|
95
|
295 if(setMaxHost(channel, receivedSessionList2.getMaxHost())){
|
|
296 sendCommand = new REPCommand();
|
|
297 sendCommand.setCMD(REP.SMCMD_CH_MASTER);
|
|
298 sendCommand.setString(maxHost);
|
|
299 smList.sendExcept(channel, sendCommand);
|
|
300 }
|
82
|
301
|
38
|
302 if(isMaster){
|
39
|
303 }else{
|
38
|
304 }
|
|
305
|
6
|
306 break;
|
38
|
307
|
8
|
308 case REP.SMCMD_UPDATE:
|
70
|
309
|
99
|
310 SessionXMLDecoder decoder3 = new SessionXMLDecoder();
|
|
311 SessionList receivedSessionList3 = decoder3.decode(receivedCommand.string);
|
|
312
|
|
313 //SessionListへ追加し変換テーブルを生成する。
|
|
314 sessionlist.update(channel, receivedSessionList3);
|
|
315
|
|
316 smList.sendExcept(channel, receivedCommand);
|
70
|
317
|
100
|
318 for(Session session3 : receivedSessionList3.getList()){
|
|
319 gui.setComboSession(session3.getSID(), session3.getName());
|
|
320 }
|
|
321
|
99
|
322 //SessionのownerのEditor
|
|
323 //editor = new Editor(channel);
|
|
324 //editor.setName(receivedCommand.string);
|
|
325
|
|
326
|
70
|
327
|
99
|
328 //session = new Session(editor);
|
|
329 //session.addEditor(editor);
|
70
|
330
|
99
|
331 //sessionlist.addSession(session);
|
|
332
|
|
333 //gui.setComboSession(session.getSID(), session.getName());
|
70
|
334
|
83
|
335 //if(isMaster){
|
|
336 // receivedCommand.setCMD(REP.SMCMD_UPDATE_ACK);
|
|
337 // smList.sendToSlave(receivedCommand);
|
|
338 //}else{
|
|
339 // receivedCommand.setCMD(REP.SMCMD_UPDATE);
|
|
340 // smList.sendToMaster(receivedCommand);
|
|
341 //}
|
9
|
342 break;
|
38
|
343
|
9
|
344 case REP.SMCMD_UPDATE_ACK:
|
75
|
345 if(receivedCommand.sid > sessionlist.getList().size()){
|
73
|
346 editor = new Editor(channel);
|
75
|
347 editor.setName(receivedCommand.string);
|
73
|
348
|
|
349 session = new Session(editor);
|
|
350 session.addEditor(editor);
|
|
351
|
|
352 sessionlist.addSession(session);
|
|
353
|
83
|
354 gui.setComboSession(session.getSID(), session.getName());
|
73
|
355 }
|
75
|
356 smList.sendToSlave(receivedCommand);
|
1
|
357 break;
|
38
|
358
|
3
|
359 case REP.REPCMD_READ:
|
17
|
360 //sessionlist.sendCmd(channel, repCmd);
|
3
|
361 break;
|
38
|
362
|
95
|
363 case REP.SMCMD_CH_MASTER:
|
|
364 //maxHost を設定。
|
|
365 if(setMaxHost(channel, receivedCommand.string)){
|
|
366 sendCommand = new REPCommand();
|
|
367 sendCommand.setCMD(REP.SMCMD_CH_MASTER);
|
|
368 sendCommand.setString(maxHost);
|
|
369 smList.sendExcept(channel, sendCommand);
|
|
370 }
|
|
371 break;
|
|
372
|
0
|
373 default:
|
9
|
374 //sessionlist.sendCmd(channel, repCmd);
|
75
|
375 sessionlist.sendToNextEditor(channel, receivedCommand);
|
0
|
376 break;
|
|
377 }
|
|
378 }
|
83
|
379
|
79
|
380 private boolean setMaxHost(SocketChannel channel, String host) {
|
81
|
381 if(maxHost == null) {
|
|
382 maxHost = myHost;
|
|
383 sessionlist.setMaxHost(maxHost);
|
|
384 }
|
82
|
385 if(host.compareTo(maxHost) > 0){
|
79
|
386 //host > MaxHost なら maxHost = host
|
|
387 //masterを設定する。
|
|
388 maxHost = host;
|
|
389 sessionlist.setMaxHost(maxHost);
|
|
390 setMaster(false, channel);
|
|
391 return true;
|
|
392 }else{
|
|
393 return false;
|
|
394 }
|
78
|
395 }
|
|
396
|
76
|
397 private void setMyHostName(String localHostName) {
|
95
|
398 myHost = localHostName + temp_port;
|
81
|
399 if(maxHost == null) {
|
|
400 maxHost = myHost;
|
|
401 sessionlist.setMaxHost(maxHost);
|
|
402 }
|
77
|
403 allEditorList.setHost(myHost);
|
76
|
404 }
|
0
|
405
|
77
|
406 private void setMaster(boolean b, SocketChannel channel) {
|
75
|
407 isMaster = b;
|
|
408 System.out.println("isMaster = " + b);
|
77
|
409 smList.setMaster(channel);
|
75
|
410 }
|
|
411
|
0
|
412 public static void main(String[] args) throws InterruptedException, IOException {
|
101
|
413 int port = DEFAULT_PORT;
|
|
414 int port_s = DEFAULT_PORT;
|
1
|
415
|
82
|
416 if(args.length > 0){
|
39
|
417 port = Integer.parseInt(args[0]);
|
95
|
418 port_s = Integer.parseInt(args[1]);
|
0
|
419 }
|
95
|
420 temp_port = port;
|
|
421 send_port = port_s;
|
0
|
422 SessionManager sm = new SessionManager(port);
|
2
|
423 sm.openSelector();
|
|
424 sm.openWindow();
|
0
|
425 sm.sessionManagerNet(port);
|
|
426 }
|
|
427
|
2
|
428 private void openWindow() {
|
83
|
429 Thread th = new Thread( gui );
|
2
|
430 th.start();
|
75
|
431 //System.out.println(sessionmanagerGUI.toString());
|
83
|
432 gui.addConnectionListener(this);
|
|
433 gui.addREPActionListener(this);
|
2
|
434 }
|
|
435
|
|
436 private void connectSession(String host) {
|
101
|
437 int port = DEFAULT_PORT;
|
95
|
438 port = send_port;
|
1
|
439 InetSocketAddress addr = new InetSocketAddress(host, port);
|
|
440 try {
|
6
|
441 SocketChannel sessionchannel = SocketChannel.open();
|
1
|
442 sessionchannel.configureBlocking(true);
|
|
443 sessionchannel.connect(addr);
|
6
|
444 while(!sessionchannel.finishConnect()){
|
77
|
445 System.out.print("test afro");
|
6
|
446 }
|
|
447 System.out.println("");
|
2
|
448 registerChannel(selector, sessionchannel, SelectionKey.OP_READ);
|
45
|
449
|
77
|
450 sm_join(sessionchannel);
|
45
|
451
|
1
|
452 }catch (IOException e) {
|
|
453 e.printStackTrace();
|
|
454 }
|
|
455 }
|
77
|
456
|
|
457 private void sm_join(SocketChannel channel){
|
79
|
458
|
|
459 //SM_JOINコマンドを生成。
|
77
|
460 REPCommand command = new REPCommand();
|
|
461 command.setCMD(REP.SMCMD_SM_JOIN);
|
79
|
462
|
|
463 //hostnameをセット。
|
82
|
464 setMyHostName(getLocalHostName(channel));
|
|
465
|
|
466 //XMLを生成。送信コマンドにセット。
|
77
|
467 SessionXMLEncoder encoder = new SessionXMLEncoder(sessionlist);
|
|
468 String string = encoder.sessionListToXML();
|
|
469 command.setString(string);
|
|
470
|
79
|
471 //SM_JOINコマンドを送信。
|
77
|
472 REPPacketSend send = new REPPacketSend(channel);
|
|
473 send.send(command);
|
|
474
|
79
|
475 //SessionManagerのListに追加。
|
77
|
476 smList.add(channel);
|
|
477 }
|
2
|
478
|
75
|
479 private String getLocalHostName(SocketChannel channel) {
|
74
|
480 String host = null;
|
|
481 host = channel.socket().getLocalAddress().getHostName();
|
|
482 return host;
|
|
483 }
|
|
484
|
77
|
485 // private String getSocketString(SocketChannel sessionchannel) {
|
|
486 // SocketAddress socket = sessionchannel.socket().getRemoteSocketAddress();
|
|
487 // //String inetAddressString = sessionchannel.socket().getInetAddress().toString();
|
|
488 // StringTokenizer stn = new StringTokenizer(socket.toString(), "/");
|
|
489 // String socketString = null;
|
|
490 // while(stn.hasMoreTokens()){
|
|
491 // socketString = stn.nextToken();
|
|
492 // //System.out.println(socketString);
|
|
493 // }
|
|
494 // return socketString;
|
|
495 // }
|
14
|
496
|
2
|
497 public void connectionOccured(ConnectionEvent event) {
|
|
498 connectSession(event.getHost());
|
|
499 }
|
8
|
500
|
|
501 public void ActionOccured(REPActionEvent event) {
|
104
|
502
|
107
|
503 /*** 元の ***/
|
|
504 // SocketChannel editorChannel = event.getEditorChannel();
|
|
505 // int sid = event.getSID();
|
|
506 // Editor editor = new Editor(editorChannel);
|
|
507 // editor.setHost(this.myHost);
|
|
508 // Session session = sessionlist.getSession(sid);
|
|
509 // session.addEditor(editor);
|
|
510 //
|
|
511 // Editor owner = session.getMaster();
|
|
512 //
|
|
513 // REPCommand command = new REPCommand();
|
|
514 // command.setCMD(REP.SMCMD_SELECT);
|
|
515 // command.setSID(sid);
|
|
516 // command.setString(editor.getHost() + ":" + editor.getPort());
|
|
517 // owner.send(command);
|
103
|
518
|
|
519 /*** 書き直し ***/
|
107
|
520 SocketChannel channel = event.getEditorChannel();
|
|
521 int sid = event.getSID();
|
|
522 Session session = sessionlist.getSession(sid);
|
|
523 if(session.isOwner()){
|
|
524 int eid = session.addEditor(new Editor(channel));
|
|
525 REPCommand sendCommand = new REPCommand();
|
|
526 sendCommand.setCMD(REP.SMCMD_JOIN_ACK);
|
|
527 sendCommand.setEID(eid);
|
|
528 sendCommand.setSID(sid);
|
|
529 REPPacketSend sender = new REPPacketSend(channel);
|
|
530 sender.send(sendCommand);
|
|
531 }else {
|
|
532 SocketChannel editorChannel = event.getEditorChannel();
|
|
533 sid = event.getSID();
|
|
534 Editor editor = new Editor(editorChannel);
|
|
535 editor.setHost(myHost);
|
|
536 session = sessionlist.getSession(sid);
|
|
537 session.addEditor(editor);
|
|
538
|
|
539 Editor owner = session.getMaster();
|
|
540
|
|
541 REPCommand command = new REPCommand();
|
|
542 command.setCMD(REP.SMCMD_SELECT);
|
|
543 command.setSID(sid);
|
|
544 command.setString(editor.getHost() + ":" + editor.getPort());
|
|
545 owner.send(command);
|
|
546 }
|
72
|
547
|
|
548
|
84
|
549 //REPPacketSend send = new REPPacketSend(editorChannel);
|
|
550 //send.send(new REPCommand(REP.SMCMD_SELECT_ACK, sid, eid, 0,0,0,""));
|
72
|
551
|
|
552
|
|
553
|
71
|
554 //sessionlist.sendSelect(sid);
|
8
|
555 }
|
0
|
556 }
|