comparison rep/SessionManager.java @ 367:1bde894edd83

*** empty log message ***
author kono
date Tue, 21 Oct 2008 18:46:04 +0900
parents e391433fa9f1
children 7d21eb209e27
comparison
equal deleted inserted replaced
366:e391433fa9f1 367:1bde894edd83
430 Forwarder next; 430 Forwarder next;
431 if (editor.channel==null) { 431 if (editor.channel==null) {
432 next = routingTable.toSessionManager(getSMID(eid)); 432 next = routingTable.toSessionManager(getSMID(eid));
433 } else { 433 } else {
434 // session searching continue... 434 // session searching continue...
435 next = routingTable.toSession(sid); 435 next = routingTable.toSessionManager(getSMID(sid));
436 // create dummy editor for this session 436 // create dummy editor for this session
437 Forwarder f = new Editor(this, false, makeID(editorList.newEid())); 437 Forwarder f = new Editor(this, false, makeID(editorList.newEid()));
438 f.setChannel(editor.channel); // incoming channel 438 f.setChannel(editor.channel); // incoming channel
439 f.setNext(next); 439 f.setNext(f);
440 f.setHost(myHost); 440 f.setHost(myHost);
441 f.setSID(sid); 441 f.setSID(sid);
442 session.setFirstForwarder(f); 442 session.setFirstForwarder(f);
443 } 443 }
444 if (next==null) next = smList.parent() ;
444 // pass the select command to the next path. 445 // pass the select command to the next path.
445 REPCommand command = new REPCommand(); 446 REPCommand command = new REPCommand();
446 command.setCMD(REP.SMCMD_SELECT); 447 command.setCMD(REP.SMCMD_SELECT);
447 command.setSID(sid); 448 command.setSID(sid);
448 command.setEID(eid); 449 command.setEID(eid);
577 // Session Manager Command 578 // Session Manager Command
578 579
579 case SMCMD_JOIN: 580 case SMCMD_JOIN:
580 { 581 {
581 // first connection or forwarded command 582 // first connection or forwarded command
583 routingTable.add(forwarder,getSMID(command.eid));
582 if(isMaster()) { 584 if(isMaster()) {
583 REPCommand ackCommand = new REPCommand(); 585 REPCommand ackCommand = new REPCommand();
584 ackCommand.setCMD(REP.SMCMD_JOIN_ACK); 586 ackCommand.setCMD(REP.SMCMD_JOIN_ACK);
585 ackCommand.setEID(command.eid); 587 ackCommand.setEID(command.eid);
586 ackCommand.setSID(command.sid); 588 ackCommand.setSID(command.sid);
587 ackCommand.string = command.string; 589 ackCommand.string = command.string;
588 smList.sendToSlaves(ackCommand); 590 smList.sendToSlaves(ackCommand);
589 registEditor(forwarder,ackCommand); 591 registEditor(forwarder,ackCommand);
590 } else { 592 } else {
591 routingTable.add(forwarder,getSMID(command.eid),command.sid);
592 smList.sendToMaster(command); 593 smList.sendToMaster(command);
593 } 594 }
594 updateGUI(); 595 updateGUI();
595 } 596 }
596 597
611 break; 612 break;
612 613
613 case SMCMD_PUT: 614 case SMCMD_PUT:
614 { 615 {
615 // first connection or forwarded command 616 // first connection or forwarded command
616 routingTable.add(forwarder,getSMID(command.eid),command.sid); 617 routingTable.add(forwarder,getSMID(command.eid));
617 if(isMaster()) { 618 if(isMaster()) {
618 command.setCMD(REP.SMCMD_PUT_ACK); 619 command.setCMD(REP.SMCMD_PUT_ACK);
619 command.string = command.string; 620 command.string = command.string;
620 command.setEID(command.eid); 621 command.setEID(command.eid);
621 command.setSID(command.sid); 622 command.setSID(command.sid);
666 // channel を持たないForwarderとして登録する 667 // channel を持たないForwarderとして登録する
667 sm = new Forwarder(this); 668 sm = new Forwarder(this);
668 } else { 669 } else {
669 sm = forwarder; 670 sm = forwarder;
670 } 671 }
671 int sid = smList.addNewSessionManager(sm,command); 672 int sid = smList.addNewSessionManager(sm,command);
673 routingTable.add(forwarder,sid);
674
672 REPCommand sendCommand = makeREPCommandWithSessionList(REP.SMCMD_SM_JOIN_ACK); 675 REPCommand sendCommand = makeREPCommandWithSessionList(REP.SMCMD_SM_JOIN_ACK);
673 // command.eid==smList.sesionManagerID() の場合は、 676 // command.eid==smList.sesionManagerID() の場合は、
674 // 待っている自分の下のsessionManagerにsidをassignする必要がある。 677 // 待っている自分の下のsessionManagerにsidをassignする必要がある。
675 sendCommand.setSID(sid); // new Session manager ID 678 sendCommand.setSID(sid); // new Session manager ID
676 // 複数のSM_JOIN_ACKを識別するには、最初にSM_JOINを受け付けた 679 // 複数のSM_JOIN_ACKを識別するには、最初にSM_JOINを受け付けた
749 /** 752 /**
750 * Register Editor to our editorList. No connection is made. 753 * Register Editor to our editorList. No connection is made.
751 * @param forwarder Editor to be add 754 * @param forwarder Editor to be add
752 * @param command 755 * @param command
753 */ 756 */
754 private void registEditor(Forwarder forwarder,REPCommand command) { 757 public void registEditor(Forwarder forwarder,REPCommand command) {
755 // make ack for PUT/JOIN. Do not send this to the editor, 758 // make ack for PUT/JOIN. Do not send this to the editor,
756 // before select. After select, ack is sent to the editor. 759 // before select. After select, ack is sent to the editor.
757 routingTable.add(forwarder,getSMID(command.eid),command.sid);
758 Editor editor; 760 Editor editor;
759 if (getSMID(command.sid)==smList.sessionManagerID() 761 if (getSMID(command.eid)==smList.sessionManagerID()) {
760 && forwarder.isDirect()) { 762 if (forwarder.isDirect()) {
761 // direct link だった 763 editor = (Editor)forwarder;
762 editor = (Editor)forwarder; 764 } else
765 return;
763 } else { 766 } else {
764 editor = new Editor(this, command.cmd==REP.SMCMD_PUT_ACK, command.eid); 767 editor = new Editor(this, command.cmd==REP.SMCMD_PUT_ACK, command.eid);
765 } 768 }
766 editor.setName(command.string); 769 editor.setName(command.string);
767 editor.setSID(command.sid); 770 editor.setSID(command.sid);
768 if (!editorList.hasEid(command.eid)) { 771 if (!editorList.hasEid(command.eid)) {
769 editorList.add(editor); 772 editorList.add(editor);
773 }
774 if (command.cmd==REP.SMCMD_PUT_ACK) {
775 Session session = new Session(command.sid, command.string, editor);
776 sessionList.put(command.sid, session);
770 } 777 }
771 // we don't join ack to the direct linked editor. We 778 // we don't join ack to the direct linked editor. We
772 // have to wait select command 779 // have to wait select command
773 } 780 }
774 781
818 } 825 }
819 826
820 public void setParent(Forwarder fw) { 827 public void setParent(Forwarder fw) {
821 smList.setParent(fw); 828 smList.setParent(fw);
822 } 829 }
830
831 public String toString() {
832 int myId = 0;
833 if (smList!=null) myId = smList.sessionManagerID();
834 return "rep.SessionManager-"+myId+"@"+myHost+":"+receive_port;
835 }
823 836
824 837
825 } 838 }