changeset 156:31334767e65d

*** empty log message ***
author kono
date Thu, 28 Aug 2008 16:11:18 +0900
parents bbd2801d8ce0
children f0d80a64aba0
files rep/channel/NetworkSimulator.java rep/channel/REPServerSocket.java rep/channel/REPServerSocketChannel.java rep/channel/REPSocketChannel.java rep/channel/SelectableChannelSimulator.java rep/channel/ServerChannelSimulator.java rep/channel/ServerChannelSimulatorImpl.java
diffstat 7 files changed, 65 insertions(+), 141 deletions(-) [+]
line wrap: on
line diff
--- a/rep/channel/NetworkSimulator.java	Thu Aug 28 15:39:20 2008 +0900
+++ b/rep/channel/NetworkSimulator.java	Thu Aug 28 16:11:18 2008 +0900
@@ -1,11 +1,16 @@
 package rep.channel;
 
+import java.net.SocketAddress;
+import java.util.HashMap;
 import java.util.LinkedList;
 
 
 public class NetworkSimulator<P> extends REPLogger {
 	public static NetworkSimulator<?> ns;
 	
+	public HashMap<SocketAddress,Integer>namedb = new HashMap<SocketAddress,Integer>();
+	public int ipcount = 1;
+	
 	public static <T> NetworkSimulator<?> singleton(){
 		// double check singleton
 		if (ns==null)
@@ -95,6 +100,16 @@
 			writeLog("\testablishedList="+sd.establishedList.size());
 		}
 	}
+
+
+
+	public int nslookup(SocketAddress semaIP) {
+		Integer ip;
+		if ((ip=namedb.get(semaIP))==null) {
+			namedb.put(semaIP, (ip=ipcount++));
+		}
+		return ip;
+	}
 	
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rep/channel/REPServerSocket.java	Thu Aug 28 16:11:18 2008 +0900
@@ -0,0 +1,17 @@
+package rep.channel;
+
+import java.io.IOException;
+import java.nio.channels.SocketChannel;
+
+public class REPServerSocket<T> extends REPSocketChannel<T>{
+
+	public REPServerSocket(SocketChannel channel) {
+		super(channel);
+	}
+	
+
+	public static <T> REPServerSocket<T> create() throws IOException {
+		return new REPServerSocket<T>(null);
+	}
+
+}
--- a/rep/channel/REPServerSocketChannel.java	Thu Aug 28 15:39:20 2008 +0900
+++ b/rep/channel/REPServerSocketChannel.java	Thu Aug 28 16:11:18 2008 +0900
@@ -4,7 +4,6 @@
 import java.net.ServerSocket;
 import java.nio.channels.ClosedChannelException;
 import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
 import java.nio.channels.spi.SelectorProvider;
@@ -31,7 +30,7 @@
 
 	public static <T> REPServerSocketChannel<T> open() throws IOException{
 		if(isSimulation){
-			return new ServerChannelSimulatorImpl<T>(null);
+			return new ServerChannelSimulator<T>();
 		}else{
 			return new REPServerSocketChannel<T>(ServerSocketChannel.open());
 		}
@@ -67,4 +66,5 @@
 		REPSelector selector = sel;
 		return selector.register(this, ops, att);
 	}
+
 }
--- a/rep/channel/REPSocketChannel.java	Thu Aug 28 15:39:20 2008 +0900
+++ b/rep/channel/REPSocketChannel.java	Thu Aug 28 16:11:18 2008 +0900
@@ -121,7 +121,7 @@
 	public boolean connect(SocketAddress semaIP) throws IOException {
 		return sc.connect(semaIP);
 	}
-	
+
 	
 
 }
\ No newline at end of file
--- a/rep/channel/SelectableChannelSimulator.java	Thu Aug 28 15:39:20 2008 +0900
+++ b/rep/channel/SelectableChannelSimulator.java	Thu Aug 28 16:11:18 2008 +0900
@@ -1,12 +1,9 @@
 package rep.channel;
 
-import java.nio.channels.SelectableChannel;
 import java.nio.channels.SocketChannel;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 
