changeset 420:5c95a9020e31

Modify ServerMainLoop
author one
date Fri, 13 Feb 2009 19:13:50 +0900
parents 7ff127c8ad64
children f8916a96a373
files rep/ServerMainLoop.java test/AutoSelectManager.java test/editortest/REPEditor.java test/editortest/TestMerger.java test/editortest/UserSimulator.java test/mergertest/EditorSimulator.java test/mergertest/EditorSimulatorImpl.java test/mergertest/REPTextWithLinkedList.java test/mergertest/RemoteEditorSimulator.java test/mergertest/SeMaSimulator.java test/mergertest/TestMerger.java test/mergertest/TestMerger2.java test/mergertest/TestUserSimulator.java test/mergertest/UserSimulator.java
diffstat 14 files changed, 479 insertions(+), 145 deletions(-) [+]
line wrap: on
line diff
--- a/rep/ServerMainLoop.java	Tue Jan 20 18:39:02 2009 +0900
+++ b/rep/ServerMainLoop.java	Fri Feb 13 19:13:50 2009 +0900
@@ -62,9 +62,10 @@
 			manager.checkWaitingCommandInMerge();
 			if (checkInputEvent() ||
 			    checkWaitingWrite()) { 
+				continue;
 				   // try to do fair execution for waiting task
-				   if(selector.selectNow() > 0) select();
-				   continue;
+				   //if(selector.selectNow() > 0) select();
+				   //continue;
 			}
 			// now we can wait for input packet or event
 			selector.select();
--- a/test/AutoSelectManager.java	Tue Jan 20 18:39:02 2009 +0900
+++ b/test/AutoSelectManager.java	Fri Feb 13 19:13:50 2009 +0900
@@ -21,7 +21,7 @@
 			port = Integer.parseInt(args[0]);
 			port_s = Integer.parseInt(args[1]);
 		}
-		Editor.noMergeMode = true;
+		Editor.noMergeMode = false;
 		SessionManager sm = new SessionManager();
 		sm.setReceivePort(port);
 		sm.setParentPort(port_s);
--- a/test/editortest/REPEditor.java	Tue Jan 20 18:39:02 2009 +0900
+++ b/test/editortest/REPEditor.java	Fri Feb 13 19:13:50 2009 +0900
@@ -31,6 +31,7 @@
 	private boolean master;
 	private boolean syncEnable = true;
 	private LogTarget logTarget;
