Mercurial > hg > RemoteEditor > REPSessionManager
comparison rep/SessionManager.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 |
comparison
equal
deleted
inserted
replaced
358:034acadc0cdc | 359:fa041bae35f1 |
---|---|
341 private void selectSession(int sid, Session session, int eid, Forwarder editor) { | 341 private void selectSession(int sid, Session session, int eid, Forwarder editor) { |
342 if(session.hasOwner()){ | 342 if(session.hasOwner()){ |
343 session.addForwarder(editor); | 343 session.addForwarder(editor); |
344 REPCommand sendCommand = new REPCommand(); | 344 REPCommand sendCommand = new REPCommand(); |
345 if (editor.isDirect()&&editor.getEID()==eid) { | 345 if (editor.isDirect()&&editor.getEID()==eid) { |
346 sendUpdate(); | 346 sendUpdate(session.getSID()); |
347 sendCommand.setCMD(REP.SMCMD_JOIN_ACK); | 347 sendCommand.setCMD(REP.SMCMD_JOIN_ACK); |
348 } else { | 348 } else { |
349 // SELECT_ACK is sent to the session ring to | 349 // SELECT_ACK is sent to the session ring to |
350 // find out joined editor | 350 // find out joined editor |
351 sendCommand.setCMD(REP.SMCMD_SELECT_ACK); | 351 sendCommand.setCMD(REP.SMCMD_SELECT_ACK); |
367 command.setString(editor.getHost()); | 367 command.setString(editor.getHost()); |
368 next.send(command); | 368 next.send(command); |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 private void sendUpdate() { | 372 private void sendUpdate(int sid) { |
373 // TODO Auto-generated method stub | 373 REPCommand command = makeREPCommandWithSessionList(REP.SMCMD_UPDATE); |
374 | 374 command.setSID(sid); |
375 } | 375 command.setEID(REP.SM_EID.id); |
376 | 376 smList.sendToMaster(command); |
377 } | |
378 | |
379 public Editor newEditor(REPSocketChannel<REPCommand> channel) { | |
380 int eid = makeID(editorList.newEid()); | |
381 Editor editor = new Editor(this, eid, channel); | |
382 editorList.add(editor); | |
383 return editor; | |
384 } | |
385 | |
386 | |
387 public Session newSession(Forwarder master) { | |
388 int sid= makeID(sessionList.newSessionID()); | |
389 Session session = new Session(sid, master); | |
390 return session; | |
391 } | |
377 | 392 |
378 public void addWaitingCommand(PacketSet set) { | 393 public void addWaitingCommand(PacketSet set) { |
379 waitingCommandInMerge.add(set); | 394 waitingCommandInMerge.add(set); |
380 } | 395 } |
381 | 396 |
430 } | 445 } |
431 | 446 |
432 private void removeSession(Session s0) { | 447 private void removeSession(Session s0) { |
433 s0.remove(this); | 448 s0.remove(this); |
434 sessionList.remove(s0); | 449 sessionList.remove(s0); |
435 sendUpdate(); | 450 sendUpdate(s0.getSID()); |
436 } | 451 } |
437 | 452 |
438 public void setParentPort(int port) { | 453 public void setParentPort(int port) { |
439 parent_port = port; | 454 parent_port = port; |
440 } | 455 } |
454 // Session Manager Command | 469 // Session Manager Command |
455 | 470 |
456 case SMCMD_JOIN: | 471 case SMCMD_JOIN: |
457 { | 472 { |
458 // first connection or forwarded command | 473 // first connection or forwarded command |
459 if (forwarder.isDirect()) { | |
460 // direct linked editor なので、ここでIDを作成する | |
461 command.setEID(makeID(editorList.newEid())); | |
462 } | |
463 if(isMaster()) { | 474 if(isMaster()) { |
464 REPCommand ackCommand = new REPCommand(); | 475 REPCommand ackCommand = new REPCommand(); |
465 ackCommand.setCMD(REP.SMCMD_JOIN_ACK); | 476 ackCommand.setCMD(REP.SMCMD_JOIN_ACK); |
466 ackCommand.setEID(command.eid); | 477 ackCommand.setEID(command.eid); |
467 ackCommand.string = command.string; | 478 ackCommand.string = command.string; |
482 break; | 493 break; |
483 | 494 |
484 case SMCMD_PUT: | 495 case SMCMD_PUT: |
485 { | 496 { |
486 // first connection or forwarded command | 497 // first connection or forwarded command |
487 if (forwarder.isDirect()) { | |
488 // direct link, make new ID | |
489 int eid = makeID(editorList.newEid()); | |
490 int sid = makeID(sessionList.newSessionID()); | |
491 command.setEID(eid); | |
492 command.setSID(sid); | |
493 } | |
494 if(isMaster()) { | 498 if(isMaster()) { |
495 command.setCMD(REP.SMCMD_PUT_ACK); | 499 command.setCMD(REP.SMCMD_PUT_ACK); |
496 command.string = command.string; | 500 command.string = command.string; |
497 command.setEID(command.eid); | 501 command.setEID(command.eid); |
498 command.setSID(command.sid); | 502 command.setSID(command.sid); |
557 case SMCMD_SM_JOIN_ACK: | 561 case SMCMD_SM_JOIN_ACK: |
558 send_sm_join_ack(command.eid, command.sid, command); | 562 send_sm_join_ack(command.eid, command.sid, command); |
559 break; | 563 break; |
560 | 564 |
561 case SMCMD_UPDATE: | 565 case SMCMD_UPDATE: |
562 command.setString(mergeUpdate(command)); | 566 if (!isMaster()) { |
563 // 上に知らせる | 567 command.setString(mergeUpdate(command)); |
564 smList.sendToMaster(command); | 568 // 上に知らせる |
565 break; | 569 smList.sendToMaster(command); |
566 | 570 break; |
571 } | |
572 // fall thru | |
573 command.setCMD(REP.SMCMD_UPDATE_ACK); | |
567 case SMCMD_UPDATE_ACK: | 574 case SMCMD_UPDATE_ACK: |
568 command.setString(mergeUpdate(command)); | 575 command.setString(mergeUpdate(command)); |
569 // 下に知らせる | 576 // 下に知らせる |
570 smList.sendToSlaves(command); | 577 smList.sendToSlaves(command); |
571 updateGUI(); | 578 updateGUI(); |