# HG changeset patch # User kono # Date 1220062903 -32400 # Node ID 4c0a948363576ec9961750a16a2e6f8db52cee6b # Parent ffedaf382e0ce5f88461900fbab51c718558d619 *** empty log message *** diff -r ffedaf382e0c -r 4c0a94836357 rep/channel/ChannelSimulator.java --- a/rep/channel/ChannelSimulator.java Sat Aug 30 11:15:31 2008 +0900 +++ b/rep/channel/ChannelSimulator.java Sat Aug 30 11:21:43 2008 +0900 @@ -56,19 +56,20 @@ } + @SuppressWarnings("unchecked") public SelectionKey keyFor(Selector selector2) { return ((SelectorSimulator) selector2).getKey(this); } + @SuppressWarnings("unchecked") @Override public SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException { - SelectorSimulator selector = (SelectorSimulator) sel; + SelectorSimulator

selector = (SelectorSimulator

) sel; return selector.register(this, ops, att); } - public SelectionKey register(REPSelector sel, int ops, Object att) throws ClosedChannelException { - REPSelector selector = sel; - return selector.register(this, ops, att); + public SelectionKey register(REPSelector

sel, int ops, Object att) throws ClosedChannelException { + return sel.register(this, ops, att); } diff -r ffedaf382e0c -r 4c0a94836357 rep/channel/NetworkSimulator.java --- a/rep/channel/NetworkSimulator.java Sat Aug 30 11:15:31 2008 +0900 +++ b/rep/channel/NetworkSimulator.java Sat Aug 30 11:21:43 2008 +0900 @@ -37,7 +37,7 @@ } /* */ - synchronized public void listen(SocketAddress ip, SelectorSimulator selector) { + synchronized public void listen(SocketAddress ip, SelectorSimulator

selector) { serverList.add(new ServerData

(ip, selector)); logger.writeLog("listen", 1); printAllState(); @@ -120,11 +120,11 @@ class ServerData

{ //int virtualIP; SocketAddress IP; - SelectorSimulator selector; + SelectorSimulator

selector; LinkedList> acceptWaitingList; LinkedList> establishedList; - ServerData(SocketAddress ip, SelectorSimulator _selector){ + ServerData(SocketAddress ip, SelectorSimulator

_selector){ IP = ip; selector = _selector; acceptWaitingList = new LinkedList>(); diff -r ffedaf382e0c -r 4c0a94836357 rep/channel/REPSelectionKey.java --- a/rep/channel/REPSelectionKey.java Sat Aug 30 11:15:31 2008 +0900 +++ b/rep/channel/REPSelectionKey.java Sat Aug 30 11:21:43 2008 +0900 @@ -5,6 +5,7 @@ import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; public class REPSelectionKey

extends SelectionKey { @@ -21,6 +22,8 @@ @Override public SelectableChannel channel() { + assert(false); + // use public SelectableChannel channel(REPPack

packer) instead return key.channel(); } @@ -28,9 +31,10 @@ if (REPServerSocketChannel.isSimulation) return key.channel(); if (key.isAcceptable()) { return new REPServerSocketChannel

(key.channel(),packer); - } else { + } else if (key.isReadable()) { return new REPSocketChannel

(key.channel(),packer); } + return null; } @Override @@ -55,13 +59,18 @@ @Override public Selector selector() { - return key.selector(); + assert(false); + return key.selector(); // should return REPSelector } public REPSocketChannel

accept(REPPack

pack) throws IOException { assert(!REPServerSocketChannel.isSimulation); - ServerSocketChannel sc = (ServerSocketChannel)key.channel(); - return new REPSocketChannel

(sc.accept(),pack); + if (!key.isAcceptable()) throw new IOException(); + ServerSocketChannel ssc = (ServerSocketChannel)key.channel(); + if (ssc==null) return null; + SocketChannel ss = (SocketChannel)ssc.accept(); + if (ss==null) return null; + return new REPSocketChannel

(ss,pack); } diff -r ffedaf382e0c -r 4c0a94836357 rep/channel/SelectableChannelSimulator.java --- a/rep/channel/SelectableChannelSimulator.java Sat Aug 30 11:15:31 2008 +0900 +++ b/rep/channel/SelectableChannelSimulator.java Sat Aug 30 11:21:43 2008 +0900 @@ -8,8 +8,8 @@ protected BlockingQueue

qread; protected BlockingQueue

qwrite; - protected SelectorSimulator writeSelector; - protected SelectorSimulator readSelector; + protected SelectorSimulator

writeSelector; + protected SelectorSimulator

readSelector; public SelectableChannelSimulator(SocketChannel channel) { super(channel, null); @@ -62,7 +62,7 @@ public void createWriteQ(){ qwrite = new LinkedBlockingQueue

(); } - public void setWriteSelector(SelectorSimulator _selector){ + public void setWriteSelector(SelectorSimulator

_selector){ writeSelector = _selector; } diff -r ffedaf382e0c -r 4c0a94836357 rep/channel/SelectorSimulator.java --- a/rep/channel/SelectorSimulator.java Sat Aug 30 11:15:31 2008 +0900 +++ b/rep/channel/SelectorSimulator.java Sat Aug 30 11:21:43 2008 +0900 @@ -18,7 +18,6 @@ keyList = new HashSet(); } - //@SuppressWarnings("unchecked") public int select() throws IOException { selectedKeys = new HashSet(); @@ -26,7 +25,7 @@ while(selectedKeys.isEmpty()){ for(SelectionKey key : keyList){ - if(((SelectionKeySimulator) key).isAble()) + if(((SelectionKeySimulator) key).isAble()) selectedKeys.add(key); } @@ -62,14 +61,6 @@ return newKeys;//(Set>)newKeys; } - /* - public SelectionKeySimulator register(ChannelSimulator cs, int opt, Object handler){ - SelectionKeySimulator key = new SelectionKeySimulator(cs, opt, this); - key.attach(handler); - keyList.add(key); - return key; - }*/ - public SelectionKey getKey(ChannelSimulator channel){ for(SelectionKey key : keyList){ if(key.channel() == channel) diff -r ffedaf382e0c -r 4c0a94836357 rep/channel/ServerChannelSimulator.java --- a/rep/channel/ServerChannelSimulator.java Sat Aug 30 11:15:31 2008 +0900 +++ b/rep/channel/ServerChannelSimulator.java Sat Aug 30 11:21:43 2008 +0900 @@ -7,7 +7,6 @@ import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; -import java.nio.channels.SocketChannel; import java.nio.channels.spi.SelectorProvider; /* シミュレーションの際にコンストラクトされる REPServerSocketChannel の実装 */ @@ -44,7 +43,7 @@ public SelectionKey register(REPSelector

sel, int ops, Object att) throws ClosedChannelException { REPSelector

selector = sel; - ns.listen(IP, (SelectorSimulator) selector); + ns.listen(IP, (SelectorSimulator

) selector); return selector.register(this, ops, att); } diff -r ffedaf382e0c -r 4c0a94836357 test/channeltest/testNetworkSimulator.java --- a/test/channeltest/testNetworkSimulator.java Sat Aug 30 11:15:31 2008 +0900 +++ b/test/channeltest/testNetworkSimulator.java Sat Aug 30 11:21:43 2008 +0900 @@ -53,7 +53,7 @@ semasList.add(sm); sm.start(); } - logger.writeLog("all slave SessionManagers were created",1); + logger.writeLog("all slave SessionManagers were created "+slavePort,1); synchronized (this) { try { wait(100); diff -r ffedaf382e0c -r 4c0a94836357 test/channeltest/testSeMa.java --- a/test/channeltest/testSeMa.java Sat Aug 30 11:15:31 2008 +0900 +++ b/test/channeltest/testSeMa.java Sat Aug 30 11:21:43 2008 +0900 @@ -65,6 +65,7 @@ if(key.isAcceptable()){ ns.writeLog("gets acceptable channel", 1); REPSocketChannel channel = key.accept(pack); + if(channel==null) continue; channel.configureBlocking(false); channel.register(selector, SelectionKey.OP_READ, null); ns.writeLog("accepts a client.", 1);