Mercurial > hg > RemoteEditor > REPSessionManager
changeset 229:f816e0cbe6fd
*** empty log message ***
author | pin |
---|---|
date | Sun, 31 Aug 2008 17:08:55 +0900 |
parents | e6c7a56ff7f1 |
children | 43445986113b |
files | rep/SessionManager.java test/sematest/JoinTester.java test/sematest/PutTester.java test/sematest/Tester.java |
diffstat | 4 files changed, 41 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/SessionManager.java Sun Aug 31 15:27:04 2008 +0900 +++ b/rep/SessionManager.java Sun Aug 31 17:08:55 2008 +0900 @@ -92,7 +92,7 @@ continue; } int i = selector.select(); - System.out.println(i); + System.out.println("SessionManager.mainLoop():select:"+i); select(); } } @@ -120,18 +120,19 @@ if(key.isAcceptable()){ /*** serverChannelはenableになったSelectionKeyのchannel ***/ REPSocketChannel<REPCommand> channel = key.accept(new REPCommandPacker()); - registerChannel (selector, channel, SelectionKey.OP_READ); + registerChannel (channel, SelectionKey.OP_READ); channel = null; }else if(key.isReadable()){ REPHandler handler = (REPHandler)(key.attachment()); + handler.handle(key); } } } - private void registerChannel(REPSelector selector, SelectableChannel channel, int ops) throws IOException { + private void registerChannel(REPSocketChannel<REPCommand> channel, int ops) throws IOException { if(channel == null) { return; } @@ -491,7 +492,7 @@ System.out.print("test afro"); } System.out.println(""); - registerChannel(selector, sessionchannel, SelectionKey.OP_READ); + registerChannel(sessionchannel, SelectionKey.OP_READ); sm_join(sessionchannel);
--- a/test/sematest/JoinTester.java Sun Aug 31 15:27:04 2008 +0900 +++ b/test/sematest/JoinTester.java Sun Aug 31 17:08:55 2008 +0900 @@ -1,10 +1,9 @@ package test.sematest; -import java.io.IOException; +import java.util.LinkedList; import rep.REP; import rep.REPCommand; -import rep.channel.REPSocketChannel; public class JoinTester extends Tester { @@ -12,18 +11,15 @@ super(name, _host, _port); } - @Override - public void sendCommand(REPSocketChannel<REPCommand> channel)throws IOException { + public static void main(String[] args){ + REPCommand command = new REPCommand(); command.setCMD(REP.SMCMD_JOIN); - command.setString("join test"); - channel.write(command); + LinkedList<REPCommand> commandList = new LinkedList<REPCommand>(); + commandList.add(command); - channel.read(); - } - - public static void main(String[] args){ - Thread tester = new JoinTester("JoinTester", "localhost", 8766); + Tester tester = new JoinTester("JoinTester", "localhost", 8766); + tester.setCommands(commandList); tester.start(); }
--- a/test/sematest/PutTester.java Sun Aug 31 15:27:04 2008 +0900 +++ b/test/sematest/PutTester.java Sun Aug 31 17:08:55 2008 +0900 @@ -1,31 +1,26 @@ package test.sematest; -import java.io.IOException; +import java.util.LinkedList; import rep.REP; import rep.REPCommand; -import rep.channel.REPSocketChannel; public class PutTester extends Tester { public PutTester(String name, String _host, int _port) { super(name, _host, _port); } - - @Override - public void sendCommand(REPSocketChannel<REPCommand> channel)throws IOException { - + + public static void main(String[] args){ + REPCommand command = new REPCommand(); command.setCMD(REP.SMCMD_PUT); command.setString("PutTest.txt"); - channel.write(command); + LinkedList<REPCommand> commandList = new LinkedList<REPCommand>(); + commandList.add(command); - channel.read(); - - } - - public static void main(String[] args){ - Thread tester = new PutTester("PutTester", "localhost", 8766); + Tester tester = new PutTester("PutTester", "localhost", 8766); + tester.setCommands(commandList); tester.start(); }
--- a/test/sematest/Tester.java Sun Aug 31 15:27:04 2008 +0900 +++ b/test/sematest/Tester.java Sun Aug 31 17:08:55 2008 +0900 @@ -3,6 +3,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.util.List; import rep.REP; import rep.REPCommand; @@ -11,10 +12,12 @@ import rep.channel.REPServerSocketChannel; import rep.channel.REPSocketChannel; -public abstract class Tester extends Thread{ +public class Tester extends Thread{ private SocketAddress semaIP; private REPLogger ns; private boolean running = true; + private REPSocketChannel<REPCommand> channel; + private List<REPCommand> commandList; public Tester(String name, String _host,int _port){ super(name); @@ -27,7 +30,6 @@ public void run(){ try { - REPSocketChannel<REPCommand> channel; channel = REPSocketChannel.<REPCommand>create(new REPCommandPacker()); channel.configureBlocking(true); @@ -37,9 +39,8 @@ Thread.yield(); } ns.writeLog("successes to connect", 1); - - sendCommand(channel); - ns.writeLog("wrote packet", 1); + + sendCommands(); while(running){ REPCommand packet = channel.read(); @@ -56,5 +57,19 @@ } catch (IOException e) {} } - public abstract void sendCommand(REPSocketChannel<REPCommand> channel) throws IOException; + public void sendCommands(){ + if(commandList == null) return; + if(channel == null) return; + + for(REPCommand command: commandList){ + channel.write(command); + ns.writeLog("send command : "+command, 1); + } + + } + + public void setCommands(List<REPCommand> commands){ + commandList = commands; + } + }