changeset 157:f0d80a64aba0

*** empty log message ***
author kono
date Thu, 28 Aug 2008 16:20:17 +0900
parents 31334767e65d
children 5cc8cd48bded
files test/channeltest/testNetworkSimulator.java test/channeltest/testSeMa.java test/channeltest/testSeMaSlave.java
diffstat 3 files changed, 50 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/test/channeltest/testNetworkSimulator.java	Thu Aug 28 16:11:18 2008 +0900
+++ b/test/channeltest/testNetworkSimulator.java	Thu Aug 28 16:20:17 2008 +0900
@@ -2,7 +2,6 @@
 
 import java.util.ArrayList;
 import java.util.Random;
-import pathfinder.mergetest.channels.NetworkSimulator;
 import rep.channel.REPLogger;
 
 public class testNetworkSimulator {
@@ -23,8 +22,6 @@
 
 	/** Constructor. */
 	public testNetworkSimulator(int sm, int ss,int e){
-		//ns = new NetworkSimulator<String>();
-		ns = NetworkSimulator.singleton();
 		semaList = new ArrayList<testSeMa>();
 		semasList = new ArrayList<testSeMaSlave>();
 		editorList = new ArrayList<testEditor>();
--- a/test/channeltest/testSeMa.java	Thu Aug 28 16:11:18 2008 +0900
+++ b/test/channeltest/testSeMa.java	Thu Aug 28 16:20:17 2008 +0900
@@ -1,33 +1,48 @@
 package test.channeltest;
 
 import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.nio.channels.SelectionKey;
 import java.util.LinkedList;
 
-import pathfinder.mergetest.channels.*;
+import rep.channel.REPLogger;
+import rep.channel.REPSelector;
+import rep.channel.REPServerSocketChannel;
+import rep.channel.REPSocketChannel;
+import sun.nio.ch.SocketOpts.IP;
 
 
 public class testSeMa extends Thread{
 
-	int IP;
+	SocketAddress IP;
 	boolean running=true;
-	NetworkSimulator<String> ns;
-	LinkedList<ChannelSimulator<String>> channels;
+	REPLogger ns;
+	LinkedList<REPSocketChannel<String>> channels;
 	
-	public testSeMa(NetworkSimulator<String> _ns, String name, int ip){
+	public testSeMa(REPLogger _ns, String name, String host, int port){
 		super(name);
-		IP = ip;
+		IP = new InetSocketAddress(host,port);
 		ns = _ns;
-		channels = new LinkedList<ChannelSimulator<String>>();
+		channels = new LinkedList<REPSocketChannel<String>>();
 	}
 	public void init(){
 		
 	}
 
+	@SuppressWarnings("unchecked")
 	public void run() {
-		SelectorSimulator<String> selector = new SelectorSimulator<String>();
-		ServerChannelSimulator<String> scs = new ServerChannelSimulator<String>(ns, selector);
-		scs.bind(IP);
-		selector.register(scs, SelectionKeySimulator.OP_ACCEPT);
+		REPSelector selector = new REPSelector(null);
+		REPServerSocketChannel<String> scs;
+		try {
+			scs = REPServerSocketChannel.<String>open();
+	        scs.socket().setReuseAddress(true);
+	        scs.socket().bind(IP);
+	        scs.configureBlocking(false);
+			selector.register(scs, SelectionKey.OP_ACCEPT, null);
+		} catch (IOException e1) {
+		}
+
 		ns.writeLog("SessionManager starts mainroutin.", 1);
 
 		/* Main Loop */
@@ -36,21 +51,29 @@
 			try { selector.select(); }
 			catch (IOException e) { e.printStackTrace();}
 
-			for(SelectionKeySimulator<String> key : selector.selectedKeys()){
+			for(SelectionKey key : selector.selectedKeys()){
 
 				if(key.isAcceptable()){
 					ns.writeLog(this, "gets acceptable channel", 1);
-					ServerChannelSimulator<String> sc = (ServerChannelSimulator<String>) key.channel();
-					ChannelSimulator<String> channel = sc.accept();
-					selector.register(channel, SelectionKeySimulator.OP_READ);
+					REPServerSocketChannel<String> sc = (REPServerSocketChannel<String>) key.channel();
+					REPSocketChannel<String> channel;
+					try {
+						channel = sc.accept1();
+						selector.register(channel, SelectionKey.OP_READ, null);
+					} catch (IOException e) {
+					}
 					ns.writeLog(this, "accepts a client.", 1);
 					
 				}else if(key.isReadable()){
 					ns.writeLog(this, "gets readable channel", 1);
 					//SelectableChannelSimulator<String> channel = key.channel();
-					ChannelSimulator<String> channel = (ChannelSimulator<String>) key.channel();
-					String packet = channel.read();
-					ns.writeLog(this, "receives String==> `"+packet+"\'", 1);
+					REPSocketChannel<String> channel = (REPSocketChannel<String>) key.channel();
+					try {
+						String packet;
+						packet = channel.read();
+						ns.writeLog(this, "receives String==> `"+packet+"\'", 1);
+					} catch (IOException e) {
+					}
 					channel.write("from SeMa"+this.getName()+": world");
 				}
 			}
--- a/test/channeltest/testSeMaSlave.java	Thu Aug 28 16:11:18 2008 +0900
+++ b/test/channeltest/testSeMaSlave.java	Thu Aug 28 16:20:17 2008 +0900
@@ -1,24 +1,24 @@
 package test.channeltest;
 
 import java.io.IOException;
+import java.net.SocketAddress;
 import java.util.LinkedList;
+import java.net.InetSocketAddress;
 
-import pathfinder.mergetest.channels.*;
-
+import rep.channel.REPLogger;
 
 public class testSeMaSlave extends Thread{
 
-	int ownIP;
-	int masterIP;
+	SocketAddress ownIP;
+	SocketAddress masterIP;
 	boolean running=true;
-	NetworkSimulator<String> ns;
+	REPLogger ns = new REPLogger();
 	LinkedList<ClientInfo> cis;
 	
-	public testSeMaSlave(NetworkSimulator<String> _ns, String name, int oIP, int mIP){
+	public testSeMaSlave(String name, String oname,int oport, String mname,int  mport){
 		super(name);
-		ownIP = oIP;
-		masterIP = mIP;
-		ns = _ns;
+		ownIP = new InetSocketAddress(oname,oport);
+		masterIP = new InetSocketAddress(mname,mport);
 		cis = new LinkedList<ClientInfo>();
 	}
 	public void init(){