+	private int tempseq = -1;
 	
 	public REPEditor(REPText repText, boolean master){
 		this.repText = repText;
@@ -136,6 +137,17 @@
 
 	private void handle(REPCommand command) {
 		Logger.print(logTarget, command);
+		
+		//check seq
+		if(eid == 1){
+			if(command.eid == 3){
+				if(tempseq > command.seq){
+					System.err.println(command);
+				}
+				tempseq = command.seq;
+			}
+		}
+		
 //		if(inputLock) Logger.print(logTarget, command);
 		if(command == null) return;
 		switch(command.cmd){
--- a/test/editortest/TestMerger.java	Tue Jan 20 18:39:02 2009 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,132 +0,0 @@
-package test.editortest;
-
-import java.io.IOException;
-import java.util.LinkedList;
-
-import rep.REP;
-import rep.REPCommand;
-import rep.Session;
-import rep.channel.REPSelectionKey;
-import rep.channel.REPSocketChannel;
-import rep.handler.REPNode;
-import rep.handler.Translator;
-import rep.optimizers.NullOptimizer;
-
-public class TestMerger extends REPNode{
-	Translator trans;
-	private int seq;
-	private LinkedList<REPCommand> commandList;
-	private LinkedList<REPCommand> othersCommandList;
-	
-	public static void main(String[] args){
-		TestMerger test = new TestMerger();
-		test.setCommands();
-		test.start();
-	}
-
-	public TestMerger(){
-		eid = 1;
-		sid = 1;
-		trans = new Translator(eid, new NullOptimizer());
-	}
-	
-	private void setCommands() {
-		commandList = new LinkedList<REPCommand>();
-		commandList.add(new REPCommand(REP.REPCMD_INSERT, sid, eid, seq++, 10, "AAAAA"));
-		commandList.add(new REPCommand(REP.REPCMD_INSERT, sid, eid, seq++, 10, "BBBBB"));
-		othersCommandList = new LinkedList<REPCommand>();
-		othersCommandList.add(new REPCommand(REP.REPCMD_INSERT, sid, eid+1, seq++, 10, "CCCCC"));
-	}
-
-	private void start() {
-		for(REPCommand command : commandList){
-			trans.transSendCmd(command);
-		}
-		for(REPCommand command : othersCommandList){
-			trans.transSendCmd(command);
-		}
-		for(int i = 0; i < commandList.size(); i++){
-			trans.catchOwnCommand(this);
-			System.out.println();
-		}
-	}
-
-	@Override
-	public void cancel(REPSocketChannel<REPCommand> channel1) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void checkWaitingCommandInMerge() {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void forwardedCommandManage(REPCommand command) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public String getLocalHostName() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void handle(REPCommand command, REPSelectionKey<REPCommand> key)
-			throws IOException {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public boolean isMerging() {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-	@Override
-	public void joinAck(REPCommand sendCommand, int sid) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public boolean manage(REPCommand command) {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-	@Override
-	public void selectSession(REPCommand sendCommand, Session session) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public void send(REPCommand command) {
-		// TODO Auto-generated method stub
-		Logger.print(command);
-	}
-
-	@Override
-	public void sendWithSeq(REPCommand command) {
-		// TODO Auto-generated method stub
-		
-	}
-
-	@Override
-	public int seq() {
-		// TODO Auto-generated method stub
-		return 0;
-	}
-
-	@Override
-	public void setQuit2(REPCommand receivedCommand) {
-		// TODO Auto-generated method stub
-		
-	}
-}
--- a/test/editortest/UserSimulator.java	Tue Jan 20 18:39:02 2009 +0900
+++ b/test/editortest/UserSimulator.java	Fri Feb 13 19:13:50 2009 +0900
@@ -19,7 +19,6 @@
 	private static final long serialVersionUID = 1L;
 	private JButton startButton;
 	private LinkedList<SimpleEditorForREPEditor> editorList;
-	private LinkedList<REPCommand> userInputList;
 	private JButton initButton;
 	
 	public UserSimulator(String title){
@@ -31,15 +30,7 @@
 		pack();
 	}
 
-	private void setUserInput() {
-		userInputList = new LinkedList<REPCommand>();
-		userInputList.add(new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, 0, "AAAAA"));
-		userInputList.add(new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, 1, "BBBBB"));
-		userInputList.add(new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, 2, "CCCCC"));
-	}
-	
 	private void init(){
-		setUserInput();
 		editorList.get(0).repPut();
 		for(int i = 1; i < editorList.size(); i++){
 			editorList.get(i).repJoin();
@@ -81,7 +72,7 @@
 //			for(REPCommand command : userInputList){
 			for(int i = 0; i < 5; i++){
 				for(SimpleEditorForREPEditor editor : editorList){
-					REPCommand command = new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, i, editor.getTitle() + ":" + i);
+					REPCommand command = new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, 0, editor.getTitle() + ":" + i);
 					((REPTextWithJTextArea) editor.getREPEditor().getREPText()).userInsert(command);
 				}
 			}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mergertest/EditorSimulator.java	Fri Feb 13 19:13:50 2009 +0900
@@ -0,0 +1,86 @@
+package test.mergertest;
+
+import java.io.IOException;
+
+import rep.REPCommand;
+import rep.Session;
+import rep.channel.REPSelectionKey;
+import rep.channel.REPSocketChannel;
+import rep.handler.REPNode;
+
+public abstract class EditorSimulator extends REPNode {
+
+	@Override
+	public void cancel(REPSocketChannel<REPCommand> channel1) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void checkWaitingCommandInMerge() {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void forwardedCommandManage(REPCommand command) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public String getLocalHostName() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public void handle(REPCommand command, REPSelectionKey<REPCommand> key)
+			throws IOException {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public boolean isMerging() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public void joinAck(REPCommand sendCommand, int sid) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public boolean manage(REPCommand command) {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public void selectSession(REPCommand sendCommand, Session session) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void sendWithSeq(REPCommand command) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public int seq() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	@Override
+	public void setQuit2(REPCommand receivedCommand) {
+		// TODO Auto-generated method stub
+
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mergertest/EditorSimulatorImpl.java	Fri Feb 13 19:13:50 2009 +0900
@@ -0,0 +1,24 @@
+package test.mergertest;
+
+import rep.REPCommand;
+import rep.handler.Translator;
+import rep.optimizers.NullOptimizer;
+import test.editortest.Logger;
+
+public class EditorSimulatorImpl extends EditorSimulator {
+
+	private Translator translator;
+
+	public EditorSimulatorImpl(int sid, int eid) {
+		this.eid = eid;
+		this.sid = sid;
+		
+		translator = new Translator(eid, new NullOptimizer());
+	}
+
+	@Override
+	public void send(REPCommand command) {
+		Logger.print(command);
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mergertest/REPTextWithLinkedList.java	Fri Feb 13 19:13:50 2009 +0900
@@ -0,0 +1,47 @@
+package test.mergertest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import test.editortest.REPText;
+import test.editortest.REPTextListener;
+
+public class REPTextWithLinkedList implements REPText {
+	
+	ArrayList<String> textList = new ArrayList<String>();
+
+	public void addTextListener(REPTextListener listener) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public String delete(int lineno) {
+		return null;
+	}
+
+	public String get(int i) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public void insert(int lineno, String text) {
+		int d = lineno - textList.size() + 1;
+
+		for(int i = 0; i < d; i++){
+			textList.add("");
+		}
+
+		textList.add(lineno, text);
+	}
+
+	public List<String> list() {
+		// TODO Auto-generated method stub
+		return textList;
+	}
+
+	public int size() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mergertest/RemoteEditorSimulator.java	Fri Feb 13 19:13:50 2009 +0900
@@ -0,0 +1,42 @@
+package test.mergertest;
+
+import java.util.List;
+
+import rep.REP;
+import rep.REPCommand;
+import test.editortest.Logger;
+import test.editortest.REPText;
+
+public class RemoteEditorSimulator {
+
+	private REPText repText;
+	private int eid;
+	
+	public RemoteEditorSimulator(int eid){
+		this.eid = eid;
+		repText = new REPTextWithLinkedList();
+	}
+
+	public void edit(REPCommand command) {
+		Logger.print(command);
+		if(command.cmd == REP.REPCMD_INSERT_USER){
+			repText.insert(command.lineno, command.string);
+		}else if(command.cmd == REP.REPCMD_DELETE_USER){
+			repText.delete(command.lineno);
+		}
+	}
+
+	public int getEID() {
+		return eid;
+	}
+
+	public void display() {
+		List<String> list = repText.list();
+		System.out.println();
+		System.out.println("---------- Editor" + eid + " ----------");
+		for(String str : list){
+			System.out.println(str);
+		}
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mergertest/SeMaSimulator.java	Fri Feb 13 19:13:50 2009 +0900
@@ -0,0 +1,12 @@
+package test.mergertest;
+
+import rep.REPCommand;
+
+public class SeMaSimulator {
+
+	public void toSeMa(REPCommand command) {
+		// TODO Auto-generated method stub
+		
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mergertest/TestMerger.java	Fri Feb 13 19:13:50 2009 +0900
@@ -0,0 +1,134 @@
+package test.mergertest;
+
+import java.io.IOException;
+import java.util.LinkedList;
+
+import rep.REP;
+import rep.REPCommand;
+import rep.Session;
+import rep.channel.REPSelectionKey;
+import rep.channel.REPSocketChannel;
+import rep.handler.REPNode;
+import rep.handler.Translator;
+import rep.optimizers.NullOptimizer;
+import test.editortest.Logger;
+
+public class TestMerger extends REPNode{
+	Translator trans;
+	private int seq;
+	private LinkedList<REPCommand> commandList;
+	private LinkedList<REPCommand> othersCommandList;
+	
+	public static void main(String[] args){
+		TestMerger test = new TestMerger();
+		test.setCommands();
+		test.start();
+	}
+
+	public TestMerger(){
+		eid = 1;
+		sid = 1;
+		trans = new Translator(eid, new NullOptimizer());
+	}
+	
+	private void setCommands() {
+		commandList = new LinkedList<REPCommand>();
+		commandList.add(new REPCommand(REP.REPCMD_INSERT, sid, eid, seq++, 10, "AAAAA"));
+		commandList.add(new REPCommand(REP.REPCMD_INSERT, sid, eid, seq++, 10, "BBBBB"));
+		othersCommandList = new LinkedList<REPCommand>();
+		othersCommandList.add(new REPCommand(REP.REPCMD_INSERT, sid, eid+1, 1, 10, "CCCCC"));
+	}
+
+	private void start() {
+		for(REPCommand command : commandList){
+			Logger.print(command);
+			trans.transSendCmd(command);
+		}
+		for(REPCommand command : othersCommandList){
+			Logger.print(command);
+			trans.transReceiveCmd(null, command);
+		}
+		for(int i = 0; i < commandList.size(); i++){
+			trans.catchOwnCommand(this);
+			System.out.println();
+		}
+	}
+
+	@Override
+	public void cancel(REPSocketChannel<REPCommand> channel1) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void checkWaitingCommandInMerge() {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void forwardedCommandManage(REPCommand command) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public String getLocalHostName() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public void handle(REPCommand command, REPSelectionKey<REPCommand> key)
+			throws IOException {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public boolean isMerging() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public void joinAck(REPCommand sendCommand, int sid) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public boolean manage(REPCommand command) {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public void selectSession(REPCommand sendCommand, Session session) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void send(REPCommand command) {
+		Logger.print(command);
+	}
+
+	@Override
+	public void sendWithSeq(REPCommand command) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public int seq() {
+		// TODO Auto-generated method stub
+		return seq++;
+	}
+
+	@Override
+	public void setQuit2(REPCommand receivedCommand) {
+		// TODO Auto-generated method stub
+		
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mergertest/TestMerger2.java	Fri Feb 13 19:13:50 2009 +0900
@@ -0,0 +1,37 @@
+package test.mergertest;
+
+import java.util.LinkedList;
+
+public class TestMerger2 {
+	
+	private LinkedList<EditorSimulator> editorList;
+
+	public TestMerger2(int en, int cn) {
+		editorList = new LinkedList<EditorSimulator>();
+		for(int i = 0; i < en; i++){
+			editorList.add(new EditorSimulatorImpl(0, i));
+			try{
+				editorList.get(i-1).setNext(editorList.get(i));
+			}catch(IndexOutOfBoundsException e){
+				
+			}
+		}
+	}
+
+	public static void main(String[] args){
+		if(args.length > 1){
+			int en = Integer.parseInt(args[0]);
+			int cn = Integer.parseInt(args[1]);
+			TestMerger2 test = new TestMerger2(en, cn);
+			test.start();
+		}else{
+			TestMerger2 test = new TestMerger2(3, 3);
+			test.start();
+		}
+	}
+
+	private void start() {
+		
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mergertest/TestUserSimulator.java	Fri Feb 13 19:13:50 2009 +0900
@@ -0,0 +1,44 @@
+package test.mergertest;
+
+import java.util.LinkedList;
+
+import test.editortest.Logger;
+
+public class TestUserSimulator {
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		Logger.print(Thread.currentThread());
+		int en = 3;
+//		int cn = 3;
+		
+		LinkedList<UserSimulator> userList = new LinkedList<UserSimulator>();
+		LinkedList<RemoteEditorSimulator> editorList = new LinkedList<RemoteEditorSimulator>();
+		
+		for(int i = 0; i < en; i++){
+			RemoteEditorSimulator editor = new RemoteEditorSimulator(i);
+			editorList.add(editor);
+			userList.add(new UserSimulator(editor));
+		}
+		
+		for(UserSimulator user : userList){
+			user.start();
+		}
+		
+		for(UserSimulator user : userList){
+			try {
+				user.join();
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+		
+		for(RemoteEditorSimulator editor : editorList){
+			editor.display();
+		}
+		
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mergertest/UserSimulator.java	Fri Feb 13 19:13:50 2009 +0900
@@ -0,0 +1,36 @@
+package test.mergertest;
+
+import java.util.LinkedList;
+
+import rep.REP;
+import rep.REPCommand;
+
+public class UserSimulator extends Thread {
+	
+	private RemoteEditorSimulator editor;
+	private LinkedList<REPCommand> userInputList;
+
+	public UserSimulator(RemoteEditorSimulator editor){
+		this.editor = editor;
+		
+		int eid = editor.getEID();
+		userInputList = new LinkedList<REPCommand>();
+		int count = 0;
+		for(int i = 0; i < 3; i++){
+			userInputList.add(new REPCommand(REP.REPCMD_INSERT_USER, 0, eid, count, 3, " User:" + eid + ":" + i));
+			count++;
+		}
+	}
+	
+	public void setUserInput(LinkedList<REPCommand> list){
+		userInputList = list;
+	}
+	
+	@Override
+	public void run(){
+		for(REPCommand command : userInputList){
+			editor.edit(command);
+		}
+	}
+
+}