Mercurial > hg > RemoteEditor > REPSessionManager
changeset 125:9faacdd6c9cb
*** empty log message ***
author | pin |
---|---|
date | Wed, 27 Aug 2008 17:54:47 +0900 |
parents | 97a321d91b79 |
children | 291c62984ba0 |
files | rep/channel/REPSelector.java rep/channel/SelectionKeySimulator.java rep/channel/SelectorSimulator.java |
diffstat | 3 files changed, 81 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/channel/REPSelector.java Wed Aug 27 17:54:47 2008 +0900 @@ -0,0 +1,70 @@ +package rep.channel; + +import java.io.IOException; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.spi.AbstractSelector; +import java.nio.channels.spi.SelectorProvider; +import java.util.Set; + +public class REPSelector extends Selector{ + + Selector selector; + + public REPSelector(AbstractSelector selector) { + this.selector = selector; + } + + static REPSelector create() throws IOException{ + if(REPServerSocketChannel.isSimulation){ + return new SelectorSimulator(); + } + return new REPSelector(SelectorProvider.provider().openSelector()); + } + + @Override + public void close() throws IOException { + selector.close(); + } + + @Override + public boolean isOpen() { + return selector.isOpen(); + } + + @Override + public Set<SelectionKey> keys() { + return selector.keys(); + } + + @Override + public SelectorProvider provider() { + return selector.provider(); + } + + @Override + public int select() throws IOException { + return selector.select(); + } + + @Override + public int select(long timeout) throws IOException { + return selector.select(timeout); + } + + @Override + public int selectNow() throws IOException { + return selector.selectNow(); + } + + @Override + public Set<SelectionKey> selectedKeys() { + return selector.selectedKeys(); + } + + @Override + public Selector wakeup() { + return selector.wakeup(); + } + +}
--- a/rep/channel/SelectionKeySimulator.java Wed Aug 27 17:21:25 2008 +0900 +++ b/rep/channel/SelectionKeySimulator.java Wed Aug 27 17:54:47 2008 +0900 @@ -3,14 +3,14 @@ import java.nio.channels.SelectionKey; import java.nio.channels.Selector; -public class SelectionKeySimulator<P> extends SelectionKey{ +public class SelectionKeySimulator extends SelectionKey{ private int interestOpt; - private SelectableChannelSimulator<P> channel; + private SelectableChannelSimulator channel; private int ready; public Selector selector; - public SelectionKeySimulator(SelectableChannelSimulator<P> cs, int opt, Selector _selector) { + public SelectionKeySimulator(SelectableChannelSimulator cs, int opt, Selector _selector) { channel = cs; interestOpt = opt; selector = _selector; @@ -34,7 +34,7 @@ if(channel.isWritable()) ready |= OP_WRITE; } - public SelectableChannelSimulator<P> channel() { + public SelectableChannelSimulator channel() { return channel; }
--- a/rep/channel/SelectorSimulator.java Wed Aug 27 17:21:25 2008 +0900 +++ b/rep/channel/SelectorSimulator.java Wed Aug 27 17:54:47 2008 +0900 @@ -12,13 +12,13 @@ -public class SelectorSimulator<P> extends Selector{ +public class SelectorSimulator<P> extends REPSelector{ private TreeSet<SelectionKey> keyList; private TreeSet<SelectionKey> selectedKeys; public SelectorSimulator() { - // TODO Auto-generated constructor stub + super(null); keyList = new TreeSet<SelectionKey>(); } @@ -30,7 +30,7 @@ while(selectedKeys.isEmpty()){ for(SelectionKey key : keyList){ - if(((SelectionKeySimulator<P>) key).isAble()) + if(((SelectionKeySimulator) key).isAble()) selectedKeys.add(key); } @@ -45,14 +45,14 @@ return selectedKeys.size(); } - public SelectionKeySimulator<P> register(SelectableChannelSimulator<P> cs, int opt){ - SelectionKeySimulator<P> key = new SelectionKeySimulator<P>(cs, opt, this); + public SelectionKeySimulator register(SelectableChannelSimulator<P> cs, int opt){ + SelectionKeySimulator key = new SelectionKeySimulator(cs, opt, this); keyList.add(key); return key; } - public SelectionKeySimulator<P> register(ChannelSimulator<P> cs, int opt, Object handler){ - SelectionKeySimulator<P> key = new SelectionKeySimulator<P>(cs, opt, this); + public SelectionKeySimulator register(ChannelSimulator<P> cs, int opt, Object handler){ + SelectionKeySimulator key = new SelectionKeySimulator(cs, opt, this); key.attach(handler); keyList.add(key); return key;