# HG changeset patch # User kono # Date 1224119958 -32400 # Node ID 59ef23ee73ada5d30413c59ea10aef45616444c7 # Parent ef4afcae0c92ab5acb4e2917e695d4c62329b239 SelectorSimulator is not thread safe now. diff -r ef4afcae0c92 -r 59ef23ee73ad rep/channel/SelectorSimulator.java --- a/rep/channel/SelectorSimulator.java Thu Oct 16 01:12:34 2008 +0900 +++ b/rep/channel/SelectorSimulator.java Thu Oct 16 10:19:18 2008 +0900 @@ -5,30 +5,34 @@ import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.nio.channels.spi.SelectorProvider; +import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; +import java.util.Map; import java.util.Set; public class SelectorSimulator
extends REPSelector
{
- // access to these set have to be synchronized
- private Set key : keyList.values()){
+ if(key.isAble())
+ selectedKeys.add(new SelectionKeySimulator (key));
}
}
@Override
- public synchronized int selectNow() throws IOException {
+ public int selectNow() throws IOException {
getSelectedKeys();
return selectedKeys.size();
}
@@ -69,39 +75,26 @@
return register(cs, opt, null);
}
public SelectionKeySimulator register(SelectableChannel cs, int opt, Object handler){
- SelectionKeySimulator key = new SelectionKeySimulator (cs, opt, this);
+ SelectionKeySimulator key = keyList.get(cs);
+ if (key!=null) {
+ key.attach(handler);
+ key.interestOps(opt);
+ return key;
+ }
+ key = new SelectionKeySimulator (cs, opt, this);
key.attach(handler);
- deregister(cs);
- synchronized(this) {
- keyList.add(key);
- }
+ keyList.put(cs,key);
return key;
}
- public synchronized void deregister(SelectableChannel channel) {
- for(Iterator deregister(SelectableChannel channel) {
+ SelectionKeySimulator key = keyList.remove(channel);
+ return key;
}
- public synchronized Set (k));
- }
- return newKeys;
- }
-
- public synchronized k: keyList.values()) {
+ // REPSelectionKeyを生成しないように注意
+ newKeys.add(k); //new SelectionKeySimulator (k));
+ }
+ return newKeys;
}
@Override
@@ -132,9 +141,26 @@
return this;
}
+
+ public Set k: selectedKeys) {
+ // REPSelectionKeyを生成しないように注意
+ //newKeys.add(new SelectionKeySimulator (k));
+ newKeys.add(k);
+ }
+ return newKeys;
+ }
+
@Override
- public synchronized Set k: keys) {
+ // REPSelectionKeyを生成しないように注意
+ newKeys.add(k); // new SelectionKeySimulator (k));
+ }
+ return newKeys;
}
}