# HG changeset patch # User kent # Date 1219926127 -32400 # Node ID 5653cf8e3c8b2e349923c5f4af75b615e3c943d9 # Parent 72252e970a8bbda95a14960c571afc39d6f62d71 *** empty log message *** diff -r 72252e970a8b -r 5653cf8e3c8b rep/channel/ChannelSimulator.java --- a/rep/channel/ChannelSimulator.java Thu Aug 28 19:49:41 2008 +0900 +++ b/rep/channel/ChannelSimulator.java Thu Aug 28 21:22:07 2008 +0900 @@ -32,14 +32,10 @@ /** Connecting methods */ // for clients. - public boolean connect(int ip){ + public boolean connect(SocketAddress ip){ return ns.connect(ip, this); } - public boolean connect(SocketAddress semaIP) throws IOException { - int ip = ns.nslookup(semaIP); - return ns.connect(ip, this); - } public ChannelSimulator

accept(){ return null; diff -r 72252e970a8b -r 5653cf8e3c8b rep/channel/NetworkSimulator.java --- a/rep/channel/NetworkSimulator.java Thu Aug 28 19:49:41 2008 +0900 +++ b/rep/channel/NetworkSimulator.java Thu Aug 28 21:22:07 2008 +0900 @@ -11,7 +11,7 @@ public HashMapnamedb = new HashMap(); public int ipcount = 1; - @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked") // から へのキャストのため. public static NetworkSimulator singleton(){ // double check singleton if (ns==null) @@ -32,19 +32,17 @@ writeLog("construct Networksimulator", 1); printAllState(); } - - /* */ - synchronized public void listen(int ip, SelectorSimulator selector) { + synchronized public void listen(SocketAddress ip, SelectorSimulator selector) { serverList.add(new ServerData

(ip, selector)); writeLog("listen", 1); printAllState(); } - synchronized public ChannelSimulator

