changeset 369:7d21eb209e27

*** empty log message ***
author kono
date Tue, 21 Oct 2008 20:37:05 +0900
parents 335f685ac658
children 46c95d8885ad
files rep/RoutingTable.java rep/SessionManager.java
diffstat 2 files changed, 30 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/rep/RoutingTable.java	Tue Oct 21 20:11:09 2008 +0900
+++ b/rep/RoutingTable.java	Tue Oct 21 20:37:05 2008 +0900
@@ -6,9 +6,14 @@
 public class RoutingTable {
 
 	HashMap<Integer,Forwarder> sessionManagers =new HashMap<Integer,Forwarder>();
+	SessionManager manager;
 	// we don't need this, but we keep it because it is easy.
 	// editor can be reached using this routing table.
 
+	public RoutingTable(SessionManager sessionManager) {
+		manager = sessionManager;
+	}
+
 	public void add(Forwarder forwarder, int smid) {
 		if (smid>0) sessionManagers.put(smid, forwarder)	;
 	}
@@ -24,7 +29,9 @@
 	}
 
 	public Forwarder toSessionManager(int eid) {
-		return sessionManagers.get(eid);
+		Forwarder next = sessionManagers.get(eid);
+		if (next==null) return manager.smList.parent();
+		return next;
 	}
 
 }
--- a/rep/SessionManager.java	Tue Oct 21 20:11:09 2008 +0900
+++ b/rep/SessionManager.java	Tue Oct 21 20:37:05 2008 +0900
@@ -77,7 +77,7 @@
 	// SocketChannel for our parent. At most one parent is allowed.
 	private Forwarder sm_join_channel;
 	// Routing table for session and session manager.
-	private RoutingTable routingTable = new RoutingTable();
+	private RoutingTable routingTable = new RoutingTable(this);
 	private SessionManagerEvent execAfterConnect = null;;
 
 	public static void main(String[] args) throws InterruptedException, IOException {
@@ -421,27 +421,29 @@
 				f.setHost(myHost);
 				f.setSID(sid);
 				session.addForwarder(f); // f.next is set up here.
+				sendCommand.setSID(sid);
+				sendCommand.string = session.getName();
+				sendCommand.setEID(eid);
+				editor.send(sendCommand);
+				return;
 			}
-			sendCommand.setEID(editor.getEID());
-			sendCommand.setSID(sid);
-			sendCommand.string = session.getName();
-			editor.send(sendCommand);
 		}else {
 			Forwarder next;
 			if (editor.channel==null) {
+				// we don't have this editor, search the editor first.
 				next = routingTable.toSessionManager(getSMID(eid));
 			} else {
 				// session searching continue...
 				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.setChannel(next.channel); // incoming channel
 				f.setNext(f);
 				f.setHost(myHost);
 				f.setSID(sid);
 				session.setFirstForwarder(f);
+				session.addForwarder(editor);
 			}
-			if (next==null) next = smList.parent() ;
 			// pass the select command to the next path.
 			REPCommand command = new REPCommand();
 			command.setCMD(REP.SMCMD_SELECT);
@@ -643,9 +645,20 @@
 			break;
 		case SMCMD_SELECT_ACK:
 		{
+			// Sessionが見つかったので、select したeditorに教える。
 			Session session = sessionList.get(command.sid);
-			selectSession(command.sid, session, command.eid, 
-					session.getFirstForwarder());
+			Forwarder next = session.getNextEditor(forwarder);
+			if (next==null) next = session.getFirstForwarder();
+			if (next.getEID()==command.eid) {
+				// select したeditor を見つける
+				command.cmd=REP.SMCMD_JOIN_ACK;
+				next.send(command);
+			} else if (next.isDirect()) {
+				// 
+				next.manage(command);
+			} else {
+				next.send(command);
+			}
 		}
 			break;