# HG changeset patch # User pin # Date 1220176208 -32400 # Node ID b837feb0013286fa033d3ed8441581d98d2453c8 # Parent 43445986113b4a3155cde78104f00335f67c3a0a *** empty log message *** diff -r 43445986113b -r b837feb00132 rep/SessionManager.java --- a/rep/SessionManager.java Sun Aug 31 17:54:52 2008 +0900 +++ b/rep/SessionManager.java Sun Aug 31 18:50:08 2008 +0900 @@ -7,6 +7,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -58,7 +59,7 @@ } public void openSelector() throws IOException{ - selector = REPSelector.create(); + selector = REPSelector.create(); } public void init(int port) throws InterruptedException, IOException { @@ -83,7 +84,7 @@ } - private void mainLoop() throws IOException { + public void mainLoop() throws IOException { while(true){ if(checkSend()){ if(selector.selectNow() > 0){ @@ -92,7 +93,6 @@ continue; } int i = selector.select(); - System.out.println("SessionManager.mainLoop():select:"+i); select(); } } @@ -116,16 +116,17 @@ while((e = waitingQueue.poll())!=null){ e.exec(); } - for(REPSelectionKey key : selector.selectedKeys1()){ + + Set> keys = selector.selectedKeys1(); + for(REPSelectionKey key : keys){ if(key.isAcceptable()){ - /*** serverChannelはenableになったSelectionKeyのchannel ***/ REPSocketChannel channel = key.accept(new REPCommandPacker()); + System.out.println("SessionManager.select() : channel = " + channel); registerChannel (channel, SelectionKey.OP_READ); channel = null; }else if(key.isReadable()){ REPHandler handler = (REPHandler)(key.attachment()); - handler.handle(key); } @@ -388,6 +389,10 @@ } private void guiUpdate() { + if(gui == null){ + //System.out.println("SessionManager.guiUpdate() : gui = " + gui); + return; + } //リストのコピーをGUIに渡す LinkedList sList = new LinkedList(sessionList); LinkedList eList = new LinkedList(editorList); diff -r 43445986113b -r b837feb00132 test/sematest/JoinTester.java --- a/test/sematest/JoinTester.java Sun Aug 31 17:54:52 2008 +0900 +++ b/test/sematest/JoinTester.java Sun Aug 31 18:50:08 2008 +0900 @@ -15,11 +15,12 @@ REPCommand command = new REPCommand(); command.setCMD(REP.SMCMD_JOIN); - LinkedList commandList = new LinkedList(); - commandList.add(command); + command.setString("JoinTester"); + LinkedList commands = new LinkedList(); + commands.add(command); - Tester tester = new JoinTester("JoinTester", "localhost", 8766); - tester.setCommands(commandList); + Tester tester = new PutTester("JoinTester", "localhost", 8766); + tester.setCommands(commands); tester.start(); } diff -r 43445986113b -r b837feb00132 test/sematest/PutTester.java --- a/test/sematest/PutTester.java Sun Aug 31 17:54:52 2008 +0900 +++ b/test/sematest/PutTester.java Sun Aug 31 18:50:08 2008 +0900 @@ -1,5 +1,6 @@ package test.sematest; +import java.nio.ByteBuffer; import java.util.LinkedList; import rep.REP; @@ -11,16 +12,28 @@ super(name, _host, _port); } + @Override + public void sendCommands(){ + if(commandList == null) return; + if(channel == null) return; + + REPCommand command = commandList.get(0); + for(int i = 0; i < 5; i++){ + channel.write(command); + ns.writeLog("send command : "+command, 1); + } + } + public static void main(String[] args){ REPCommand command = new REPCommand(); command.setCMD(REP.SMCMD_PUT); command.setString("PutTest.txt"); - LinkedList commandList = new LinkedList(); - commandList.add(command); + LinkedList commands = new LinkedList(); + commands.add(command); Tester tester = new PutTester("PutTester", "localhost", 8766); - tester.setCommands(commandList); + tester.setCommands(commands); tester.start(); } diff -r 43445986113b -r b837feb00132 test/sematest/TestSessionManager.java --- a/test/sematest/TestSessionManager.java Sun Aug 31 17:54:52 2008 +0900 +++ b/test/sematest/TestSessionManager.java Sun Aug 31 18:50:08 2008 +0900 @@ -17,13 +17,28 @@ int masterPort = 8766; String[] strs ={String.valueOf(masterPort), String.valueOf(masterPort)}; startSessionManager(strs); + + } private void startSessionManager(final String[] strs) { new Thread(new Runnable(){ public void run(){ try { - SessionManager.main(strs); + + int port = 8766; + + + if(strs.length > 0){ + port = Integer.parseInt(strs[0]); + } + + SessionManager sm = new SessionManager(port); + sm.openSelector(); + sm.init(port); + logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager"); + sm.mainLoop(); + } catch (InterruptedException e) { e.printStackTrace(); } catch (IOException e) { diff -r 43445986113b -r b837feb00132 test/sematest/Tester.java --- a/test/sematest/Tester.java Sun Aug 31 17:54:52 2008 +0900 +++ b/test/sematest/Tester.java Sun Aug 31 18:50:08 2008 +0900 @@ -14,10 +14,10 @@ public class Tester extends Thread{ private SocketAddress semaIP; - private REPLogger ns; + protected REPLogger ns; private boolean running = true; - private REPSocketChannel channel; - private List commandList; + protected REPSocketChannel channel; + protected List commandList; public Tester(String name, String _host,int _port){ super(name);