Mercurial > hg > RemoteEditor > REPSessionManager
diff rep/SessionManager.java @ 76:97ca5f5447cd
*** empty log message ***
author | pin |
---|---|
date | Tue, 04 Dec 2007 10:33:06 +0900 |
parents | a636b651dbce |
children | eb78312ea831 |
line wrap: on
line diff
--- a/rep/SessionManager.java Sun Nov 25 03:21:17 2007 +0900 +++ b/rep/SessionManager.java Tue Dec 04 10:33:06 2007 +0900 @@ -37,6 +37,7 @@ private String myHost; private boolean isMaster = true; private EditorList editorList; + //private boolean addressIsGlobal; //private SocketChannel sessionchannel; //private boolean co; public SessionManager(int port) { @@ -203,14 +204,15 @@ break; case REP.SMCMD_SM_JOIN: - myHost = getLocalHostName(channel); - if(myHost.compareTo(receivedCommand.string) < 0) + if(myHost == null) setMyHostName(getLocalHostName(channel)); + if(myHost.compareTo(receivedCommand.string) < 0){ setMaster(false); + } if(isMaster){ smList.add(channel); - receivedCommand.setCMD(REP.SMCMD_SM_JOIN_ACK); - smList.sendSessionList(sessionlist, receivedCommand); + sendCommand.setCMD(REP.SMCMD_SM_JOIN_ACK); + smList.sendSessionList(sessionlist, sendCommand); }else { } @@ -272,49 +274,21 @@ break; } } + + private void setMyHostName(String localHostName) { + myHost = localHostName; + editorList.setHost(myHost); + } // private void sendJoin(REPCommand repCmd) { // smList.sendJoin(repCmd); // } private void setMaster(boolean b) { - // TODO Auto-generated method stub isMaster = b; System.out.println("isMaster = " + b); } - private void sendSessionManagerJoinAck(SocketChannel channel, REPCommand repCmd) { - String socketstring = getSocketString(channel); - System.out.println(socketstring); - smList.add(channel); //SessionManagerのリストへ追加 - repCmd.setCMD(REP.SMCMD_SM_JOIN_ACK); - repCmd.setString(repCmd.string + ":" + socketstring); - REPPacketSend repSend4 = new REPPacketSend(channel); - repSend4.send(repCmd); //ACK - } - - private void sendJoinAck(REPCommand repCmd) { - - } - - private void sendJoinAck(SocketChannel channel, REPCommand repCmd) { - //int eid = sessionlist.getNumberOfEditor(); //eidを取得 - int eid = editorList.addEditor(channel, repCmd); - sessionmanagerGUI.setComboEditor(eid, channel); //ComboBoxにEditorを追加 - repCmd.setEID(eid); //eidを決定して、 - repCmd.setCMD(REP.SMCMD_JOIN_ACK); - repCmd.string = sessionlist.getSessionList(); //Session一覧を - - String string = getSocketString(channel); - StringTokenizer stn = new StringTokenizer(string, ":"); - String host = stn.nextToken(); - String port = stn.nextToken(); - repCmd.setString(repCmd.string + ":" + myHost + ":" + port); - - REPPacketSend repSend = new REPPacketSend(channel); //Editor側へ送信 - repSend.send(repCmd); - } - public static void main(String[] args) throws InterruptedException, IOException { int port = 8766;