# HG changeset patch # User kent # Date 1219844890 -32400 # Node ID 785a3e8ea858042410669ef9daaff9d7d97d33ad # Parent abaf502e6d8fa1fce29c8bb576977a4b38b20c8d *** empty log message *** diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/ChannelSimulator.java --- a/rep/channel/ChannelSimulator.java Wed Aug 27 21:31:21 2008 +0900 +++ b/rep/channel/ChannelSimulator.java Wed Aug 27 22:48:10 2008 +0900 @@ -18,8 +18,8 @@ public ChannelSimulator(NetworkSimulator

_ns){ this(_ns, null); } - - public ChannelSimulator(NetworkSimulator

_ns, SelectorSimulator

_selector){ + + public ChannelSimulator(NetworkSimulator

_ns, SelectorSimulator _selector){ super(null); ns = _ns; //ns = NetworkSimulator.singleton(); //どっちがいい? @@ -69,7 +69,7 @@ } public SelectionKey keyFor(Selector selector2) { - return ((SelectorSimulator

) selector2).getKey(this); + return ((SelectorSimulator) selector2).getKey(this); } @Override public Object blockingLock() { @@ -97,11 +97,17 @@ // TODO Auto-generated method stub return null; } + @SuppressWarnings("unchecked") @Override public SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException { - // TODO Auto-generated method stub - return null; + 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); + } + @Override public int validOps() { // TODO Auto-generated method stub diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/NetworkSimulator.java --- a/rep/channel/NetworkSimulator.java Wed Aug 27 21:31:21 2008 +0900 +++ b/rep/channel/NetworkSimulator.java Wed Aug 27 22:48:10 2008 +0900 @@ -26,7 +26,7 @@ /* */ - synchronized public void listen(int ip, SelectorSimulator

selector) { + synchronized public void listen(int ip, SelectorSimulator selector) { serverList.add(new ServerData

(ip, selector)); writeLog(Thread.currentThread(), "listen", 1); printAllState(); @@ -113,11 +113,11 @@ class ServerData

{ int virtualIP; - SelectorSimulator

selector; + SelectorSimulator selector; LinkedList> acceptWaitingList; LinkedList> establishedList; - ServerData(int ip, SelectorSimulator

_selector){ + ServerData(int ip, SelectorSimulator _selector){ virtualIP = ip; selector = _selector; acceptWaitingList = new LinkedList>(); diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/REPSelector.java --- a/rep/channel/REPSelector.java Wed Aug 27 21:31:21 2008 +0900 +++ b/rep/channel/REPSelector.java Wed Aug 27 22:48:10 2008 +0900 @@ -1,6 +1,8 @@ package rep.channel; import java.io.IOException; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.nio.channels.spi.AbstractSelector; @@ -15,7 +17,7 @@ this.selector = selector; } - static REPSelector create() throws IOException{ + public static REPSelector create() throws IOException{ if(REPServerSocketChannel.isSimulation){ return new SelectorSimulator(); } @@ -67,4 +69,9 @@ return selector.wakeup(); } + public SelectionKey register(SelectableChannel ch, int ops, Object att){ + return null; + } + + } diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/REPServerSocketChannel.java --- a/rep/channel/REPServerSocketChannel.java Wed Aug 27 21:31:21 2008 +0900 +++ b/rep/channel/REPServerSocketChannel.java Wed Aug 27 22:48:10 2008 +0900 @@ -2,6 +2,9 @@ import java.io.IOException; import java.net.ServerSocket; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.nio.channels.spi.SelectorProvider; @@ -26,11 +29,11 @@ } - public REPServerSocketChannel

create() throws IOException { + public static REPServerSocketChannel open() throws IOException{ if(isSimulation){ - return new ServerChannelSimulatorImpl

(null).open(); + return new ServerChannelSimulatorImpl(null); }else{ - return new REPServerSocketChannel

(open()); + return new REPServerSocketChannel(ServerSocketChannel.open()); } } @@ -58,4 +61,10 @@ // TODO Auto-generated method stub return null; } + + + public SelectionKey register(REPSelector sel, int ops, Object att) throws ClosedChannelException { + REPSelector selector = sel; + return selector.register(this, ops, att); + } } diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/REPSocketChannel.java --- a/rep/channel/REPSocketChannel.java Wed Aug 27 21:31:21 2008 +0900 +++ b/rep/channel/REPSocketChannel.java Wed Aug 27 22:48:10 2008 +0900 @@ -83,6 +83,10 @@ // TODO Auto-generated method stub return null; } + + public void read(P p){ + + } public REPSocketChannel

create() throws IOException { if (REPServerSocketChannel.isSimulation) { diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/SelectableChannelSimulator.java --- a/rep/channel/SelectableChannelSimulator.java Wed Aug 27 21:31:21 2008 +0900 +++ b/rep/channel/SelectableChannelSimulator.java Wed Aug 27 22:48:10 2008 +0900 @@ -11,8 +11,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); @@ -65,7 +65,7 @@ public void createWriteQ(){ qwrite = new LinkedBlockingQueue

(); } - public void setWriteSelector(SelectorSimulator

_selector){ + public void setWriteSelector(SelectorSimulator _selector){ writeSelector = _selector; } diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/SelectionKeySimulator.java --- a/rep/channel/SelectionKeySimulator.java Wed Aug 27 21:31:21 2008 +0900 +++ b/rep/channel/SelectionKeySimulator.java Wed Aug 27 22:48:10 2008 +0900 @@ -1,16 +1,17 @@ package rep.channel; +import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; -public class SelectionKeySimulator extends SelectionKey{ +public class SelectionKeySimulator

extends SelectionKey{ private int interestOpt; - private SelectableChannelSimulator channel; + private SelectableChannel channel; private int ready; public Selector selector; - public SelectionKeySimulator(SelectableChannelSimulator cs, int opt, Selector _selector) { + public SelectionKeySimulator(SelectableChannel cs, int opt, Selector _selector) { channel = cs; interestOpt = opt; selector = _selector; @@ -28,26 +29,26 @@ } public void setFlag() { + SelectableChannelSimulator scs = (SelectableChannelSimulator) channel; ready = 0; - if(channel.isAcceptable()) ready |= OP_ACCEPT; - if(channel.isReadable()) ready |= OP_READ; - if(channel.isWritable()) ready |= OP_WRITE; + if(scs.isAcceptable()) ready |= OP_ACCEPT; + if(scs.isReadable()) ready |= OP_READ; + if(scs.isWritable()) ready |= OP_WRITE; } - public SelectableChannelSimulator channel() { + public SelectableChannel channel() { return channel; } @Override public void cancel() { - // TODO Auto-generated method stub - + System.err.println("cancel is not implemented yet."); + //selector. } @Override public int interestOps() { - // TODO Auto-generated method stub return interestOpt; } @@ -69,7 +70,6 @@ @Override public Selector selector() { - // TODO Auto-generated method stub return selector; } diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/SelectorSimulator.java --- a/rep/channel/SelectorSimulator.java Wed Aug 27 21:31:21 2008 +0900 +++ b/rep/channel/SelectorSimulator.java Wed Aug 27 22:48:10 2008 +0900 @@ -12,7 +12,7 @@ -public class SelectorSimulator

extends REPSelector{ +public class SelectorSimulator extends REPSelector{ private TreeSet keyList; private TreeSet selectedKeys; @@ -45,20 +45,20 @@ return selectedKeys.size(); } - public SelectionKeySimulator register(SelectableChannelSimulator

cs, int opt){ + public SelectionKeySimulator register(SelectableChannelSimulator cs, int opt){ SelectionKeySimulator key = new SelectionKeySimulator(cs, opt, this); keyList.add(key); return key; } - - public SelectionKeySimulator register(ChannelSimulator

cs, int opt, Object handler){ + + 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){ + public SelectionKey getKey(ChannelSimulator channel){ for(SelectionKey key : keyList){ if(key.channel() == channel) return key; diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/ServerChannelSimulator.java --- a/rep/channel/ServerChannelSimulator.java Wed Aug 27 21:31:21 2008 +0900 +++ b/rep/channel/ServerChannelSimulator.java Wed Aug 27 22:48:10 2008 +0900 @@ -15,7 +15,7 @@ private int virtualIP; /** Constructors. */ - public ServerChannelSimulator(NetworkSimulator

_ns, SelectorSimulator

rselector){ + public ServerChannelSimulator(NetworkSimulator

_ns, SelectorSimulator rselector){ super(null); ns = _ns; readSelector = rselector; diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/ServerChannelSimulatorImpl.java --- a/rep/channel/ServerChannelSimulatorImpl.java Wed Aug 27 21:31:21 2008 +0900 +++ b/rep/channel/ServerChannelSimulatorImpl.java Wed Aug 27 22:48:10 2008 +0900 @@ -41,9 +41,5 @@ // TODO Auto-generated method stub } - - public REPServerSocketChannel

open() { - return new ServerChannelSimulatorImpl

(null); - } }