changeset 158:5cc8cd48bded

*** empty log message ***
author pin
date Thu, 28 Aug 2008 16:36:18 +0900
parents f0d80a64aba0
children ecab03b50e08
files rep/Session.java rep/SessionList.java rep/SessionManager.java
diffstat 3 files changed, 50 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/rep/Session.java	Thu Aug 28 16:20:17 2008 +0900
+++ b/rep/Session.java	Thu Aug 28 16:36:18 2008 +0900
@@ -48,7 +48,7 @@
 	public int getSID() {
 		return sessionID;
 	}
-	public Editor getMaster() {
+	public Editor getOwner() {
 		return masterEditor;
 	}
 	public String getName() {
@@ -65,10 +65,10 @@
 	public void addToRoutingTable(Editor editor) {
 		routingTable.add(new REPNode(editor));
 	}
-	public boolean isOwner() {
+	public boolean hasOwner() {
 		return isOwner;
 	}
-	public void setOwner(boolean b) {
+	public void hasOwner(boolean b) {
 		isOwner = true;
 	}
 	public void sendToEditor(REPCommand repCmd) {
--- a/rep/SessionList.java	Thu Aug 28 16:20:17 2008 +0900
+++ b/rep/SessionList.java	Thu Aug 28 16:36:18 2008 +0900
@@ -176,7 +176,7 @@
 
 	public void sendSelect(int sid) {
 //		SocketChannel channel = session3.get(sid).getMaster().getChannel();
-		REPSocketChannel<REPCommand> channel = sessionLinkedList.get(sid-1).getMaster().getChannel();
+		REPSocketChannel<REPCommand> channel = sessionLinkedList.get(sid-1).getOwner().getChannel();
 		REPPacketSend send = new REPPacketSend(channel);
 		send.send(new REPCommand(REP.SMCMD_SELECT, sid, 0, 0, 0, 0, ""));
 	}
--- a/rep/SessionManager.java	Thu Aug 28 16:20:17 2008 +0900
+++ b/rep/SessionManager.java	Thu Aug 28 16:36:18 2008 +0900
@@ -25,7 +25,7 @@
 import rep.handler.PacketSet;
 import rep.handler.REPHandler;
 import rep.handler.REPHandlerImpl;
-import rep.simulator.REPSelector;
+import rep.channel.REPSelector;
 import rep.xml.SessionXMLDecoder;
 import rep.xml.SessionXMLEncoder;
 
@@ -57,7 +57,6 @@
 	private String maxHost;
 	private boolean isSimulation;
 	private List<PacketSet> packetSetList;
-	//private Set<SelectionKey> sessionList;
 	private static int temp_port;
 	private static int send_port;
 	
@@ -136,22 +135,21 @@
 
 	public void manage(REPSocketChannel<REPCommand> channel, REPCommand receivedCommand) {
 		if(receivedCommand == null) return;
-		Session session;
+		//Session session;
 		REPCommand sendCommand = new REPCommand(receivedCommand);
 		REPPacketSend send = new REPPacketSend(channel);
 
 		switch(receivedCommand.cmd){
 
 		case REP.SMCMD_JOIN:
-			
-			if(isSimulation){
-				editorList.add(new Editor(editorList.size(), channel));
+			{
+				//どのSessionにも属さないエディタをリストに追加
+				Editor editor = new Editor(editorList.size(), channel);
+				editor.setHost(myHost);
+				editorList.add(editor);
 				
-			}else{
-				Editor editor = new Editor(channel);
-				editor.setHost(myHost);
-				int tempeid = ownEditorList.addEditor(editor);
-				gui.setComboEditor(tempeid, channel);
+				//GUIに反映
+				gui.setComboEditor(editor.getEID(), channel);
 			}
 			
 
@@ -162,65 +160,58 @@
 			break;
 
 		case REP.SMCMD_PUT:
-
-			if(isSimulation){
+			{
 				//エディタのリストに追加
-				editorList.add(new Editor(editorList.size(), channel));
+				Editor editor = new Editor(editorList.size(), channel);
+				editorList.add(editor);
+				
 				//Sessionを生成
 				int sid = sessionList.size();
-				sessionList.add(new Session(sid, new Editor(0, channel)));
-
-			}else{
-				Editor editor = new Editor(channel);
+				editor = new Editor(0, channel);
 				editor.setHost(myHost);
-				ownEditorList.addEditor(editor);
-				editor.setEID(1);
-				editor.setName(receivedCommand.string);
-				session = new Session(editor);
-				session.setOwner(true);
-				session.addEditor(editor);
-				sessionlist.addSession(session);
+				Session session = new Session(sid, editor);
+				session.hasOwner(true);
+				sessionList.add(new Session(sid, editor));
+				
+				//GUIに反映
 				gui.setComboSession(session.getSID(), session.getName());
 				gui.setComboEditor(editor.getEID(), editor.getChannel());
-				session.addToRoutingTable(editor);
+				
+				//エディタにAckを送信
 				sendCommand.setCMD(REP.SMCMD_PUT_ACK);
-				sendCommand.setEID(1);
+				sendCommand.setEID(editor.getEID());
 				sendCommand.setSID(session.getSID());
 				editor.send(sendCommand);
-
+				
+				//他のSessionManagerへSessionの追加を報告
 				SessionXMLEncoder sessionEncoder = new SessionXMLEncoder(session);
 				REPCommand command = new REPCommand();
 				command.setSID(session.getSID());
 				command.setString(sessionEncoder.sessionListToXML());
-
 				command.setCMD(REP.SMCMD_UPDATE);
 				smList.sendExcept(channel, command);
+
 			}
 
-
-
 			break;
 
 		case REP.SMCMD_SELECT:
-			
-			if(isSimulation){
-				Editor editor = getEditor(channel);
-				sessionList.get(receivedCommand.sid).addEditor(editor);
+			{
+				//エディタをSessionに追加
+				Editor editor = new Editor(channel);
+				Session session = getSession(receivedCommand.sid);
+				session.addEditor(editor);
 				
-			}else{
-				Editor editor = new Editor(channel);
-				session = sessionlist.getSession(receivedCommand.sid);
-				if(session.isOwner()){
-					session.addEditor(editor);
+				if(session.hasOwner()){
+					//このSessionManagerがオーナーを持っている場合、Sessionにエディタを追加し、エディタへAckを返す
 					sendCommand.setCMD(REP.SMCMD_SELECT_ACK);
 					sendCommand.setEID(editor.getEID());
-					send.send(sendCommand);
-				}else {
-					Editor master = session.getMaster();
-					master.send(receivedCommand);
-					session.addEditor(editor);
+					editor.send(sendCommand);
+				}else{
+					//オーナーを持ってない場合は、オーナーを持っているSessionManagerへSELECTコマンドを中継する
+					Editor owner = session.getOwner();
+					owner.send(receivedCommand);
 				}
-
 			}
 
 			break;
@@ -242,6 +233,11 @@
 			break;
 
 		case REP.SMCMD_SM_JOIN:
+			
+			if(isSimulation){
+				smList.add(channel);
+				break;
+			}
 
 			//SessionManagerのリストへ追加
 			smList.add(channel);
@@ -325,7 +321,7 @@
 				Editor editor = new Editor(channel);
 				editor.setName(receivedCommand.string);
 
-				session = new Session(editor);
+				Session session = new Session(editor);
 				session.addEditor(editor);
 
 				sessionlist.addSession(session);
@@ -351,7 +347,7 @@
 
 		default:
 			//sid から Session を取得
-			session = getSession(receivedCommand.sid);
+			Session session = getSession(receivedCommand.sid);
 			//マージの処理と次のエディタへコマンドを送信する処理
 			session.translate(channel, receivedCommand);
 		break;
@@ -472,7 +468,7 @@
 		REPSocketChannel channel = event.getEditorChannel();
 		int sid = event.getSID();
 		Session session = sessionlist.getSession(sid);
-		if(session.isOwner()){
+		if(session.hasOwner()){
 			Editor editor = new Editor(channel);
 			session.addEditor(new Editor(channel));
 			REPCommand sendCommand = new REPCommand();
@@ -489,7 +485,7 @@
 			session = sessionlist.getSession(sid);
 			session.addEditor(editor);
 			
-			Editor owner = session.getMaster();
+			Editor owner = session.getOwner();
 			
 			REPCommand command = new REPCommand();
 			command.setCMD(REP.SMCMD_SELECT);