Mercurial > hg > RemoteEditor > REPSessionManager
diff rep/SessionManager.java @ 78:8a4f92f31c58
*** empty log message ***
author | pin |
---|---|
date | Tue, 11 Dec 2007 11:55:23 +0900 |
parents | eb78312ea831 |
children | d1877cfd131d |
line wrap: on
line diff
--- a/rep/SessionManager.java Tue Dec 11 09:01:06 2007 +0900 +++ b/rep/SessionManager.java Tue Dec 11 11:55:23 2007 +0900 @@ -37,6 +37,7 @@ private String myHost; private boolean isMaster = true; private EditorList allEditorList; + private String maxHost; //private boolean addressIsGlobal; //private SocketChannel sessionchannel; //private boolean co; @@ -121,6 +122,8 @@ Editor editor; Session session; REPCommand sendCommand = receivedCommand.clone(); + REPPacketSend send = new REPPacketSend(channel); + //SessionXMLEncoder encoder = new SessionXMLEncoder(); switch(receivedCommand.cmd){ @@ -160,10 +163,10 @@ editor.send(receivedCommand); //if(isMaster){ - SessionXMLEncoder encoder = new SessionXMLEncoder(session); + SessionXMLEncoder sessionEncoder = new SessionXMLEncoder(session); REPCommand command = new REPCommand(); command.setSID(session.getSID()); - command.setString(encoder.sessionListToXML()); + command.setString(sessionEncoder.sessionListToXML()); if(isMaster){ command.setCMD(REP.SMCMD_UPDATE_ACK); smList.sendToSlave(command); @@ -183,7 +186,7 @@ if(session.isOwner()){ int eid = session.addEditor(editor); editor.setEID(eid); - REPPacketSend send = new REPPacketSend(channel); + //REPPacketSend send = new REPPacketSend(channel); receivedCommand.setCMD(REP.SMCMD_SELECT_ACK); receivedCommand.setEID(eid); send.send(receivedCommand); @@ -204,20 +207,39 @@ break; case REP.SMCMD_SM_JOIN: + + //XMLからSessionListオブジェクトを生成する。 SessionXMLDecoder decoder = new SessionXMLDecoder(); SessionList sl = decoder.decode(receivedCommand.string); + + //myHost を設定。 if(myHost == null) setMyHostName(getLocalHostName(channel)); + + //host の size を比較。myHost が小さければ自分はslaveになる。 + //maxHost を大きい方に変更する。 if(myHost.compareTo(sl.getHost()) < 0){ setMaster(false, channel); + setMaxHost(sl.getHost()); } + //SessionListからXMLを生成。 + //joinしてきたSessionManagerに対してACKを送信。 + SessionXMLEncoder sessionlistEncoder = new SessionXMLEncoder(sessionlist); + sendCommand = new REPCommand(); + sendCommand.setCMD(REP.SMCMD_SM_JOIN_ACK); + sendCommand.setString(sessionlistEncoder.sessionListToXML()); + send.send(sendCommand); + + //その他のSessionManagerに対してSMCMD_SM_JOINを送信。 + sendCommand = new REPCommand(); + sendCommand.setCMD(REP.SMCMD_SM_JOIN); + sendCommand.setString(receivedCommand.string); + smList.sendExcept(channel, sendCommand); + if(isMaster){ - smList.add(channel); - sendCommand.setCMD(REP.SMCMD_SM_JOIN_ACK); - smList.sendSessionList(sessionlist, sendCommand); }else { - } + break; case REP.SMCMD_SM_JOIN_ACK: @@ -277,6 +299,10 @@ } } + private void setMaxHost(String host) { + maxHost = host; + } + private void setMyHostName(String localHostName) { myHost = localHostName; sessionlist.setHost(myHost);