0
|
1 package rep;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.net.InetSocketAddress;
|
2
|
5 import java.nio.channels.SelectableChannel;
|
0
|
6 import java.nio.channels.SelectionKey;
|
|
7 import java.nio.channels.Selector;
|
179
|
8
|
178
|
9 import java.util.Iterator;
|
83
|
10 import java.util.LinkedList;
|
144
|
11 import java.util.List;
|
178
|
12 import java.util.concurrent.BlockingQueue;
|
192
|
13 import java.util.concurrent.LinkedBlockingQueue;
|
0
|
14
|
198
|
15 import javax.swing.SwingUtilities;
|
|
16
|
123
|
17 import rep.channel.REPServerSocketChannel;
|
133
|
18 import rep.channel.REPSocketChannel;
|
144
|
19 import rep.handler.PacketSet;
|
146
|
20 import rep.handler.REPHandler;
|
148
|
21 import rep.handler.REPHandlerImpl;
|
164
|
22 import rep.handler.REPHandlerInMerge;
|
158
|
23 import rep.channel.REPSelector;
|
56
|
24 import rep.xml.SessionXMLDecoder;
|
45
|
25 import rep.xml.SessionXMLEncoder;
|
198
|
26 import rep.channel.REPSelectionKey;
|
|
27 /*
|
1
|
28 //+-------+--------+--------+-------+--------+---------+------+
|
|
29 //| cmd | session| editor | seqid | lineno | textsiz | text |
|
|
30 //| | id | id | | | | |
|
|
31 //+-------+--------+--------+-------+--------+---------+------+
|
|
32 //o-------header section (network order)-------------o
|
198
|
33 int cmd; // command
|
101
|
34 int sid; // session ID : uniqu to editing file
|
123
|
35 int eid; // editor ID : owner editor ID = 1。Session に対して unique
|
122
|
36 int seqno; // Sequence number : sequence number はエディタごとに管理
|
1
|
37 int lineno; // line number
|
101
|
38 int textsize; // textsize : bytesize
|
198
|
39 byte[] text;
|
|
40 */
|
1
|
41
|
8
|
42 public class SessionManager implements ConnectionListener, REPActionListener{
|
0
|
43
|
164
|
44 private LinkedList<Session> sessionList;
|
83
|
45 private SessionManagerGUI gui;
|
198
|
46 private REPSelector<REPCommand> selector;
|
7
|
47 private SessionManagerList smList;
|
17
|
48 private String myHost;
|
21
|
49 private boolean isMaster = true;
|
144
|
50 private List<Editor> editorList;
|
78
|
51 private String maxHost;
|
148
|
52 private boolean isSimulation;
|
212
|
53 private List<PacketSet> waitingCommandInMerge;
|
178
|
54 private BlockingQueue<SessionManagerEvent> waitingQueue;
|
95
|
55 private static int temp_port;
|
|
56 private static int send_port;
|
101
|
57 static final int DEFAULT_PORT = 8766;
|
|
58
|
2
|
59 public SessionManager(int port) {
|
191
|
60
|
2
|
61 }
|
|
62
|
|
63 public void openSelector() throws IOException{
|
191
|
64 selector = REPSelector.create();
|
2
|
65 }
|
0
|
66
|
155
|
67 public void init(int port) throws InterruptedException, IOException {
|
2
|
68
|
186
|
69 REPServerSocketChannel<REPCommand> ssc = REPServerSocketChannel.<REPCommand>open(new REPCommandPacker());
|
122
|
70 ssc.configureBlocking(false); //reuse address 必須
|
101
|
71 ssc.socket().setReuseAddress(true);
|
212
|
72 //getAllByNameで取れた全てのアドレスに対してbindする
|
|
73 ssc.socket().bind(new InetSocketAddress(port));
|
192
|
74 ssc.register(selector, SelectionKey.OP_ACCEPT, new REPHandlerImpl(-1, this));
|
6
|
75
|
144
|
76 sessionList = new LinkedList<Session>();
|
7
|
77 smList = new SessionManagerList();
|
144
|
78 editorList = new LinkedList<Editor>();
|
212
|
79 waitingCommandInMerge = new LinkedList<PacketSet>();
|
192
|
80 waitingQueue = new LinkedBlockingQueue<SessionManagerEvent>();
|
215
|
81
|
155
|
82 }
|
|
83
|
|
84 private void mainLoop() throws IOException {
|
0
|
85 while(true){
|
178
|
86 if(checkSend()){
|
|
87 if(selector.selectNow() > 0){
|
|
88 select();
|
|
89 }
|
|
90 continue;
|
|
91 }
|
215
|
92 System.out.println(selector.select());
|
144
|
93 select();
|
|
94 }
|
|
95 }
|
|
96
|
178
|
97 private boolean checkSend() {
|
212
|
98 for(Iterator<PacketSet> it = waitingCommandInMerge.iterator(); it.hasNext();){
|
178
|
99 PacketSet p = it.next();
|
|
100 if(p.getEditor().isMerging()) {
|
|
101 continue;
|
|
102 }else{
|
|
103 manage(p.channel, p.command);
|
|
104 it.remove();
|
212
|
105 return true;
|
178
|
106 }
|
|
107 }
|
|
108 return false;
|
|
109 }
|
|
110
|
144
|
111 private void select() throws IOException {
|
212
|
112 SessionManagerEvent e;
|
|
113 while((e = waitingQueue.poll())!=null){
|
178
|
114 e.exec();
|
|
115 }
|
198
|
116 for(REPSelectionKey<REPCommand> key : selector.selectedKeys1()){
|
144
|
117 if(key.isAcceptable()){
|
|
118 /*** serverChannelはenableになったSelectionKeyのchannel ***/
|
199
|
119 REPSocketChannel<REPCommand> channel = key.accept(new REPCommandPacker());
|
144
|
120 registerChannel (selector, channel, SelectionKey.OP_READ);
|
|
121 channel = null;
|
123
|
122
|
144
|
123 }else if(key.isReadable()){
|
212
|
124 REPHandler handler = (REPHandler)(key.attachment());
|
146
|
125 handler.handle(key);
|
144
|
126
|
0
|
127 }
|
|
128 }
|
|
129 }
|
1
|
130
|
212
|
131 private void registerChannel(REPSelector selector, SelectableChannel channel, int ops) throws IOException {
|
2
|
132 if(channel == null) {
|
|
133 return;
|
|
134 }
|
|
135 channel.configureBlocking(false);
|
170
|
136 REPHandler handler = new REPHandlerImpl(-1, this);
|
148
|
137 channel.register(selector, ops, handler);
|
2
|
138 }
|
|
139
|
144
|
140 public void manage(REPSocketChannel<REPCommand> channel, REPCommand receivedCommand) {
|
75
|
141 if(receivedCommand == null) return;
|
158
|
142 //Session session;
|
141
|
143 REPCommand sendCommand = new REPCommand(receivedCommand);
|
178
|
144 REPSocketChannel<REPCommand> send = channel;
|
144
|
145
|
75
|
146 switch(receivedCommand.cmd){
|
144
|
147
|
0
|
148 case REP.SMCMD_JOIN:
|
164
|
149 {
|
|
150 //どのSessionにも属さないエディタをリストに追加
|
212
|
151 //エディタとchannelは1対1
|
|
152 //エディタが新しくputする場合は新しくソケットを作る
|
164
|
153 Editor editor = new Editor(editorList.size(), channel);
|
|
154 editor.setHost(myHost);
|
|
155 editorList.add(editor);
|
144
|
156
|
212
|
157 guiUpdate();
|
199
|
158
|
164
|
159 }
|
|
160
|
|
161 break;
|
144
|
162
|
1
|
163 case REP.SMCMD_JOIN_ACK:
|
212
|
164 assert (false);
|
1
|
165 break;
|
144
|
166
|
0
|
167 case REP.SMCMD_PUT:
|
164
|
168 {
|
|
169 //エディタのリストに追加
|
|
170 Editor editor = new Editor(editorList.size(), channel);
|
|
171 editorList.add(editor);
|
|
172
|
|
173 //Sessionを生成
|
|
174 int sid = sessionList.size();
|
|
175 editor = new Editor(0, channel);
|
|
176 editor.setHost(myHost);
|
|
177 Session session = new Session(sid, editor);
|
|
178 session.hasOwner(true);
|
|
179 sessionList.add(new Session(sid, editor));
|
|
180
|
212
|
181 guiUpdate();
|
158
|
182
|
164
|
183 //エディタにAckを送信
|
|
184 sendCommand.setCMD(REP.SMCMD_PUT_ACK);
|
|
185 sendCommand.setEID(editor.getEID());
|
|
186 sendCommand.setSID(session.getSID());
|
|
187 editor.send(sendCommand);
|
144
|
188
|
164
|
189 //他のSessionManagerへSessionの追加を報告
|
212
|
190 //親に送って、親から子へ
|
164
|
191 SessionXMLEncoder sessionEncoder = new SessionXMLEncoder(session);
|
|
192 REPCommand command = new REPCommand();
|
|
193 command.setSID(session.getSID());
|
|
194 command.setString(sessionEncoder.sessionListToXML());
|
|
195 command.setCMD(REP.SMCMD_UPDATE);
|
|
196 smList.sendExcept(channel, command);
|
|
197
|
|
198 }
|
|
199
|
|
200 break;
|
133
|
201
|
0
|
202 case REP.SMCMD_SELECT:
|
164
|
203 {
|
178
|
204 //他のSessionManagerをエディタとしてSessionに追加
|
164
|
205 Editor editor = new Editor(channel);
|
|
206 Session session = getSession(receivedCommand.sid);
|
|
207 session.addEditor(editor);
|
|
208
|
|
209 if(session.hasOwner()){
|
|
210 //このSessionManagerがオーナーを持っている場合、Sessionにエディタを追加し、エディタへAckを返す
|
|
211 sendCommand.setCMD(REP.SMCMD_SELECT_ACK);
|
|
212 sendCommand.setEID(editor.getEID());
|
|
213 editor.send(sendCommand);
|
|
214 }else{
|
|
215 //オーナーを持ってない場合は、オーナーを持っているSessionManagerへSELECTコマンドを中継する
|
|
216 Editor owner = session.getOwner();
|
|
217 owner.send(receivedCommand);
|
148
|
218 }
|
164
|
219 }
|
144
|
220
|
164
|
221 break;
|
144
|
222
|
8
|
223 case REP.SMCMD_SELECT_ACK:
|
160
|
224 {
|
85
|
225 String hostport = receivedCommand.string;
|
160
|
226 Editor editor = getEditor(hostport);
|
164
|
227
|
160
|
228 if(editor != null) {
|
|
229 //host, port を見て、このコマンドが自分が送信したSelectコマンドのAckかどうかを判断する
|
|
230 REPCommand command = new REPCommand();
|
|
231 command.setCMD(REP.SMCMD_JOIN_ACK);
|
|
232 command.setSID(receivedCommand.sid);
|
|
233 command.setEID(receivedCommand.eid);
|
|
234 editor.send(command);
|
164
|
235
|
85
|
236 }else{
|
160
|
237 //自分が送信したコマンドでなければ、次のSessionManagerへ中継する
|
85
|
238 smList.sendExcept(channel, receivedCommand);
|
|
239 }
|
160
|
240 }
|
144
|
241
|
164
|
242 break;
|
144
|
243
|
8
|
244 case REP.SMCMD_SM_JOIN:
|
164
|
245
|
160
|
246 {
|
122
|
247 //SessionManagerのリストへ追加
|
83
|
248 smList.add(channel);
|
144
|
249
|
122
|
250 //XMLからSessionListオブジェクトを生成する。
|
77
|
251 SessionXMLDecoder decoder = new SessionXMLDecoder();
|
79
|
252 SessionList receivedSessionList = decoder.decode(receivedCommand.string);
|
144
|
253
|
122
|
254 //myHost を設定。
|
178
|
255 //立ち上げ時にやるとlocalhostしか取れない
|
76
|
256 if(myHost == null) setMyHostName(getLocalHostName(channel));
|
144
|
257
|
122
|
258 //maxHost を設定。
|
95
|
259 if(setMaxHost(channel, receivedSessionList.getMaxHost())){
|
|
260 sendCommand = new REPCommand();
|
|
261 sendCommand.setCMD(REP.SMCMD_CH_MASTER);
|
|
262 sendCommand.setString(maxHost);
|
|
263 smList.sendExcept(channel, sendCommand);
|
|
264 }
|
144
|
265
|
122
|
266 //SessionListからXMLを生成。
|
|
267 //joinしてきたSessionManagerに対してACKを送信。
|
164
|
268 SessionXMLEncoder sessionlistEncoder = new SessionXMLEncoder(sessionList);
|
78
|
269 sendCommand = new REPCommand();
|
|
270 sendCommand.setCMD(REP.SMCMD_SM_JOIN_ACK);
|
|
271 sendCommand.setString(sessionlistEncoder.sessionListToXML());
|
178
|
272 send.write(sendCommand);
|
144
|
273
|
122
|
274 //その他の SessionManager に対して SMCMD_UPDATEを 送信。
|
78
|
275 sendCommand = new REPCommand();
|
83
|
276 sendCommand.setCMD(REP.SMCMD_UPDATE);
|
78
|
277 sendCommand.setString(receivedCommand.string);
|
|
278 smList.sendExcept(channel, sendCommand);
|
144
|
279
|
160
|
280 }
|
164
|
281 break;
|
144
|
282
|
8
|
283 case REP.SMCMD_SM_JOIN_ACK:
|
144
|
284
|
122
|
285 //XMLからSessionListオブジェクトを生成。
|
82
|
286 SessionXMLDecoder decoder2 = new SessionXMLDecoder();
|
|
287 SessionList receivedSessionList2 = decoder2.decode(receivedCommand.string);
|
144
|
288
|
122
|
289 //maxHostを決定。
|
95
|
290 if(setMaxHost(channel, receivedSessionList2.getMaxHost())){
|
|
291 sendCommand = new REPCommand();
|
|
292 sendCommand.setCMD(REP.SMCMD_CH_MASTER);
|
|
293 sendCommand.setString(maxHost);
|
|
294 smList.sendExcept(channel, sendCommand);
|
|
295 }
|
144
|
296
|
6
|
297 break;
|
144
|
298
|
8
|
299 case REP.SMCMD_UPDATE:
|
200
|
300 {
|
99
|
301 SessionXMLDecoder decoder3 = new SessionXMLDecoder();
|
|
302 SessionList receivedSessionList3 = decoder3.decode(receivedCommand.string);
|
144
|
303
|
200
|
304 //UPDATEコマンドにより送られてきたSessionの情報を追加する
|
|
305 LinkedList<Session> list = receivedSessionList3.getList();
|
|
306 for(Session session : list){
|
|
307 session.getEditorList().get(0).setChannel(channel);
|
|
308 sessionList.add(session);
|
|
309 }
|
|
310
|
|
311 //他のSessionManagerへ中継する
|
99
|
312 smList.sendExcept(channel, receivedCommand);
|
144
|
313
|
200
|
314 //リストのコピーをGUIに渡す
|
|
315 LinkedList<Session> sList = new LinkedList<Session>(sessionList);
|
|
316 LinkedList<Editor> eList = new LinkedList<Editor>(editorList);
|
|
317 //GUIに反映
|
|
318 Runnable doRun = new DoGUIUpdate(sList, eList, gui);
|
|
319 SwingUtilities.invokeLater(doRun);
|
|
320 }
|
9
|
321 break;
|
144
|
322
|
9
|
323 case REP.SMCMD_UPDATE_ACK:
|
200
|
324 {
|
164
|
325 if(receivedCommand.sid > sessionList.size()){
|
148
|
326 Editor editor = new Editor(channel);
|
75
|
327 editor.setName(receivedCommand.string);
|
144
|
328
|
158
|
329 Session session = new Session(editor);
|
73
|
330 session.addEditor(editor);
|
144
|
331
|
164
|
332 sessionList.add(session);
|
200
|
333
|
|
334 //リストのコピーをGUIに渡す
|
|
335 LinkedList<Session> sList = new LinkedList<Session>(sessionList);
|
|
336 LinkedList<Editor> eList = new LinkedList<Editor>(editorList);
|
|
337 //GUIに反映
|
|
338 Runnable doRun = new DoGUIUpdate(sList, eList, gui);
|
|
339 SwingUtilities.invokeLater(doRun);
|
73
|
340 }
|
75
|
341 smList.sendToSlave(receivedCommand);
|
200
|
342 }
|
1
|
343 break;
|
144
|
344
|
95
|
345 case REP.SMCMD_CH_MASTER:
|
200
|
346 {
|
122
|
347 //maxHost を設定。
|
95
|
348 if(setMaxHost(channel, receivedCommand.string)){
|
|
349 sendCommand = new REPCommand();
|
|
350 sendCommand.setCMD(REP.SMCMD_CH_MASTER);
|
|
351 sendCommand.setString(maxHost);
|
|
352 smList.sendExcept(channel, sendCommand);
|
|
353 }
|
200
|
354 }
|
95
|
355 break;
|
144
|
356
|
213
|
357 case REP.REPCMD_DELETE:
|
|
358 case REP.REPCMD_INSERT:
|
164
|
359 {
|
144
|
360 //sid から Session を取得
|
158
|
361 Session session = getSession(receivedCommand.sid);
|
144
|
362 //マージの処理と次のエディタへコマンドを送信する処理
|
|
363 session.translate(channel, receivedCommand);
|
164
|
364
|
178
|
365
|
167
|
366 Editor editor = session.getEditor(channel);
|
|
367 Editor prevEditor = session.getPrevEditor(editor);
|
|
368
|
201
|
369 //マージ中のエディタはコマンドを受け取らない
|
164
|
370 if(editor.isMerging()){
|
|
371 //Handlerを切り替える
|
167
|
372 setMergeState(prevEditor.getChannel(), session.getSID());
|
169
|
373 }else {
|
178
|
374 setNormalState(prevEditor.getChannel(), session.getSID());
|
164
|
375 }
|
|
376 }
|
144
|
377 break;
|
213
|
378
|
|
379 default:
|
|
380 assert(false);
|
|
381 break;
|
|
382
|
144
|
383 }
|
|
384 }
|
|
385
|
212
|
386 private void guiUpdate() {
|
|
387 //リストのコピーをGUIに渡す
|
|
388 LinkedList<Session> sList = new LinkedList<Session>(sessionList);
|
|
389 LinkedList<Editor> eList = new LinkedList<Editor>(editorList);
|
|
390 //GUIに反映
|
|
391 Runnable doRun = new DoGUIUpdate(sList, eList, gui);
|
|
392 SwingUtilities.invokeLater(doRun);
|
|
393 }
|
|
394
|
169
|
395 private void setNormalState(REPSocketChannel<REPCommand> channel, int sid) {
|
|
396 SelectionKey key = channel.keyFor(selector);
|
|
397 key.attach(new REPHandlerImpl(sid, this));
|
|
398 }
|
|
399
|
167
|
400 private void setMergeState(REPSocketChannel<REPCommand> channel, int sid) {
|
|
401 SelectionKey key = channel.keyFor(selector);
|
|
402 key.attach(new REPHandlerInMerge(sid, this));
|
164
|
403 }
|
|
404
|
160
|
405 private Editor getEditor(String hostport) {
|
178
|
406 for(Editor editor : editorList){
|
|
407 if(editor.getHost() == hostport){
|
|
408 return editor;
|
|
409 }
|
|
410 }
|
|
411 return null;
|
|
412 }
|
|
413
|
|
414 public Editor getEditor(REPSocketChannel channel){
|
|
415 for(Editor editor : editorList){
|
|
416 if(editor.getChannel() == channel){
|
|
417 return editor;
|
|
418 }
|
|
419 }
|
160
|
420 return null;
|
|
421 }
|
|
422
|
144
|
423 private Session getSession(int sid) {
|
|
424 for(Session session : sessionList){
|
|
425 if(session.getSID() == sid) return session;
|
|
426 }
|
|
427 return null;
|
0
|
428 }
|
83
|
429
|
139
|
430 private boolean setMaxHost(REPSocketChannel channel, String maxHost2) {
|
179
|
431 if(maxHost.compareTo(maxHost2) > 0){
|
|
432 return false;
|
|
433 }else{
|
|
434 maxHost = maxHost2;
|
|
435 return true;
|
|
436 }
|
139
|
437 }
|
|
438
|
76
|
439 private void setMyHostName(String localHostName) {
|
95
|
440 myHost = localHostName + temp_port;
|
81
|
441 if(maxHost == null) {
|
|
442 maxHost = myHost;
|
|
443 }
|
164
|
444 setHostToEditor(myHost);
|
|
445 }
|
|
446
|
|
447 private void setHostToEditor(String myHost2) {
|
|
448 for(Editor editor : editorList){
|
|
449 editor.setHost(myHost2);
|
|
450 }
|
76
|
451 }
|
0
|
452
|
|
453 public static void main(String[] args) throws InterruptedException, IOException {
|
191
|
454
|
101
|
455 int port = DEFAULT_PORT;
|
|
456 int port_s = DEFAULT_PORT;
|
113
|
457 //System.setProperty("file.encoding", "UTF-8");
|
82
|
458 if(args.length > 0){
|
39
|
459 port = Integer.parseInt(args[0]);
|
95
|
460 port_s = Integer.parseInt(args[1]);
|
0
|
461 }
|
95
|
462 temp_port = port;
|
|
463 send_port = port_s;
|
0
|
464 SessionManager sm = new SessionManager(port);
|
2
|
465 sm.openSelector();
|
155
|
466 sm.init(port);
|
191
|
467 sm.startGUI(sm);
|
155
|
468 sm.mainLoop();
|
191
|
469
|
0
|
470 }
|
|
471
|
191
|
472 private void startGUI(SessionManager sm) {
|
|
473 gui = new SessionManagerGUI(this);
|
83
|
474 Thread th = new Thread( gui );
|
2
|
475 th.start();
|
|
476 }
|
|
477
|
178
|
478 public void connectSession(String host) {
|
101
|
479 int port = DEFAULT_PORT;
|
95
|
480 port = send_port;
|
1
|
481 InetSocketAddress addr = new InetSocketAddress(host, port);
|
|
482 try {
|
186
|
483 REPSocketChannel<REPCommand> sessionchannel = REPSocketChannel.<REPCommand>create(new REPCommandPacker());
|
1
|
484 sessionchannel.configureBlocking(true);
|
|
485 sessionchannel.connect(addr);
|
6
|
486 while(!sessionchannel.finishConnect()){
|
77
|
487 System.out.print("test afro");
|
6
|
488 }
|
|
489 System.out.println("");
|
2
|
490 registerChannel(selector, sessionchannel, SelectionKey.OP_READ);
|
45
|
491
|
77
|
492 sm_join(sessionchannel);
|
45
|
493
|
1
|
494 }catch (IOException e) {
|
|
495 e.printStackTrace();
|
|
496 }
|
|
497 }
|
77
|
498
|
164
|
499 private void sm_join(REPSocketChannel<REPCommand> channel){
|
79
|
500
|
122
|
501 //SM_JOINコマンドを生成。
|
77
|
502 REPCommand command = new REPCommand();
|
|
503 command.setCMD(REP.SMCMD_SM_JOIN);
|
79
|
504
|
122
|
505 //hostnameをセット。
|
82
|
506 setMyHostName(getLocalHostName(channel));
|
|
507
|
122
|
508 //XMLを生成。送信コマンドにセット。
|
164
|
509 SessionXMLEncoder encoder = new SessionXMLEncoder(sessionList);
|
77
|
510 String string = encoder.sessionListToXML();
|
|
511 command.setString(string);
|
|
512
|
122
|
513 //SM_JOINコマンドを送信。
|
186
|
514 channel.write(command);
|
122
|
515 //SessionManagerのListに追加。
|
77
|
516 smList.add(channel);
|
|
517 }
|
2
|
518
|
139
|
519 private String getLocalHostName(REPSocketChannel channel) {
|
74
|
520 String host = null;
|
|
521 host = channel.socket().getLocalAddress().getHostName();
|
|
522 return host;
|
|
523 }
|
|
524
|
2
|
525 public void connectionOccured(ConnectionEvent event) {
|
178
|
526 try {
|
|
527 waitingQueue.put(event);
|
|
528 } catch (InterruptedException e) {
|
|
529 }
|
|
530 selector.wakeup();
|
2
|
531 }
|
8
|
532
|
213
|
533 public void selectOccured(REPActionEvent event) {
|
212
|
534 try {
|
|
535 waitingQueue.put(event);
|
|
536 } catch (InterruptedException e) {
|
|
537 e.printStackTrace();
|
|
538 }
|
213
|
539 selector.wakeup();
|
212
|
540 }
|
|
541
|
|
542 public void selectSession(REPActionEvent event) {
|
163
|
543 REPSocketChannel<REPCommand> channel = event.getEditorChannel();
|
107
|
544 int sid = event.getSID();
|
164
|
545 Session session = getSession(sid);
|
213
|
546 selector.wakeup();
|
158
|
547 if(session.hasOwner()){
|
148
|
548 Editor editor = new Editor(channel);
|
|
549 session.addEditor(new Editor(channel));
|
107
|
550 REPCommand sendCommand = new REPCommand();
|
|
551 sendCommand.setCMD(REP.SMCMD_JOIN_ACK);
|
148
|
552 sendCommand.setEID(editor.getEID());
|
107
|
553 sendCommand.setSID(sid);
|
186
|
554 channel.write(sendCommand);
|
107
|
555 }else {
|
164
|
556 REPSocketChannel<REPCommand> editorChannel = event.getEditorChannel();
|
107
|
557 sid = event.getSID();
|
|
558 Editor editor = new Editor(editorChannel);
|
|
559 editor.setHost(myHost);
|
164
|
560 session = getSession(sid);
|
107
|
561 session.addEditor(editor);
|
|
562
|
158
|
563 Editor owner = session.getOwner();
|
107
|
564
|
|
565 REPCommand command = new REPCommand();
|
|
566 command.setCMD(REP.SMCMD_SELECT);
|
|
567 command.setSID(sid);
|
178
|
568 command.setString(editor.getHost());
|
107
|
569 owner.send(command);
|
|
570 }
|
8
|
571 }
|
122
|
572
|
144
|
573 public void addWaitingCommand(PacketSet set) {
|
212
|
574 waitingCommandInMerge.add(set);
|
144
|
575 }
|
148
|
576
|
185
|
577 public List<Session> getSessionList() {
|
|
578 // TODO Auto-generated method stub
|
|
579 return sessionList;
|
|
580 }
|
|
581
|
|
582 public List<Editor> getEditorList() {
|
|
583 // TODO Auto-generated method stub
|
|
584 return editorList;
|
|
585 }
|
|
586
|
0
|
587 }
|