Mercurial > hg > RemoteEditor > Eclipse
changeset 126:b56b5950cb18
ns.writelog(str, int);
author | kent |
---|---|
date | Tue, 25 Dec 2007 20:52:18 +0900 |
parents | 34b15dfcb83e |
children | 6f174e2b7503 |
files | src/pathfinder/mergetest/EditorSimulator.java src/pathfinder/mergetest/NetworkSimulator.java src/pathfinder/mergetest/SeMaSimulator.java src/pathfinder/mergetest/TestMerger.java src/pathfinder/mergetest/UsersSimulator.java |
diffstat | 5 files changed, 33 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/pathfinder/mergetest/EditorSimulator.java Tue Dec 25 20:07:37 2007 +0900 +++ b/src/pathfinder/mergetest/EditorSimulator.java Tue Dec 25 20:52:18 2007 +0900 @@ -35,7 +35,7 @@ } public void run(){ - System.out.println("Editor"+eid+" start."); + ns.writeLog("Editor"+eid+" start.", 1); // Send All Command that is included CmdList. //sendAllCommand(); @@ -45,36 +45,38 @@ REPCommand cmd = cs.read(); REPCommand[] cmds; - //System.out.println("\tEditor"+eid+" catch command from "+cmd.eid+" NO."+cmd.seq); + ns.writeLog("\tEditor"+eid+" catch command from "+cmd.eid+" NO."+cmd.seq, 3); if (cmd.eid==eid){ cmds = translater.catchOwnCommand(cmd); for (int i=0; i<cmds.length; i++){ REPCommand tmp = cmds[i]; - //System.out.println("\t\tEditor"+eid+" edit text. "); + ns.writeLog("\t\tEditor"+eid+" edit text. ", 4); text.edit(tmp); } /* 終了条件 */ if (cmd.cmd==REP.SMCMD_QUIT){ - //System.out.println("\tEditor"+eid+" catch QUIT command emited by itself."); + ns.writeLog("\tEditor"+eid+" catch QUIT command emited by itself.", 2); running=false; break; } } else if (cmd.eid==-1){ /* 制御プロセスからの指令 */ - System.out.println("\tEditor"+eid+" send command."); + ns.writeLog("\tEditor"+eid+" send command.", 2); + if (cmd.cmd==REP.SMCMD_QUIT) + synchronized(ns){ ns.writeLog("send Quit cmd.", 1); } sendOneCommand(cmd); } else { cmds = translater.transReceiveCmd(cmd); for (int i=0; i<cmds.length; i++){ cmd = cmds[i]; - //System.out.println("\t\tEditor"+eid+" edit text and pass Cmd. "); + ns.writeLog("\t\tEditor"+eid+" edit text and pass Cmd. ", 4); text.edit(cmd); cs.write(new REPCommand(cmd)); } } } - System.out.println("Editor"+eid+" finish."); + ns.writeLog("Editor"+eid+" finish.", 1); } private void sendOneCommand(REPCommand cmd) {
--- a/src/pathfinder/mergetest/NetworkSimulator.java Tue Dec 25 20:07:37 2007 +0900 +++ b/src/pathfinder/mergetest/NetworkSimulator.java Tue Dec 25 20:52:18 2007 +0900 @@ -2,17 +2,22 @@ public abstract class NetworkSimulator<P> { - - /** - * Request to connect. - * Client editor use this method to connect SeMa. - * @param cs - */ + int logLevel; + public abstract ChannelSimulator<P> connect(); public abstract ChannelSimulator<P> accept(); public abstract boolean checkAllCS(); public abstract ChannelSimulator<P> getAcceptedSession(int i); + + public void writeLog(String log, int level){ + if ( level<=logLevel ) + System.out.println(log); + } + + public void setLogLevel(int logLevel) { + this.logLevel = logLevel; + } /* synchronized public P read(ChannelSimulator<P> cs){ try {
--- a/src/pathfinder/mergetest/SeMaSimulator.java Tue Dec 25 20:07:37 2007 +0900 +++ b/src/pathfinder/mergetest/SeMaSimulator.java Tue Dec 25 20:52:18 2007 +0900 @@ -48,7 +48,7 @@ int count=0; P packet; - System.out.println("SessionManager start."); + ns.writeLog("SessionManager start.", 1); /* Main Loop */ ChannelSimulator<P> cs = csList.get(i); @@ -64,31 +64,15 @@ } if(!running) break; - //System.out.println("SeMa pass packet to "+i+":>> "+packet.toString()); + ns.writeLog("SeMa pass packet to "+i+":>> "+packet.toString(), 3); i = (i+1)%csList.size(); // i++ cs = csList.get(i); // 次のChennelをゲット if ( !cs.write(packet) ){ - System.err.println("Session Manager failed to write."); + ns.writeLog("Session Manager failed to write.", 0); } count++; } -/* - ChannelSimulator<P> cs = csList.get(i); - while(running - && MAX_PACKET==0 || count<MAX_PACKET){ - packet=cs.poll(); // [i]からread - //if(packet!=null) System.out.println("SeMa catch packet to "+i+":>> "+packet.toString()); - i = (i+1)%csList.size(); // i++ - cs = csList.get(i); // 次のChennelをゲット - if (packet!=null) { - System.out.println("SeMa pass packet to "+i+":>> "+packet.toString()); - cs.write(packet); // readできていたならそれを書き込む - count++; - } - //if (i==0) checkAccept(); //全部回ったらaccept待ちをチェック - } -*/ - System.out.println("SessionManager finish."); + ns.writeLog("SessionManager finish.", 1); } }
--- a/src/pathfinder/mergetest/TestMerger.java Tue Dec 25 20:07:37 2007 +0900 +++ b/src/pathfinder/mergetest/TestMerger.java Tue Dec 25 20:52:18 2007 +0900 @@ -26,10 +26,10 @@ /* create, initialize and start test. */ tm = new TestMerger(); - tm.init(true, i, j); + tm.init(false, i, j, 1); // init( boolean SM?, int max_client, int max_packet, int loglevel); tm.startTest(); - //tm.printAllTexts(); + tm.printAllTexts(); //if (!tm.checkCS()) // System.out.println("Error!! :some ChannelSimulator still have packet!"); if (!tm.checkEquality()) @@ -60,7 +60,7 @@ if (sema!=null) sema.finish(); } - private void init(boolean sm, int ne, int np){ + private void init(boolean sm, int ne, int np, int ll){ /* create NetworkSimulator, and SessionManager if it's required. */ if (sm){ ns = new NetworkSimulatorwithSeMa<REPCommand>(); @@ -69,6 +69,7 @@ ns = new NetworkSimulatorwithoutSeMa<REPCommand>(); sema = null; } + ns.setLogLevel(ll); /* create UsersSimulator. */ users = new UsersSimulator(ns, ne, np*ne);
--- a/src/pathfinder/mergetest/UsersSimulator.java Tue Dec 25 20:07:37 2007 +0900 +++ b/src/pathfinder/mergetest/UsersSimulator.java Tue Dec 25 20:52:18 2007 +0900 @@ -22,7 +22,7 @@ public void run(){ int i=0; - System.out.println("UsersSimulator start."); + ns.writeLog("UsersSimulator start.", 1); while( i++<N_packet ){ REPCommand cmd0 = createCmd(); ChannelSimulator<REPCommand> cs = channelList.get(nextChannelIndex); @@ -33,12 +33,14 @@ } /* send quitPacket to all editors. */ + synchronized (ns){ for ( ChannelSimulator<REPCommand> cs : channelList){ REPCommand cmd0 = createQuitCmd(); cs.write(cmd0); } - - System.out.println("UsersSimulator finish."); + } + + ns.writeLog("UsersSimulator finish.", 1); } private REPCommand createCmd(){