-
-
 public abstract class SelectableChannelSimulator<P> extends REPSocketChannel<P>{
 
 	protected BlockingQueue<P> qread;
--- a/rep/channel/ServerChannelSimulator.java	Thu Aug 28 15:39:20 2008 +0900
+++ b/rep/channel/ServerChannelSimulator.java	Thu Aug 28 16:11:18 2008 +0900
@@ -1,110 +1,50 @@
 package rep.channel;
 
 import java.io.IOException;
+import java.net.ServerSocket;
 import java.nio.channels.ClosedChannelException;
-import java.nio.channels.SelectableChannel;
 import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.spi.SelectorProvider;
+import java.nio.channels.SocketChannel;
 
-
-
-public class ServerChannelSimulator<P>extends SelectableChannelSimulator<P>{
+public class ServerChannelSimulator<P>extends REPServerSocketChannel<P>{
 	protected NetworkSimulator<P> ns;
-	private int virtualIP;
+	public REPServerSocket<REPSocketChannel<P>> socket;
 
-	/**  Constructors. */
-	public ServerChannelSimulator(NetworkSimulator<P> _ns, SelectorSimulator rselector){
-		super(null);
-		ns = _ns;
-		readSelector = rselector;
-		writeSelector = null;
-		qread = null;
-		qwrite = null;
+	/**  Constructors. 
+	 * @throws IOException */
+	public ServerChannelSimulator() throws IOException {
+		socket = REPServerSocket.<REPSocketChannel<P>>create();
 	}
 
-	/** Connecting methods */
-	// for servers.
-	public void bind(int ip){
-		virtualIP = ip;
-		ns.listen(ip, readSelector);
-	}
-
-	public ChannelSimulator<P> accept(){
-		ChannelSimulator<P> channel = ns.accept(virtualIP);
-		return channel;
-	}
-
-
-	/* state check methods for SelectionKeySimulator. */
-	public boolean isReadable() {
-		return false;
-	}
-	public boolean isWritable() {
-		return false;
-	}
-	public boolean isAcceptable() {
-		return ns.canAccept(virtualIP);
+	public REPSocketChannel<P> accept1() throws IOException {
+		return new REPSocketChannel<P>(ss.accept());
 	}
 
 	@Override
-	public Object blockingLock() {
+	public ServerSocket socket() {
+		return socket;
+	}
+
+	@Override
+	protected void implCloseSelectableChannel() throws IOException {
+		ss.close();
+	}
+
+	@Override
+	protected void implConfigureBlocking(boolean block) throws IOException {
+		ss.configureBlocking(block);
+	}
+
+	@Override
+	public SocketChannel accept() throws IOException {
 		// TODO Auto-generated method stub
 		return null;
 	}
-
-	@Override
-	public SelectableChannel configureBlocking(boolean block) throws IOException {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public boolean isBlocking() {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-	@Override
-	public boolean isRegistered() {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-	@Override
-	public SelectionKey keyFor(Selector sel) {
-		// TODO Auto-generated method stub
-		return null;
-	}
+	
 
-	@Override
-	public SelectorProvider provider() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public int validOps() {
-		// TODO Auto-generated method stub
-		return 0;
-	}
-
-	@Override
-	protected void implCloseChannel() throws IOException {
-		// TODO Auto-generated method stub
-		
-	}
-
-	public static ServerSocketChannel open() {
-		// TODO Auto-generated method stub
-		return null;
+	public SelectionKey register(REPSelector sel, int ops, Object att) throws ClosedChannelException {
+		REPSelector selector = sel;
+		return selector.register(this, ops, att);
 	}
 
 }
--- a/rep/channel/ServerChannelSimulatorImpl.java	Thu Aug 28 15:39:20 2008 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-package rep.channel;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.SelectorProvider;
-
-public class ServerChannelSimulatorImpl<P> extends REPServerSocketChannel<P>{
-	
-
-	protected ServerChannelSimulatorImpl(SelectorProvider provider) {
-		super(provider);
-	}
-
-
-	@Override
-	public ServerSocket socket() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-
-	@Override
-	public SocketChannel accept() throws IOException {
-		// TODO Auto-generated method stub
-		
-		return null;
-	}
-
-
-	@Override
-	protected void implCloseSelectableChannel() throws IOException {
-		// TODO Auto-generated method stub
-		
-	}
-
-
-	@Override
-	protected void implConfigureBlocking(boolean block) throws IOException {
-		// TODO Auto-generated method stub
-		
-	}
-
-}