diff test/sematest/TestEditor.java @ 284:90965a3bd4f3

editor simulator
author kono
date Sun, 28 Sep 2008 14:16:13 +0900
parents 311847db7429
children b468f24c3e09
line wrap: on
line diff
--- a/test/sematest/TestEditor.java	Sat Sep 27 23:45:34 2008 +0900
+++ b/test/sematest/TestEditor.java	Sun Sep 28 14:16:13 2008 +0900
@@ -2,23 +2,42 @@
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
-import java.net.SocketAddress;
 
 import rep.REP;
 import rep.REPCommand;
 import rep.REPCommandPacker;
 import rep.channel.REPLogger;
 import rep.channel.REPSocketChannel;
+import test.Text;
 
 
 public class TestEditor extends Thread{
-	private SocketAddress semaIP;
+	private InetSocketAddress semaIP;
 	private REPLogger ns;
+	private boolean master;
+	private int myid ;
+	private int seq = 0;
+	public static int editorNo = 0;
+	public Text text;
+
+	static private String[] text1d = {
+		"aaa", "bbb", "ccc", "ddd", "eee",
+		"fff", "ggg", "hhh", "iii", "jjj",
+		"kkk", "lll", "mmm", "nnn", "ooo",
+		"ppp", "qqq", "rrr", "sss", "ttt",
+		"uuu", "vvv", "www", "xxx", "yyy", "zzz"
+	};	
 	
-	public TestEditor(String name, String _host,int _port){
+	public TestEditor(String name, String _host,int _port, boolean master){
 		super(name);
 		semaIP = new InetSocketAddress(_host, _port);
 		ns = REPLogger.singleton();
+		this.master = master;
+		myid = editorNo++;
+		if (master)
+			text = new Text(text1d);
+		else
+			text = new Text(new String[0]);
 	}
 
 	public void run(){
@@ -26,23 +45,29 @@
 			REPSocketChannel<REPCommand> channel;
 			channel = REPSocketChannel.<REPCommand>create(new REPCommandPacker());
 
-			ns.writeLog("try to connect to SessionManager whose ip is "+semaIP, 1);
+			ns.writeLog("try to connect to SessionManager whose ip is "+semaIP+" editor-"+myid, 1);
 			while (!channel.connect(semaIP)){
 				ns.writeLog("SeMa not listen to socket yet, wait", 1);
 				Thread.yield();
 			}
-			ns.writeLog("successes to connect", 1);
-
-			REPCommand command = new REPCommand(REP.SMCMD_JOIN,0,0,0,0,0,getName() + ": send hello");
+			ns.writeLog("successes to connect editor-"+myid, 1);
+			REPCommand command;
+			/*
+			 *         public REPCommand(REP cmd,int sid,int eid, int seq, int lineno,  String string) 
+			 */
+			if (master)
+				command = new REPCommand(REP.SMCMD_PUT,0,0,seq++,0,"master-file");
+			else				
+				command = new REPCommand(REP.SMCMD_JOIN,0,0,seq++,0,"editor-"+myid);
 			channel.write(command);
-			ns.writeLog("wrote packet", 1);
 
-			REPCommand packet = channel.read();
-
-			ns.writeLog("gets return string==> `"+packet+"\'", 1);
-
-			ns.writeLog("testEditor exits.", 1);
+			mainloop(channel);
 		} catch (IOException e) {
 		}
 	}
+
+	private void mainloop(REPSocketChannel<REPCommand> channel) {
+
+		
+	}
 }