accept(int ip) { + synchronized public ChannelSimulator

accept(SocketAddress ip) { for (ServerData

sd: serverList){ - if (sd.virtualIP!=ip) continue; + if (!sd.IP.equals(ip)) continue; writeLog("accepting..", 1); ChannelSimulator

serverCH = sd.acceptWaitingList.remove(); @@ -56,23 +54,24 @@ } return null; } - synchronized public boolean canAccept(int ip){ + synchronized public boolean canAccept(SocketAddress ip){ for (ServerData

sd: serverList){ - if (sd.virtualIP!=ip) continue; + if (!sd.IP.equals(ip)) continue; return !sd.acceptWaitingList.isEmpty(); } return false; } - public boolean connect(int ip, ChannelSimulator

clientCH) { + public boolean connect(SocketAddress ip, ChannelSimulator

clientCH) { ServerData

sd = null; writeLog("connecting..", 1); synchronized (this){ for (ServerData

sd0: serverList){ - if (sd0.virtualIP!=ip) continue; - - sd = sd0; - } + if (sd0.IP.equals(ip)){ + sd=sd0; + break; + } + } if (sd==null) return false; //ChannelSimulator

channel = new ChannelSimulator

(sd.selector); @@ -96,7 +95,7 @@ synchronized void printAllState(){ writeLog("NetworkSimulator State:"); for (ServerData

sd: serverList){ - writeLog("\tSessionManager(ip="+sd.virtualIP+"): "); + writeLog("\tSessionManager(ip="+sd.IP.toString()+"): "); writeLog("\tacceptWaitingList="+sd.acceptWaitingList.size()); writeLog("\testablishedList="+sd.establishedList.size()); } @@ -116,13 +115,14 @@ } class ServerData

{ - int virtualIP; + //int virtualIP; + SocketAddress IP; SelectorSimulator selector; LinkedList> acceptWaitingList; LinkedList> establishedList; - ServerData(int ip, SelectorSimulator _selector){ - virtualIP = ip; + ServerData(SocketAddress ip, SelectorSimulator _selector){ + IP = ip; selector = _selector; acceptWaitingList = new LinkedList>(); establishedList = new LinkedList>(); diff -r 72252e970a8b -r 5653cf8e3c8b rep/channel/REPServerSocket.java --- a/rep/channel/REPServerSocket.java Thu Aug 28 19:49:41 2008 +0900 +++ b/rep/channel/REPServerSocket.java Thu Aug 28 21:22:07 2008 +0900 @@ -17,7 +17,7 @@ scs = channel; } - public void bind(int ip){ + public void bind(SocketAddress ip){ scs.bind(ip); } diff -r 72252e970a8b -r 5653cf8e3c8b rep/channel/SelectionKeySimulator.java --- a/rep/channel/SelectionKeySimulator.java Thu Aug 28 19:49:41 2008 +0900 +++ b/rep/channel/SelectionKeySimulator.java Thu Aug 28 21:22:07 2008 +0900 @@ -63,14 +63,27 @@ return true; } - @Override - public int readyOps() { - return ready; - } @Override public Selector selector() { return selector; } + @Override + public int readyOps() { + int ops=0; + //if ( channel instanceof SelectableChannelSimulator){ + if ( channel instanceof ServerChannelSimulator ){ + ServerChannelSimulator scs = (ServerChannelSimulator) channel; + ops = ( OP_ACCEPT * (scs.isAcceptable()? 1:0) ); + } + if ( channel instanceof ChannelSimulator ){ + ChannelSimulator scs = (ChannelSimulator) channel; + ops = ( OP_READ * (scs.isReadable()? 1:0) ) + | ( OP_WRITE * (scs.isWritable()? 1:0) ); + // (OP_READ & true) がつかえないらしい. + } + return ops; + } + } diff -r 72252e970a8b -r 5653cf8e3c8b rep/channel/SelectorSimulator.java --- a/rep/channel/SelectorSimulator.java Thu Aug 28 19:49:41 2008 +0900 +++ b/rep/channel/SelectorSimulator.java Thu Aug 28 21:22:07 2008 +0900 @@ -23,7 +23,7 @@ keyList = new TreeSet(); } - @SuppressWarnings("unchecked") + //@SuppressWarnings("unchecked") public int select() throws IOException { selectedKeys = new TreeSet(); diff -r 72252e970a8b -r 5653cf8e3c8b rep/channel/ServerChannelSimulator.java --- a/rep/channel/ServerChannelSimulator.java Thu Aug 28 19:49:41 2008 +0900 +++ b/rep/channel/ServerChannelSimulator.java Thu Aug 28 21:22:07 2008 +0900 @@ -2,6 +2,7 @@ import java.io.IOException; import java.net.ServerSocket; +import java.net.SocketAddress; import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; @@ -10,20 +11,21 @@ public class ServerChannelSimulator

extends REPServerSocketChannel

{ protected NetworkSimulator

ns; //public REPServerSocket> socket; - protected int virtualIP; + protected SocketAddress IP; /** Constructors. * @throws IOException */ public ServerChannelSimulator() throws IOException { //socket = REPServerSocket.>create(); + ns = NetworkSimulator.

singleton(); } - public void bind(int ip){ - virtualIP = ip; + public void bind(SocketAddress ip){ + IP = ip; } public REPSocketChannel

accept1() /*throws IOException*/ { - return ns.accept(virtualIP); + return ns.accept(IP); } @Override @@ -55,9 +57,12 @@ public SelectionKey register(REPSelector sel, int ops, Object att) throws ClosedChannelException { REPSelector selector = sel; - ns.listen(virtualIP, (SelectorSimulator) selector); + ns.listen(IP, (SelectorSimulator) selector); return selector.register(this, ops, att); } + public boolean isAcceptable() { + return ns.canAccept(IP); + } } diff -r 72252e970a8b -r 5653cf8e3c8b test/channeltest/testNetworkSimulator.java --- a/test/channeltest/testNetworkSimulator.java Thu Aug 28 19:49:41 2008 +0900 +++ b/test/channeltest/testNetworkSimulator.java Thu Aug 28 21:22:07 2008 +0900 @@ -17,7 +17,7 @@ public static void main(String[] args){ REPServerSocketChannel.isSimulation = true; testNetworkSimulator testns = new testNetworkSimulator(1, 0, 2); - + logger.setLogLevel(5); testns.startTest(); } diff -r 72252e970a8b -r 5653cf8e3c8b test/channeltest/testSeMa.java --- a/test/channeltest/testSeMa.java Thu Aug 28 19:49:41 2008 +0900 +++ b/test/channeltest/testSeMa.java Thu Aug 28 21:22:07 2008 +0900 @@ -39,10 +39,14 @@ scs.socket().setReuseAddress(true); scs.socket().bind(IP); scs.configureBlocking(false); - selector.register(scs, SelectionKey.OP_ACCEPT, null); + //selector.register(scs, SelectionKey.OP_ACCEPT, null); + scs.register(selector, SelectionKey.OP_ACCEPT, null); } catch (IOException e1) { + ns.writeLog("cannot create REPServerSocketChannel!, exit."); return; } + ns.writeLog("selector is "+selector.toString()); + ns.writeLog("REPssc is "+scs.toString()); ns.writeLog("SessionManager starts mainroutin.", 1); @@ -59,7 +63,8 @@ REPServerSocketChannel sc = (REPServerSocketChannel) key.channel(); REPSocketChannel channel; channel = sc.accept1(); - selector.register(channel, SelectionKey.OP_READ, null); + //selector.register(channel, SelectionKey.OP_READ, null); + channel.register(selector, SelectionKey.OP_READ, null); ns.writeLog("accepts a client.", 1); }else if(key.isReadable()){