changeset 95:2462a5d11396

add hostname+port add CH_MASTER
author chiaki
date Sat, 22 Dec 2007 00:30:14 +0900
parents 2830eb33d4d3
children f0bc200d963d
files rep/SessionManager.java
diffstat 1 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/rep/SessionManager.java	Fri Dec 21 19:13:44 2007 +0900
+++ b/rep/SessionManager.java	Sat Dec 22 00:30:14 2007 +0900
@@ -42,6 +42,8 @@
 	//private boolean addressIsGlobal;
 	//private SocketChannel sessionchannel;
 	//private boolean co;
+	private static int temp_port;
+	private static int send_port;
 	public SessionManager(int port) {
 		gui = new SessionManagerGUI();
 	}
@@ -242,7 +244,12 @@
 			if(myHost == null) setMyHostName(getLocalHostName(channel));
 			
 			//maxHost を設定。
-			setMaxHost(channel, receivedSessionList.getMaxHost());
+			if(setMaxHost(channel, receivedSessionList.getMaxHost())){
+				sendCommand = new REPCommand();
+				sendCommand.setCMD(REP.SMCMD_CH_MASTER);
+				sendCommand.setString(maxHost);
+				smList.sendExcept(channel, sendCommand);
+			}
 			
 			//SessionListからXMLを生成。
 			//joinしてきたSessionManagerに対してACKを送信。
@@ -277,7 +284,12 @@
 			SessionList receivedSessionList2 = decoder2.decode(receivedCommand.string);
 			
 			//maxHostを決定。
-			setMaxHost(channel, receivedSessionList2.getMaxHost());
+			if(setMaxHost(channel, receivedSessionList2.getMaxHost())){
+				sendCommand = new REPCommand();
+				sendCommand.setCMD(REP.SMCMD_CH_MASTER);
+				sendCommand.setString(maxHost);
+				smList.sendExcept(channel, sendCommand);
+			}
 			
 			if(isMaster){
 			}else{
@@ -326,6 +338,16 @@
 			//sessionlist.sendCmd(channel, repCmd);
 			break;
 			
+		case REP.SMCMD_CH_MASTER:
+			//maxHost を設定。
+			if(setMaxHost(channel, receivedCommand.string)){
+				sendCommand = new REPCommand();
+				sendCommand.setCMD(REP.SMCMD_CH_MASTER);
+				sendCommand.setString(maxHost);
+				smList.sendExcept(channel, sendCommand);
+			}
+			break;
+			
 		default:
 			//sessionlist.sendCmd(channel, repCmd);
 			sessionlist.sendToNextEditor(channel, receivedCommand);
@@ -351,7 +373,7 @@
 	}
 
 	private void setMyHostName(String localHostName) {
-		myHost = localHostName;
+		myHost = localHostName + temp_port;
 		if(maxHost == null) {
 			maxHost = myHost;
 			sessionlist.setMaxHost(maxHost);
@@ -367,10 +389,14 @@
 
 	public static void main(String[] args) throws InterruptedException, IOException {
 		int port = 8766;
+		int port_s = 8765;
 		
 		if(args.length > 0){
 			port = Integer.parseInt(args[0]);
+			port_s = Integer.parseInt(args[1]);
 		}
+		temp_port = port;
+		send_port = port_s;
 		SessionManager sm = new SessionManager(port);
 		sm.openSelector();
 		sm.openWindow();
@@ -387,6 +413,7 @@
 
 	private void connectSession(String host) {
 		int port = 8766;
+		port = send_port;
 		InetSocketAddress addr = new InetSocketAddress(host, port);
 		try {
 			SocketChannel sessionchannel = SocketChannel.open();