changeset 197:8d7c74610b05

*** empty log message ***
author kent
date Sat, 30 Aug 2008 00:00:51 +0900
parents b85525d83b46
children ff3fcdcccc85
files rep/channel/ChannelSimulator.java rep/channel/SelectionKeySimulator.java rep/channel/SelectorSimulator.java
diffstat 3 files changed, 27 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/rep/channel/ChannelSimulator.java	Fri Aug 29 21:39:13 2008 +0900
+++ b/rep/channel/ChannelSimulator.java	Sat Aug 30 00:00:51 2008 +0900
@@ -1,7 +1,9 @@
 package rep.channel;
 
+import java.io.IOException;
 import java.net.SocketAddress;
 import java.nio.channels.ClosedChannelException;
+import java.nio.channels.SelectableChannel;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 
@@ -48,6 +50,11 @@
 	public boolean isWritable() {
 		return true;
 	}
+	@Override
+	public SelectableChannel configureBlocking(boolean block) throws IOException {
+		return null;
+	}
+
 
 	public SelectionKey keyFor(Selector selector2) {
 		return ((SelectorSimulator) selector2).getKey(this);
--- a/rep/channel/SelectionKeySimulator.java	Fri Aug 29 21:39:13 2008 +0900
+++ b/rep/channel/SelectionKeySimulator.java	Sat Aug 30 00:00:51 2008 +0900
@@ -6,7 +6,7 @@
 import java.nio.channels.Selector;
 import java.nio.channels.ServerSocketChannel;
 
-public class SelectionKeySimulator extends SelectionKey{
+public class SelectionKeySimulator<P> extends REPSelectionKey<P>{
 	
 	private int interestOpt;
 	private SelectableChannel channel;
@@ -14,10 +14,17 @@
 	public Selector selector;
 
 	public SelectionKeySimulator(SelectableChannel cs, int opt, Selector _selector) {
+		super(null);
 		channel = cs;
 		interestOpt = opt;
 		selector = _selector;
 	}
+	public SelectionKeySimulator(SelectionKey k) {
+		super(null);
+		channel = k.channel();
+		interestOpt = k.interestOps();
+		selector = k.selector();
+	}
 
 	public boolean isAble() {
 		if ( (interestOpt&OP_READ)!=0 && isReadable() )
@@ -42,13 +49,14 @@
 		return channel;
 	}
 
-	public SelectableChannel channel(REPPack<?> packer) {
+	public SelectableChannel channel(REPPack<P> packer) {
 		return channel;
 	}
 
-	public REPSocketChannel<?> accept(REPPack<?> pack) throws IOException {
-		SelectableChannelSimulator<?> scs = (SelectableChannelSimulator<?>) channel;
-		return scs.accept();
+	public REPSocketChannel<P> accept(REPPack<P> pack) throws IOException {
+		assert(channel instanceof ServerChannelSimulator);
+		ServerChannelSimulator<P> scs = (ServerChannelSimulator<P>) channel;
+		return scs.accept1();
 	}
 
 	@Override
--- a/rep/channel/SelectorSimulator.java	Fri Aug 29 21:39:13 2008 +0900
+++ b/rep/channel/SelectorSimulator.java	Sat Aug 30 00:00:51 2008 +0900
@@ -41,11 +41,11 @@
 		return selectedKeys.size();
 	}
 
-	public SelectionKeySimulator register(SelectableChannel cs, int opt){
+	public SelectionKeySimulator<P> register(SelectableChannel cs, int opt){
 		return register(cs, opt, null);
 	}
-	public SelectionKeySimulator register(SelectableChannel cs, int opt, Object handler){
-		SelectionKeySimulator key = new SelectionKeySimulator(cs, opt, this);
+	public SelectionKeySimulator<P> register(SelectableChannel cs, int opt, Object handler){
+		SelectionKeySimulator<P> key = new SelectionKeySimulator<P>(cs, opt, this);
 		key.attach(handler);
 		keyList.add(key);
 		return key;
@@ -54,11 +54,12 @@
 
 	public Set<REPSelectionKey<P>> selectedKeys1() {
 			Set<SelectionKey> keys = keyList;
-			HashSet<REPSelectionKey<P>> newKeys = new HashSet<REPSelectionKey<P>>();
+			Set<REPSelectionKey<P>> newKeys = new HashSet<REPSelectionKey<P>>();
 			for(SelectionKey k: keys) {
-				newKeys.add(new REPSelectionKey<P>(k));
+				// REPSelectionKeyを生成しないように注意
+				newKeys.add(new SelectionKeySimulator<P>(k));
 			}
-			return (Set<REPSelectionKey<P>>)newKeys;
+			return newKeys;//(Set<REPSelectionKey<P>>)newKeys;
 	}
 	
 	/*