Mercurial > hg > RemoteEditor > REPSessionManager
changeset 336:d00cb51ba652
*** empty log message ***
author | kono |
---|---|
date | Sun, 12 Oct 2008 18:06:54 +0900 |
parents | 5a78e73ecba5 |
children | 5ba5b7a9761b |
files | rep/SessionManager.java rep/channel/ChannelSimulator.java rep/channel/REPSocketChannel.java test/sematest/TestInterManagerSession.java test/sematest/TestSessionManager.java |
diffstat | 5 files changed, 57 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/SessionManager.java Sun Oct 12 15:09:46 2008 +0900 +++ b/rep/SessionManager.java Sun Oct 12 18:06:54 2008 +0900 @@ -55,8 +55,8 @@ private BlockingQueue<SessionManagerEvent> waitingEventQueue = new LinkedBlockingQueue<SessionManagerEvent>();; String myHost; private LinkedList<PacketSet> writeQueue = new LinkedList<PacketSet>(); - private static int receive_port; - private static int parent_port; + private int receive_port; + private int parent_port; static final int DEFAULT_PORT = 8766; private static final int packetLimit = 200; @@ -69,15 +69,20 @@ port = Integer.parseInt(args[0]); port_s = Integer.parseInt(args[1]); } - receive_port = port; - parent_port = port_s; SessionManager sm = new SessionManager(); + sm.setReceivePort(port); + sm.setParentPort(port_s); sm.init(port,new SessionManagerGUIimpl(sm)); } + public void setReceivePort(int port) { + receive_port = port; + } + + public void openSelector() throws IOException{ selector = REPSelector.<REPCommand>create(); } @@ -537,9 +542,8 @@ } private String getLocalHostName(REPSocketChannel<?> channel) { - String host = null; - host = channel.socket().getLocalAddress().getHostName(); - return host; + //host = channel.socket().getLocalAddress().getHostName(); + return channel.getLocalHostName(); } public void selectSession(SelectButtonEvent event) throws IOException {
--- a/rep/channel/ChannelSimulator.java Sun Oct 12 15:09:46 2008 +0900 +++ b/rep/channel/ChannelSimulator.java Sun Oct 12 18:06:54 2008 +0900 @@ -2,6 +2,7 @@ import java.io.IOException; import java.net.InetSocketAddress; +import java.net.Socket; import java.net.SocketAddress; import java.nio.channels.ClosedChannelException; import java.nio.channels.NotYetConnectedException; @@ -145,6 +146,21 @@ key = (SelectionKeySimulator<P>) sel.register(this, ops, att); return key; } + + + public boolean finishConnect() throws IOException { + return otherEnd!=null; + } + + public Socket socket() { + assert(false); + return null; + } + + @Override + public String getLocalHostName() { + return "localhost"; // always... + } public String toString(){ return "ChSim("+ownerName+")";
--- a/rep/channel/REPSocketChannel.java Sun Oct 12 15:09:46 2008 +0900 +++ b/rep/channel/REPSocketChannel.java Sun Oct 12 18:06:54 2008 +0900 @@ -172,4 +172,9 @@ return sc.register(sel, ops,att); } + public String getLocalHostName() { + return sc.socket().getLocalAddress().getHostName(); + + } + } \ No newline at end of file
--- a/test/sematest/TestInterManagerSession.java Sun Oct 12 15:09:46 2008 +0900 +++ b/test/sematest/TestInterManagerSession.java Sun Oct 12 18:06:54 2008 +0900 @@ -26,13 +26,17 @@ // executed before first select(); public void exec(SessionManager manager) { for(TestEditor editor:editors) { - if(editor.getPort()==masterPort) + if(editor.getPort()==manager.getPort()) { + logger.writeLog("Start client "+editor); editor.start(); + } } int i = sessionManagers.length; for(SessionManager slave:slaveSessionManagers) { - if (slave.getParentPort()==masterPort) + if (slave.getParentPort()==masterPort) { + logger.writeLog("Start slave "+slave); i = startSessionManager(slave,i,masterPort + i); + } } } }, @@ -42,8 +46,10 @@ public void exec(SessionManager manager) { manager.connectSession(host); for(TestEditor editor:editors) { - if(editor.getPort()==masterPort+1) - editor.start(); + if(editor.getPort()==manager.getPort()) { + logger.writeLog("Start client "+editor); + editor.start(); + } } } }, @@ -53,8 +59,10 @@ public void exec(SessionManager manager) { manager.connectSession(host); for(TestEditor editor:editors) { - if(editor.getPort()==masterPort+2) - editor.start(); + if(editor.getPort()==manager.getPort()) { + logger.writeLog("Start client "+editor); + editor.start(); + } } } } @@ -95,6 +103,15 @@ return ; } + @Override + protected void startTest() { + int i = 0; + for(SessionManager master:sessionManagers) { + logger.writeLog("Start master "+master); + i = startSessionManager(master,i, masterPort + i); + } + } + public static void main(String[] args){ /* * set simulation mode
--- a/test/sematest/TestSessionManager.java Sun Oct 12 15:09:46 2008 +0900 +++ b/test/sematest/TestSessionManager.java Sun Oct 12 18:06:54 2008 +0900 @@ -77,6 +77,7 @@ final int port1 = port; logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager"); // syncExec does not wake selector, do this before run(). + sm.setReceivePort(port1); setSMEvent(sm,i); Runnable start = new Runnable() { public void run() { @@ -87,7 +88,7 @@ } } }; - new Thread(start).run(); + new Thread(start).start(); return i+1; }