Mercurial > hg > RemoteEditor > REPSessionManager
view rep/channel/SelectorSimulator.java @ 123:5b1a0574b406 add-simulator
*** empty log message ***
author | pin |
---|---|
date | Wed, 27 Aug 2008 17:21:25 +0900 |
parents | |
children | 9faacdd6c9cb |
line wrap: on
line source
package rep.channel; import java.io.IOException; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.nio.channels.spi.SelectorProvider; import java.util.ArrayList; import java.util.Set; import java.util.TreeSet; //import java.util.Set; //ζΈγη΄γ? import java.util.Set; public class SelectorSimulator<P> extends Selector{ private TreeSet<SelectionKey> keyList; private TreeSet<SelectionKey> selectedKeys; public SelectorSimulator() { // TODO Auto-generated constructor stub keyList = new TreeSet<SelectionKey>(); } @SuppressWarnings("unchecked") public int select() throws IOException { selectedKeys = new TreeSet<SelectionKey>(); synchronized(this) { while(selectedKeys.isEmpty()){ for(SelectionKey key : keyList){ if(((SelectionKeySimulator<P>) 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 SelectionKeySimulator<P> register(SelectableChannelSimulator<P> cs, int opt){ SelectionKeySimulator<P> key = new SelectionKeySimulator<P>(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); key.attach(handler); keyList.add(key); return key; } public SelectionKey getKey(ChannelSimulator<P> 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; } }