# HG changeset patch # User kono # Date 1224582364 -32400 # Node ID 1bde894edd831918f5ef059a852997749ac2d24c # Parent e391433fa9f170750e1122db5f3e534aad245bcb *** empty log message *** diff -r e391433fa9f1 -r 1bde894edd83 rep/FirstConnector.java --- a/rep/FirstConnector.java Mon Oct 20 17:58:02 2008 +0900 +++ b/rep/FirstConnector.java Tue Oct 21 18:46:04 2008 +0900 @@ -72,8 +72,8 @@ //myHost を設定。 //立ち上げ時にやるとlocalhostしか取れない if(manager.myHost == null) manager.setMyHostName(getLocalHostName()); + fw.setMode(command.cmd); fw.setHost(manager.myHost); - fw.setMode(command.cmd); manager.registerChannel(channel, fw); manager.sessionManage(fw, command); diff -r e391433fa9f1 -r 1bde894edd83 rep/RoutingTable.java --- a/rep/RoutingTable.java Mon Oct 20 17:58:02 2008 +0900 +++ b/rep/RoutingTable.java Tue Oct 21 18:46:04 2008 +0900 @@ -8,37 +8,21 @@ HashMap sessionManagers =new HashMap(); // we don't need this, but we keep it because it is easy. // editor can be reached using this routing table. - HashMap sessionTable =new HashMap(); - // session may have multiple forward, if so we have a session - // here. So we don't have to keep multiple session, just keep - // one. - public void add(Forwarder forwarder, int smid, int sid) { + public void add(Forwarder forwarder, int smid) { if (smid>0) sessionManagers.put(smid, forwarder) ; - if (sid>0) sessionTable.put(sid, forwarder) ; } public void remove(Forwarder f) { for(Entry entry:sessionManagers.entrySet()) { if (entry.getValue()==f) sessionManagers.remove(entry.getKey()); } - for(Entry entry:sessionTable.entrySet()) { - if (entry.getValue()==f) sessionTable.remove(entry.getKey()); - } - } - - public void removeSession(int sid) { - sessionTable.remove(sid); } public void removeManager(int smid) { sessionManagers.remove(smid); } - public Forwarder toSession(int sid) { - return sessionTable.get(sid); - } - public Forwarder toSessionManager(int eid) { return sessionManagers.get(eid); } diff -r e391433fa9f1 -r 1bde894edd83 rep/SessionManager.java --- a/rep/SessionManager.java Mon Oct 20 17:58:02 2008 +0900 +++ b/rep/SessionManager.java Tue Oct 21 18:46:04 2008 +0900 @@ -432,15 +432,16 @@ next = routingTable.toSessionManager(getSMID(eid)); } else { // session searching continue... - next = routingTable.toSession(sid); + next = routingTable.toSessionManager(getSMID(sid)); // create dummy editor for this session Forwarder f = new Editor(this, false, makeID(editorList.newEid())); f.setChannel(editor.channel); // incoming channel - f.setNext(next); + f.setNext(f); f.setHost(myHost); f.setSID(sid); session.setFirstForwarder(f); } + if (next==null) next = smList.parent() ; // pass the select command to the next path. REPCommand command = new REPCommand(); command.setCMD(REP.SMCMD_SELECT); @@ -579,6 +580,7 @@ case SMCMD_JOIN: { // first connection or forwarded command + routingTable.add(forwarder,getSMID(command.eid)); if(isMaster()) { REPCommand ackCommand = new REPCommand(); ackCommand.setCMD(REP.SMCMD_JOIN_ACK); @@ -588,7 +590,6 @@ smList.sendToSlaves(ackCommand); registEditor(forwarder,ackCommand); } else { - routingTable.add(forwarder,getSMID(command.eid),command.sid); smList.sendToMaster(command); } updateGUI(); @@ -613,7 +614,7 @@ case SMCMD_PUT: { // first connection or forwarded command - routingTable.add(forwarder,getSMID(command.eid),command.sid); + routingTable.add(forwarder,getSMID(command.eid)); if(isMaster()) { command.setCMD(REP.SMCMD_PUT_ACK); command.string = command.string; @@ -668,7 +669,9 @@ } else { sm = forwarder; } - int sid = smList.addNewSessionManager(sm,command); + int sid = smList.addNewSessionManager(sm,command); + routingTable.add(forwarder,sid); + REPCommand sendCommand = makeREPCommandWithSessionList(REP.SMCMD_SM_JOIN_ACK); // command.eid==smList.sesionManagerID() の場合は、 // 待っている自分の下のsessionManagerにsidをassignする必要がある。 @@ -751,15 +754,15 @@ * @param forwarder Editor to be add * @param command */ - private void registEditor(Forwarder forwarder,REPCommand command) { + public void registEditor(Forwarder forwarder,REPCommand command) { // make ack for PUT/JOIN. Do not send this to the editor, // before select. After select, ack is sent to the editor. - routingTable.add(forwarder,getSMID(command.eid),command.sid); Editor editor; - if (getSMID(command.sid)==smList.sessionManagerID() - && forwarder.isDirect()) { - // direct link だった - editor = (Editor)forwarder; + if (getSMID(command.eid)==smList.sessionManagerID()) { + if (forwarder.isDirect()) { + editor = (Editor)forwarder; + } else + return; } else { editor = new Editor(this, command.cmd==REP.SMCMD_PUT_ACK, command.eid); } @@ -768,6 +771,10 @@ if (!editorList.hasEid(command.eid)) { editorList.add(editor); } + if (command.cmd==REP.SMCMD_PUT_ACK) { + Session session = new Session(command.sid, command.string, editor); + sessionList.put(command.sid, session); + } // we don't join ack to the direct linked editor. We // have to wait select command } @@ -820,6 +827,12 @@ public void setParent(Forwarder fw) { smList.setParent(fw); } + + public String toString() { + int myId = 0; + if (smList!=null) myId = smList.sessionManagerID(); + return "rep.SessionManager-"+myId+"@"+myHost+":"+receive_port; + } } diff -r e391433fa9f1 -r 1bde894edd83 rep/SessionManagerList.java --- a/rep/SessionManagerList.java Mon Oct 20 17:58:02 2008 +0900 +++ b/rep/SessionManagerList.java Tue Oct 21 18:46:04 2008 +0900 @@ -70,6 +70,10 @@ public void setParent(Forwarder fw) { parent = fw; } + + public Forwarder parent() { + return parent; + } diff -r e391433fa9f1 -r 1bde894edd83 test/sematest/TestGUI.java --- a/test/sematest/TestGUI.java Mon Oct 20 17:58:02 2008 +0900 +++ b/test/sematest/TestGUI.java Tue Oct 21 18:46:04 2008 +0900 @@ -41,7 +41,7 @@ if (slist.size()==0) return; Session s = slist.get(count++ % slist.size()); for(Editor e :elist) { - if (!e.hasSession()) { + if (e.isDirect() && !e.hasSession()) { SessionManagerEvent event = new SelectButtonEvent(e, s); ns.writeLog("Select session "+s.getSID()+" and editor "+i); manager.buttonPressed(event);