changeset 378:c78569ab5fce

*** empty log message ***
author kono
date Wed, 22 Oct 2008 04:27:52 +0900
parents 85a5980d96d8
children fa8ca18f74d2
files rep/ConnectButtonEvent.java rep/Editor.java rep/Forwarder.java rep/SessionManager.java test/sematest/TestInterManagerSession.java
diffstat 5 files changed, 39 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/rep/ConnectButtonEvent.java	Wed Oct 22 04:07:24 2008 +0900
+++ b/rep/ConnectButtonEvent.java	Wed Oct 22 04:27:52 2008 +0900
@@ -13,7 +13,7 @@
 	}
 
 	public void exec(SessionManager manager) {
-		manager.connectSession(host);
+		manager.connectSessionManager(host);
 	}
 
 }
--- a/rep/Editor.java	Wed Oct 22 04:07:24 2008 +0900
+++ b/rep/Editor.java	Wed Oct 22 04:27:52 2008 +0900
@@ -219,4 +219,28 @@
 	public boolean isMaster() {
 		return mode==REP.SMCMD_PUT;
 	}
+	
+	/* Handle special case first, usually these cases
+	 * are handled in the next Editor in a session manager, but 
+	 * it is forwarded here.
+	 */
+	public void forwardedCommandManage(REPCommand command, Forwarder forwarder) {
+		if (command.cmd==REP.SMCMD_QUIT_2) {
+			// we have to wait next editor's finishing before sending this.
+			// this is odd, but the editor itself does not know it's merging
+			// state. Only this session manager knows it.
+			setQuit2(command);
+		} else if (command.eid==eid) {
+			// if we handle in editor.manage(), this editor cannot distinguish this
+			// and user input command from the editor.
+			switch(command.cmd) {
+			case REPCMD_DELETE:
+			case REPCMD_INSERT:
+			case REPCMD_NOP:
+				checkReturnedCommand(command);
+				return;
+			}
+		} 
+		manage(command);
+	}
 }
--- a/rep/Forwarder.java	Wed Oct 22 04:07:24 2008 +0900
+++ b/rep/Forwarder.java	Wed Oct 22 04:27:52 2008 +0900
@@ -86,29 +86,18 @@
 			REPCommand command) throws IOException {
 		Session s = manager.getSession(command.sid);
 		if (s==null) throw new IOException();
-		Forwarder editor = s.getForwarder(channel);
-		if (editor==null) throw new IOException();
-		if (!editor.isDirect()) {
-			editor.send(command); 
+		Forwarder f = s.getForwarder(channel);
+		if (f==null) throw new IOException();
+		if (!f.isDirect()) {
+			// another forwarder, pass it to the next session manager
+			f.send(command); 
 			return;
 		}
 		/*
-		 * local editor case. Handle special case first, usually these cases
-		 * are handled in the next Editor in a session manager, but 
-		 * it is forwarded here.
+		 * local editor case. 
 		 */
-		if (command.cmd==REP.SMCMD_QUIT_2) {
-			// we have to wait next editor's finishing before sending this.
-			// this is odd, but the editor itself does not know it's merging
-			// state. Only this session manager knows it.
-			editor.setQuit2(command);
-		} else if (command.eid==editor.eid) {
-			// if we handle in editor.manage(), this editor cannot distinguish this
-			// and user input command from the editor.
-			((Editor)editor).checkReturnedCommand(command);
-		} else {
-			editor.manage(command);
-		}
+		Editor editor = (Editor)f;
+		editor.forwardedCommandManage(command, this);
 	}
 
 	public void setMode(REP cmd) {
--- a/rep/SessionManager.java	Wed Oct 22 04:07:24 2008 +0900
+++ b/rep/SessionManager.java	Wed Oct 22 04:27:52 2008 +0900
@@ -331,7 +331,7 @@
 	 * ならない。複数のSession Managerにjoinすることは出来ない。(NATを実装するまでは)。
 	 * @param host
 	 */
-	public void connectSession(String host, int port) {
+	public void connectSessionManager(String host, int port) {
 		if (sm_join_channel!=null) return;
 		if (!sessionList.isEmpty()) return;
 		if (!smList.isMaster()) return;
@@ -351,8 +351,8 @@
 		}
 	}
 
-	public void connectSession(String host) {
-		connectSession(host,parent_port);
+	public void connectSessionManager(String host) {
+		connectSessionManager(host,parent_port);
 	}
 	
 	/**
--- a/test/sematest/TestInterManagerSession.java	Wed Oct 22 04:07:24 2008 +0900
+++ b/test/sematest/TestInterManagerSession.java	Wed Oct 22 04:27:52 2008 +0900
@@ -40,17 +40,17 @@
 			},
 			new SessionManagerEvent() {
 				public void exec(SessionManager manager) {	
-					manager.connectSession(host);
+					manager.connectSessionManager(host);
 				}
 			},
 			new SessionManagerEvent() {
 				public void exec(SessionManager manager) {
 					// try to make a loop
 					if (false) {
-					sessionManagers[0].connectSession(host,
+					sessionManagers[0].connectSessionManager(host,
 							manager.getPort());
 					}
-					manager.connectSession(host);
+					manager.connectSessionManager(host);
 					manager.execAfterConnect(
 							new SessionManagerEvent() {
 								public void exec(SessionManager manager) {