Mercurial > hg > RemoteEditor > REPSessionManager
changeset 196:b85525d83b46
*** empty log message ***
author | kono |
---|---|
date | Fri, 29 Aug 2008 21:39:13 +0900 |
parents | 63f36334e8dc |
children | 8d7c74610b05 |
files | test/channeltest/testNetworkSimulator.java test/channeltest/testSeMa.java |
diffstat | 2 files changed, 24 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/test/channeltest/testNetworkSimulator.java Fri Aug 29 21:19:14 2008 +0900 +++ b/test/channeltest/testNetworkSimulator.java Fri Aug 29 21:39:13 2008 +0900 @@ -15,7 +15,7 @@ static public REPLogger logger = REPLogger.singleton(); public static void main(String[] args){ - REPServerSocketChannel.isSimulation = true; + REPServerSocketChannel.isSimulation = false; testNetworkSimulator testns = new testNetworkSimulator(1, 0, 2); logger.setLogLevel(5); @@ -54,6 +54,12 @@ sm.start(); } logger.writeLog("all slave SessionManagers were created",1); + synchronized (this) { + try { + wait(100); + } catch (InterruptedException e) { + } + } for (int i=0; i<NoEditor; i++){ testEditor te = new testEditor("Editor"+i,host, masterPort+rand.nextInt(NoSemaMaster+NoSemaSlave)); editorList.add(te); @@ -66,11 +72,15 @@ for (testEditor te: editorList) te.join(); logger.writeLog("main: all clients exited."); + for (testSeMa te: semaList) + te.join(); + for (testSeMaSlave te: semasList) + te.join(); } catch (InterruptedException e) { e.printStackTrace(); } - System.exit(0); + //System.exit(0); } public void Checker(){
--- a/test/channeltest/testSeMa.java Fri Aug 29 21:19:14 2008 +0900 +++ b/test/channeltest/testSeMa.java Fri Aug 29 21:39:13 2008 +0900 @@ -5,8 +5,11 @@ import java.net.SocketAddress; import java.nio.channels.SelectionKey; import java.util.LinkedList; +import java.util.Set; import rep.channel.REPLogger; +import rep.channel.REPPack; +import rep.channel.REPSelectionKey; import rep.channel.REPSelector; import rep.channel.REPServerSocketChannel; import rep.channel.REPSocketChannel; @@ -33,9 +36,10 @@ REPSelector selector=null; REPServerSocketChannel<String> scs; + REPPack pack = new StringPacker(); try { - selector = REPSelector.create(); - scs = REPServerSocketChannel.<String>open(new StringPacker()); + selector = REPSelector.<String>create(); + scs = REPServerSocketChannel.<String>open(pack); scs.socket().setReuseAddress(true); scs.socket().bind(IP); scs.configureBlocking(false); @@ -48,29 +52,27 @@ ns.writeLog("selector is "+selector.toString()); ns.writeLog("REPssc is "+scs.toString()); - ns.writeLog("SessionManager starts mainroutin.", 1); + ns.writeLog("SessionManager starts main routine.", 1); /* Main Loop */ while(running){ try { selector.select(); - - for(SelectionKey key : selector.selectedKeys()){ + Set<REPSelectionKey<String>> set = selector.selectedKeys1(); + for(REPSelectionKey<String> key : set) { if(key.isAcceptable()){ ns.writeLog("gets acceptable channel", 1); - REPServerSocketChannel<String> sc = (REPServerSocketChannel<String>) key.channel(); - REPSocketChannel<String> channel; - channel = sc.accept1(); - //selector.register(channel, SelectionKey.OP_READ, null); + REPSocketChannel<String> channel = key.accept(pack); + channel.configureBlocking(false); channel.register(selector, SelectionKey.OP_READ, null); ns.writeLog("accepts a client.", 1); }else if(key.isReadable()){ ns.writeLog("gets readable channel", 1); //SelectableChannelSimulator<String> channel = key.channel(); - REPSocketChannel<String> channel = (REPSocketChannel<String>) key.channel(); + REPSocketChannel<String> channel = (REPSocketChannel<String>) key.channel(pack); String packet; packet = channel.read(); ns.writeLog("receives String==> `"+packet+"\'", 1);