# HG changeset patch # User kono # Date 1220066121 -32400 # Node ID 302c4a0afab673e903d1316ccfbeb68133ef29f8 # Parent 9aeade335af0ca6a06f1e71c6da0a53dbc25fdbb *** empty log message *** diff -r 9aeade335af0 -r 302c4a0afab6 rep/channel/REPSelectionKey.java --- a/rep/channel/REPSelectionKey.java Sat Aug 30 11:51:42 2008 +0900 +++ b/rep/channel/REPSelectionKey.java Sat Aug 30 12:15:21 2008 +0900 @@ -30,8 +30,14 @@ public SelectableChannel channel(REPPack

packer) { if (REPServerSocketChannel.isSimulation) return key.channel(); if (key.isAcceptable()) { + SelectableChannel sc = key.channel(); + SelectableChannel rsc = REPSocketChannel.channels.get(sc); + if (rsc!=null) return rsc; return new REPServerSocketChannel

(key.channel(),packer); } else if (key.isReadable()) { + SelectableChannel sc = key.channel(); + SelectableChannel rsc = REPSocketChannel.channels.get(sc); + if (rsc!=null) return rsc; return new REPSocketChannel

(key.channel(),packer); } return null; @@ -63,6 +69,7 @@ return key.selector(); // should return REPSelector } + @SuppressWarnings("unchecked") public REPSocketChannel

accept(REPPack

pack) throws IOException { assert(!REPServerSocketChannel.isSimulation); if (!key.isAcceptable()) throw new IOException(); @@ -70,6 +77,8 @@ if (ssc==null) return null; SocketChannel ss = (SocketChannel)ssc.accept(); if (ss==null) return null; + REPSocketChannel

rsc = (REPSocketChannel

)REPSocketChannel.channels.get(ss); + if (rsc!=null) return rsc; return new REPSocketChannel

(ss,pack); } diff -r 9aeade335af0 -r 302c4a0afab6 rep/channel/REPServerSocketChannel.java --- a/rep/channel/REPServerSocketChannel.java Sat Aug 30 11:51:42 2008 +0900 +++ b/rep/channel/REPServerSocketChannel.java Sat Aug 30 12:15:21 2008 +0900 @@ -38,14 +38,20 @@ } public REPServerSocketChannel(ServerSocketChannel open, REPPack

packer) { - ssc = open; this. - packer = packer; + ssc = open; + this.packer = packer; + REPSocketChannel.addChannel(ssc,this); } + public void close1() throws IOException { + REPSocketChannel.removeChannel(ssc); + ssc.close(); + } public REPServerSocketChannel(SelectableChannel channel, REPPack

packer) { this.ssc = (ServerSocketChannel)channel; this.packer = packer; + REPSocketChannel.addChannel(ssc,this); } public REPSocketChannel

accept1() throws IOException { diff -r 9aeade335af0 -r 302c4a0afab6 rep/channel/REPSocketChannel.java --- a/rep/channel/REPSocketChannel.java Sat Aug 30 11:51:42 2008 +0900 +++ b/rep/channel/REPSocketChannel.java Sat Aug 30 12:15:21 2008 +0900 @@ -10,22 +10,39 @@ import java.nio.channels.Selector; import java.nio.channels.SocketChannel; import java.nio.channels.spi.SelectorProvider; +import java.util.HashMap; public class REPSocketChannel

extends SelectableChannel{ public SocketChannel sc; private REPPack

pack; + static public HashMap channels = new HashMap(); public REPSocketChannel(SocketChannel channel, REPPack

packer) { sc = channel; pack = packer; + addChannel(sc,this); } public REPSocketChannel(SelectableChannel channel, REPPack

packer) { sc = (SocketChannel)channel; pack = packer; + addChannel(sc,this); + } + + public static void addChannel(SelectableChannel sc,SelectableChannel rc) { + channels.put(sc, rc); } + public void close1() throws IOException { + removeChannel(sc); + sc.close(); + } + + public static void removeChannel(SelectableChannel sc) throws IOException { + if(channels.containsKey(sc)) channels.remove(sc); + } + @Override public Object blockingLock() { return sc.blockingLock(); diff -r 9aeade335af0 -r 302c4a0afab6 test/channeltest/testNetworkSimulator.java --- a/test/channeltest/testNetworkSimulator.java Sat Aug 30 11:51:42 2008 +0900 +++ b/test/channeltest/testNetworkSimulator.java Sat Aug 30 12:15:21 2008 +0900 @@ -16,7 +16,7 @@ public static void main(String[] args){ REPServerSocketChannel.isSimulation = false; - testNetworkSimulator testns = new testNetworkSimulator(1, 0, 2); + testNetworkSimulator testns = new testNetworkSimulator(1, 2, 2); logger.setLogLevel(5); testns.startTest(); @@ -45,6 +45,7 @@ sm.start(); } logger.writeLog("all master SessionManagers were created",1); + sleep(100); slavePort = port; for (int i=0; i