changeset 325:be0831086e63

*** empty log message ***
author kono
date Sat, 11 Oct 2008 17:43:51 +0900
parents e235998427a6
children b1a6acf0b8a9
files rep/Editor.java rep/translator/Translator.java rep/translator/TranslatorImpl.java
diffstat 3 files changed, 48 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/rep/Editor.java	Sat Oct 11 16:31:03 2008 +0900
+++ b/rep/Editor.java	Sat Oct 11 17:43:51 2008 +0900
@@ -5,11 +5,12 @@
 import rep.channel.REPSocketChannel;
 import rep.handler.PacketSet;
 import rep.optimizers.*;
+import rep.translator.Translator;
 import rep.translator.TranslatorImpl;
 
 public class Editor extends Forwarder {
 
-	private TranslatorImpl translator;
+	private Translator translator;
 	private List<REPCommand> sentList = new LinkedList<REPCommand>();
 	// REPCommands we are going to send to the next editor
 	private REPCommandOptimizer optimizer;
@@ -35,24 +36,14 @@
 
 	public void translate(Editor nextEditor, REPCommand command){
 		if(command.eid == nextEditor.getEID()){
-			if(nextEditor.checkReturnedCommand(command)){
-				// エディタからのコマンドが元のエディタに戻ってきた
-				// START_MERGE を送る
-				REPCommand cmd = new REPCommand(REP.SMCMD_START_MERGE,command.sid,REP.SM_EID.id,seq(),0,"");
-				nextEditor.send(cmd);
-				// Session Manager 側で、このeditorへの他のeditorからの
-				// 入力を止めて、merge にそなえる。merge は、eidtor 側から
-				// ACKが来てから始まる。
-				translator.startMerge(cmd);
-				return;
-			} else assert(false);
+			nextEditor.checkReturnedCommand(command);
 		} else if(command.eid == eid){
-				//エディタからの新たな編集コマンド
-				sentList.add(command);
-				assert(sentList.size()<limit);
-				translator.transSendCmd(command);
-				nextEditor.send(command);
-				return;
+			//エディタからの新たな編集コマンド
+			sentList.add(command);
+			assert(sentList.size()<limit);
+			translator.transSendCmd(command);
+			nextEditor.send(command);
+			return;
 		}else if(command.eid == REP.MERGE_EID.id){
 			//マージコマンドが返ってきた
 			if(translator.checkMergeConflict(command)){
@@ -73,7 +64,7 @@
 		}
 		return;
 	}
-	
+
 	boolean merge(REPCommand command) {
 		REPCommand prev = translator.prev();
 		if(prev==null) return false;
@@ -82,7 +73,7 @@
 		return translator.catchOwnCommand(this);
 	}
 
-	boolean checkReturnedCommand(REPCommand command) {
+	void checkReturnedCommand(REPCommand command) {
 		if(sentList.size() > 0){
 			if(sentList.get(0).seq == command.seq){
 				sentList.remove(0);
@@ -90,13 +81,19 @@
 					send(quit2);
 					manager.remove(this);
 				}
-				return true;
 			}else{
 				System.out.println("Editor.checkReturnedCommand() : command = " + command);
 				assert(false);
 			}
 		}
-		return false;
+		// START_MERGE を送る
+		REPCommand cmd = new REPCommand(REP.SMCMD_START_MERGE,command.sid,REP.SM_EID.id,seq(),0,"");
+		send(cmd);
+		// Session Manager 側で、このeditorへの他のeditorからの
+		// 入力を止めて、merge にそなえる。merge は、eidtor 側から
+		// ACKが来てから始まる。
+		translator.startMerge(cmd);
+		return;
 	}
 
 	@Override
--- a/rep/translator/Translator.java	Sat Oct 11 16:31:03 2008 +0900
+++ b/rep/translator/Translator.java	Sat Oct 11 17:43:51 2008 +0900
@@ -1,35 +1,55 @@
 package rep.translator;
 
+import java.util.LinkedList;
+
 import rep.Editor;
 import rep.Forwarder;
 import rep.REPCommand;
 
 public interface Translator {
 
+	/*
+	 * Interface で分離する意味が良くわからない。Application毎に
+	 * Transltorを換えるつもりなのか?
+	 */
 	/**
 	 * Translate command When the editor send REPCommand to remote editor.
 	 * @param command which the editor want to send.
 	 * @return translated command which should be sent by the editor.
 	 */
-	abstract public REPCommand transSendCmd(REPCommand cmd);
+	public REPCommand transSendCmd(REPCommand cmd);
 
 	/**
 	 * Inform translater about that the editor receive own command which it sent.
 	 * but in this case, you can use also transReceiveCmd()
 	 * @param command which the editor sent.
 	 */
-	abstract public boolean catchOwnCommand(Editor editor);
+	public boolean catchOwnCommand(Editor editor);
 	
 	/**
 	 * Translate Command cmd that was received from SeMa.
 	 * @param cmd the command to be translated.
 	 * @return translated command.
 	 */
-	abstract public void transReceiveCmd(Forwarder nextEditor,REPCommand cmd);
+	public void transReceiveCmd(Forwarder nextEditor,REPCommand cmd);
 
 	/**
 	 * set the editor's id.
 	 * @param editor's id.
 	 */
-	abstract public void setEid(int _eid);
+	public void setEid(int _eid);
+
+	boolean checkMergeConflict(REPCommand command);
+
+	public LinkedList<REPCommand> getMergeAgain();
+
+	public void startMerge(REPCommand cmd);
+
+	public REPCommand prev();
+
+	public boolean isMerging();
+
+	public void endMerge();
+
+	public void mergeAck();
 }
--- a/rep/translator/TranslatorImpl.java	Sat Oct 11 16:31:03 2008 +0900
+++ b/rep/translator/TranslatorImpl.java	Sat Oct 11 17:43:51 2008 +0900
@@ -50,8 +50,9 @@
 		return cmd;
 	}
 	/**
-	 * My command is returned from the session ring. At this
-	 * stage writeQueue is empty, our editor is waiting for me.
+	 * My command is returned from the session ring, and START_MERGE_ACK
+	 * is returned. At this
+	 * stage my writeQueue is empty, our editor is waiting for me.
 	 * Start merge process.
 	 * @param cmd
 	 */
@@ -154,17 +155,14 @@
 	}
 
 	public Stack<REPCommand> getList() {
-		// TODO Auto-generated method stub
 		return unMergedCmds;
 	}
 
 	public LinkedList<REPCommand> getSentCmds() {
-		// TODO Auto-generated method stub
 		return sentCmds;
 	}
 
 	public void setUndoCommand(REPCommand command) {
-		// TODO Auto-generated method stub
 		undoReplaceList.add(command);
 	}
 
@@ -223,7 +221,8 @@
 	}
 	
 	public void endMerge() {
-		merge_mode = false;
+		if(isFinished())
+			merge_mode = false;
 	}