Mercurial > hg > RemoteEditor > REPSessionManager
changeset 284:90965a3bd4f3
editor simulator
author | kono |
---|---|
date | Sun, 28 Sep 2008 14:16:13 +0900 |
parents | b864d2f60102 |
children | b468f24c3e09 |
files | rep/REPCommand.java rep/SessionList.java rep/SessionManagerList.java rep/channel/ChannelSimulator.java rep/channel/NetworkSimulator.java rep/channel/ServerChannelSimulator.java rep/translater/TranslaterImp1.java test/sematest/JoinTester.java test/sematest/TestEditor.java test/sematest/Tester.java |
diffstat | 10 files changed, 56 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/REPCommand.java Sat Sep 27 23:45:34 2008 +0900 +++ b/rep/REPCommand.java Sun Sep 28 14:16:13 2008 +0900 @@ -3,7 +3,7 @@ import rep.REP; public class REPCommand { - public static REPCommand SMCMD_SESSION_JOIN = new REPCommand(REP.SMCMD_SM_JOIN, 0, 0, 0, 0, 0, ""); + public static REPCommand SMCMD_SESSION_JOIN = new REPCommand(REP.SMCMD_SM_JOIN, 0, 0, 0, 0, ""); public REP cmd; public int sid; public int eid; @@ -14,22 +14,20 @@ public boolean throughMaster; public String string; - private int textsiz; String host; String port; - public REPCommand(REP cmd,int sid,int eid, int seq, int lineno, int textsiz, String string) { + public REPCommand(REP cmd,int sid,int eid, int seq, int lineno, String string) { this.cmd = cmd; this.sid = sid; this.eid = eid; this.seq = seq; - this.textsiz = textsiz; this.lineno = lineno; this.string = string; this.throughMaster = false; } public REPCommand(REPCommand cmd){ - this(cmd.cmd, cmd.sid, cmd.eid, cmd.seq, cmd.lineno, cmd.string.length(), new String(cmd.string)); + this(cmd.cmd, cmd.sid, cmd.eid, cmd.seq, cmd.lineno, new String(cmd.string)); } public REPCommand() { @@ -41,44 +39,38 @@ this.sid = sid; this.eid = eid; this.seq = seq; - this.textsiz = textsiz; this.lineno = lineno; this.string = string; this.throughMaster = false; } public String toString(){ - String repCmdString = new String(cmd + ",sid=" + sid + ",eid=" + eid + ",seq=" + seq + ",lineno=" + lineno + ",sz=" + textsiz + "," + string); + String repCmdString = new String(cmd + ",sid=" + sid + ",eid=" + eid + ",seq=" + seq + + ",lineno=" + lineno + ",sz=" + string.length() + "," + string); return repCmdString; } public void setEID(int eid2) { - // TODO Auto-generated method stub this.eid = eid2; } public void setCMD(REP cmd2) { - // TODO Auto-generated method stub this.cmd = cmd2; } public void setSID(int sessionID) { - // TODO Auto-generated method stub this.sid = sessionID; } public void setString(String string2) { - // TODO Auto-generated method stub string = string2; } public void setHost(String host) { - // TODO Auto-generated method stub this.host = host; } public void setPort(String port) { - // TODO Auto-generated method stub this.port = port; } @@ -86,7 +78,6 @@ this.throughMaster=f; } public void setSEQID(int i) { - // TODO Auto-generated method stub seq = i; }
--- a/rep/SessionList.java Sat Sep 27 23:45:34 2008 +0900 +++ b/rep/SessionList.java Sun Sep 28 14:16:13 2008 +0900 @@ -121,7 +121,7 @@ public void sendSelect(int sid) { // SocketChannel channel = session3.get(sid).getMaster().getChannel(); REPSocketChannel<REPCommand> channel = sessionLinkedList.get(sid-1).getOwner().getChannel(); - channel.write(new REPCommand(REP.SMCMD_SELECT, sid, 0, 0, 0, 0, "")); + channel.write(new REPCommand(REP.SMCMD_SELECT, sid, 0, 0, 0, "")); } public void addSession(REPSocketChannel<REPCommand> channel, String string, int i) {
--- a/rep/SessionManagerList.java Sat Sep 27 23:45:34 2008 +0900 +++ b/rep/SessionManagerList.java Sun Sep 28 14:16:13 2008 +0900 @@ -18,7 +18,7 @@ public void sendUpdate(int sessionID, String string) { for(REPSocketChannel<REPCommand> channel : list){ - channel.write(new REPCommand(REP.SMCMD_UPDATE, 0, mySMID, 0, 0, string.length(), string)); + channel.write(new REPCommand(REP.SMCMD_UPDATE, 0, mySMID, 0, 0, string)); } }
--- a/rep/channel/ChannelSimulator.java Sat Sep 27 23:45:34 2008 +0900 +++ b/rep/channel/ChannelSimulator.java Sun Sep 28 14:16:13 2008 +0900 @@ -1,7 +1,7 @@ package rep.channel; import java.io.IOException; -import java.net.SocketAddress; +import java.net.InetSocketAddress; import java.nio.channels.ClosedChannelException; import java.nio.channels.NotYetConnectedException; import java.nio.channels.SelectableChannel; @@ -62,7 +62,7 @@ /** Connecting methods */ // for clients. - public boolean connect(SocketAddress ip){ + public boolean connect(InetSocketAddress ip){ return ns.connect(ip, this); // ns.connectはotherEndを返した方がよいか? } void setOtherEnd(ChannelSimulator<P> other){
--- a/rep/channel/NetworkSimulator.java Sat Sep 27 23:45:34 2008 +0900 +++ b/rep/channel/NetworkSimulator.java Sun Sep 28 14:16:13 2008 +0900 @@ -33,7 +33,7 @@ serverList = new LinkedList<ServerData<P>>(); logger = REPLogger.singleton(); logger.writeLog("construct Networksimulator", 1); - printAllState(); + // printAllState(); } /* */ @@ -43,13 +43,15 @@ printAllState(); } - synchronized public boolean connect(SocketAddress ip, ChannelSimulator<P> CHclient) { + synchronized public boolean connect(InetSocketAddress ip, ChannelSimulator<P> CHclient) { logger.writeLog("connecting..", 1); for (ServerData<P> sd0: serverList){ // ANY address (0.0.0.0/0.0.0.0) should be considered. if (sd0.IP.getAddress().isAnyLocalAddress()) { - // we have to check, ip is really reachable to sd0 server - // but how? + if (sd0.IP.getPort() != ip.getPort()) continue; + // we have to check, ip is really reachable to sd0 server, + // but this simulator has no notion of host. To distinguish, + // use different port address. } else if (!sd0.IP.equals(ip)) continue; ChannelSimulator<P> CHserver = new ChannelSimulator<P>();
--- a/rep/channel/ServerChannelSimulator.java Sat Sep 27 23:45:34 2008 +0900 +++ b/rep/channel/ServerChannelSimulator.java Sun Sep 28 14:16:13 2008 +0900 @@ -3,7 +3,6 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.ServerSocket; -import java.net.SocketAddress; import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey;
--- a/rep/translater/TranslaterImp1.java Sat Sep 27 23:45:34 2008 +0900 +++ b/rep/translater/TranslaterImp1.java Sun Sep 28 14:16:13 2008 +0900 @@ -83,7 +83,7 @@ private REPCommand createUndo(REPCommand cmd){ String str = new String(cmd.string); - REPCommand retCmd = new REPCommand(cmd.cmd, cmd.sid, cmd.eid, cmd.seq, cmd.lineno, str.length(), str); + REPCommand retCmd = new REPCommand(cmd.cmd, cmd.sid, cmd.eid, cmd.seq, cmd.lineno, str); retCmd.eid = REP.MERGE_EID.id; @@ -163,7 +163,7 @@ //自分のコマンドがないとマージできないのでNOPを挿入 cmds = new REPCommand[2]; String str = "NO OPERATION"; - cmds[0] = setCmdState( new REPCommand(REP.REPCMD_NOP, 0, eid, 0, 0, str.length(), str) ); + cmds[0] = setCmdState( new REPCommand(REP.REPCMD_NOP, 0, eid, 0, 0, str) ); cmds[1] = cmd; //unMergedCmds.push(cmds[0]); unMergedCmds.push(cmd);
--- a/test/sematest/JoinTester.java Sat Sep 27 23:45:34 2008 +0900 +++ b/test/sematest/JoinTester.java Sun Sep 28 14:16:13 2008 +0900 @@ -19,7 +19,7 @@ LinkedList<REPCommand> commands = new LinkedList<REPCommand>(); commands.add(command); - Tester tester = new PutTester("JoinTester", "localhost", 8766); + Tester tester = new JoinTester("JoinTester", "localhost", 8766); tester.setCommands(commands); tester.start(); }
--- 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) { + + + } }
--- a/test/sematest/Tester.java Sat Sep 27 23:45:34 2008 +0900 +++ b/test/sematest/Tester.java Sun Sep 28 14:16:13 2008 +0900 @@ -9,7 +9,6 @@ import rep.REPCommand; import rep.REPCommandPacker; import rep.channel.REPLogger; -import rep.channel.REPServerSocketChannel; import rep.channel.REPSocketChannel; public class Tester extends Thread{ @@ -58,9 +57,6 @@ } public void sendCommands(){ - if(commandList == null) return; - if(channel == null) return; - for(REPCommand command: commandList){ channel.write(command); }