Mercurial > hg > RemoteEditor > REPSessionManager
view rep/channel/REPSelector.java @ 217:4deaaaa6354e
*** empty log message ***
author | kono |
---|---|
date | Sun, 31 Aug 2008 00:26:35 +0900 |
parents | 3e0cd34d625d |
children | 13e0520470dc |
line wrap: on
line source
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; import java.nio.channels.spi.SelectorProvider; import java.util.HashSet; import java.util.Set; public class REPSelector<P> extends Selector{ Selector selector; public REPSelector(AbstractSelector selector) { this.selector = selector; } public static <T>REPSelector<T> create() throws IOException{ if(REPServerSocketChannel.isSimulation){ return new SelectorSimulator<T>(); } return new REPSelector<T>(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(); } public SelectionKey register(SelectableChannel ch, int ops, Object att) throws ClosedChannelException{ return ch.register(selector, ops, att); } public Set<REPSelectionKey<P>> selectedKeys1() { Set<SelectionKey> keys = selector.selectedKeys(); HashSet<REPSelectionKey<P>> newKeys = new HashSet<REPSelectionKey<P>>(); for(SelectionKey k: keys) { newKeys.add(new REPSelectionKey<P>(k)); } return newKeys; } }