Mercurial > hg > RemoteEditor > REPSessionManager
changeset 143:785a3e8ea858
*** empty log message ***
author | kent |
---|---|
date | Wed, 27 Aug 2008 22:48:10 +0900 |
parents | abaf502e6d8f |
children | 0bf7f8d0f5f7 |
files | rep/channel/ChannelSimulator.java rep/channel/NetworkSimulator.java rep/channel/REPSelector.java rep/channel/REPServerSocketChannel.java rep/channel/REPSocketChannel.java rep/channel/SelectableChannelSimulator.java rep/channel/SelectionKeySimulator.java rep/channel/SelectorSimulator.java rep/channel/ServerChannelSimulator.java rep/channel/ServerChannelSimulatorImpl.java |
diffstat | 10 files changed, 58 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- 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<P> _ns){ this(_ns, null); } - - public ChannelSimulator(NetworkSimulator<P> _ns, SelectorSimulator<P> _selector){ + + public ChannelSimulator(NetworkSimulator<P> _ns, SelectorSimulator _selector){ super(null); ns = _ns; //ns = NetworkSimulator.singleton(); //どっちがいい? @@ -69,7 +69,7 @@ } public SelectionKey keyFor(Selector selector2) { - return ((SelectorSimulator<P>) 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
--- 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<P> selector) { + synchronized public void listen(int ip, SelectorSimulator selector) { serverList.add(new ServerData<P>(ip, selector)); writeLog(Thread.currentThread(), "listen", 1); printAllState(); @@ -113,11 +113,11 @@ class ServerData<P> { int virtualIP; - SelectorSimulator<P> selector; + SelectorSimulator selector; LinkedList<ChannelSimulator<P>> acceptWaitingList; LinkedList<ChannelSimulator<P>> establishedList; - ServerData(int ip, SelectorSimulator<P> _selector){ + ServerData(int ip, SelectorSimulator _selector){ virtualIP = ip; selector = _selector; acceptWaitingList = new LinkedList<ChannelSimulator<P>>();
--- 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; + } + + }
--- 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<P> create() throws IOException { + public static <T> REPServerSocketChannel<T> open() throws IOException{ if(isSimulation){ - return new ServerChannelSimulatorImpl<P>(null).open(); + return new ServerChannelSimulatorImpl<T>(null); }else{ - return new REPServerSocketChannel<P>(open()); + return new REPServerSocketChannel<T>(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); + } }
--- 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<P> create() throws IOException { if (REPServerSocketChannel.isSimulation) {
--- 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<P> qread; protected BlockingQueue<P> qwrite; - protected SelectorSimulator<P> writeSelector; - protected SelectorSimulator<P> readSelector; + protected SelectorSimulator writeSelector; + protected SelectorSimulator readSelector; public SelectableChannelSimulator(SocketChannel channel) { super(channel); @@ -65,7 +65,7 @@ public void createWriteQ(){ qwrite = new LinkedBlockingQueue<P>(); } - public void setWriteSelector(SelectorSimulator<P> _selector){ + public void setWriteSelector(SelectorSimulator _selector){ writeSelector = _selector; }
--- 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<P> 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; }
--- 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<P> extends REPSelector{ +public class SelectorSimulator extends REPSelector{ private TreeSet<SelectionKey> keyList; private TreeSet<SelectionKey> selectedKeys; @@ -45,20 +45,20 @@ return selectedKeys.size(); } - public SelectionKeySimulator register(SelectableChannelSimulator<P> cs, int opt){ + public <T> SelectionKeySimulator register(SelectableChannelSimulator<T> cs, int opt){ SelectionKeySimulator key = new SelectionKeySimulator(cs, opt, this); keyList.add(key); return key; } - - public SelectionKeySimulator register(ChannelSimulator<P> cs, int opt, Object handler){ + + public <T> SelectionKeySimulator register(ChannelSimulator<T> cs, int opt, Object handler){ SelectionKeySimulator key = new SelectionKeySimulator(cs, opt, this); key.attach(handler); keyList.add(key); return key; } - public SelectionKey getKey(ChannelSimulator<P> channel){ + public <T> SelectionKey getKey(ChannelSimulator<T> channel){ for(SelectionKey key : keyList){ if(key.channel() == channel) return key;
--- 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<P> _ns, SelectorSimulator<P> rselector){ + public ServerChannelSimulator(NetworkSimulator<P> _ns, SelectorSimulator rselector){ super(null); ns = _ns; readSelector = rselector;
--- 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<P> open() { - return new ServerChannelSimulatorImpl<P>(null); - } }