Mercurial > hg > RemoteEditor > REPSessionManager
view rep/channel/SelectorSimulator.java @ 181:3a2c6c2f9761
*** empty log message ***
author | kent |
---|---|
date | Fri, 29 Aug 2008 13:30:46 +0900 |
parents | 9cf8147591ea |
children | 63701e2a2fe8 |
line wrap: on
line source
package rep.channel; import java.io.IOException; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.nio.channels.spi.SelectorProvider; import java.util.HashSet; import java.util.Set; public class SelectorSimulator extends REPSelector{ private Set<SelectionKey> keyList; private Set<SelectionKey> selectedKeys; public SelectorSimulator() { super(null); keyList = new HashSet<SelectionKey>(); } //@SuppressWarnings("unchecked") public int select() throws IOException { selectedKeys = new HashSet<SelectionKey>(); synchronized(this) { while(selectedKeys.isEmpty()){ for(SelectionKey key : keyList){ if(((SelectionKeySimulator) key).isAble()) selectedKeys.add(key); } if(selectedKeys.isEmpty()) try { this.wait(); } catch (InterruptedException e) { throw new IOException("Error, Selector was interrupted!"); } } } return selectedKeys.size(); } /* public <T> SelectionKeySimulator register(SelectableChannelSimulator<T> cs, int opt){ SelectionKeySimulator key = new SelectionKeySimulator(cs, opt, this); keyList.add(key); return key; }*/ public SelectionKeySimulator register(SelectableChannel cs, int opt, Object handler){ SelectionKeySimulator key = new SelectionKeySimulator(cs, opt, this); key.attach(handler); keyList.add(key); return key; } /* 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 <T> SelectionKey getKey(ChannelSimulator<T> channel){ for(SelectionKey key : keyList){ if(key.channel() == channel) return key; } return null; } @Override public void close() throws IOException { // TODO Auto-generated method stub } @Override public boolean isOpen() { // TODO Auto-generated method stub return false; } @Override public Set<SelectionKey> keys() { // TODO Auto-generated method stub return null; } @Override public SelectorProvider provider() { // TODO Auto-generated method stub return null; } @Override public int select(long timeout) throws IOException { // TODO Auto-generated method stub return 0; } @Override public int selectNow() throws IOException { // TODO Auto-generated method stub return 0; } @Override public Selector wakeup() { // TODO Auto-generated method stub return null; } @Override public Set<SelectionKey> selectedKeys() { // TODO Auto-generated method stub return (Set<SelectionKey>)selectedKeys; } }