Mercurial > hg > RemoteEditor > REPSessionManager
changeset 231:b837feb00132
*** empty log message ***
author | pin |
---|---|
date | Sun, 31 Aug 2008 18:50:08 +0900 |
parents | 43445986113b |
children | 844c8f46584b |
files | rep/SessionManager.java test/sematest/JoinTester.java test/sematest/PutTester.java test/sematest/TestSessionManager.java test/sematest/Tester.java |
diffstat | 5 files changed, 51 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- 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.<REPCommand>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<REPCommand> key : selector.selectedKeys1()){ + + Set<REPSelectionKey<REPCommand>> keys = selector.selectedKeys1(); + for(REPSelectionKey<REPCommand> key : keys){ if(key.isAcceptable()){ - /*** serverChannelはenableになったSelectionKeyのchannel ***/ REPSocketChannel<REPCommand> 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<Session> sList = new LinkedList<Session>(sessionList); LinkedList<Editor> eList = new LinkedList<Editor>(editorList);
--- 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<REPCommand> commandList = new LinkedList<REPCommand>(); - commandList.add(command); + command.setString("JoinTester"); + LinkedList<REPCommand> commands = new LinkedList<REPCommand>(); + 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(); }
--- 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<REPCommand> commandList = new LinkedList<REPCommand>(); - commandList.add(command); + LinkedList<REPCommand> commands = new LinkedList<REPCommand>(); + commands.add(command); Tester tester = new PutTester("PutTester", "localhost", 8766); - tester.setCommands(commandList); + tester.setCommands(commands); tester.start(); }
--- 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) {
--- 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<REPCommand> channel; - private List<REPCommand> commandList; + protected REPSocketChannel<REPCommand> channel; + protected List<REPCommand> commandList; public Tester(String name, String _host,int _port){ super(name);