changeset 166:be2c1a1e9b8d

*** empty log message ***
author kono
date Thu, 28 Aug 2008 18:16:23 +0900
parents 9bb6bbb08ad7
children 3dc194f5e28f
files test/channeltest/testSeMa.java
diffstat 1 files changed, 24 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/test/channeltest/testSeMa.java	Thu Aug 28 18:04:50 2008 +0900
+++ b/test/channeltest/testSeMa.java	Thu Aug 28 18:16:23 2008 +0900
@@ -17,7 +17,7 @@
 	boolean running=true;
 	REPLogger ns;
 	LinkedList<REPSocketChannel<String>> channels;
-	
+
 	public testSeMa(String name, String host, int port){
 		super(name);
 		IP = new InetSocketAddress(host,port);
@@ -25,20 +25,22 @@
 		channels = new LinkedList<REPSocketChannel<String>>();
 	}
 	public void init(){
-		
+
 	}
 
 	@SuppressWarnings("unchecked")
 	public void run() {
-		REPSelector selector = new REPSelector(null);
+		REPSelector selector;
 		REPServerSocketChannel<String> scs;
 		try {
+			selector = REPSelector.create();
 			scs = REPServerSocketChannel.<String>open();
-	        scs.socket().setReuseAddress(true);
-	        scs.socket().bind(IP);
-	        scs.configureBlocking(false);
+			scs.socket().setReuseAddress(true);
+			scs.socket().bind(IP);
+			scs.configureBlocking(false);
 			selector.register(scs, SelectionKey.OP_ACCEPT, null);
 		} catch (IOException e1) {
+			return;
 		}
 
 		ns.writeLog("SessionManager starts mainroutin.", 1);
@@ -46,36 +48,32 @@
 		/* Main Loop */
 		while(running){
 
-			try { selector.select(); }
-			catch (IOException e) { e.printStackTrace();}
+			try { 
+				selector.select(); 
 
-			for(SelectionKey key : selector.selectedKeys()){
+				for(SelectionKey key : selector.selectedKeys()){
 
-				if(key.isAcceptable()){
-					ns.writeLog(this, "gets acceptable channel", 1);
-					REPServerSocketChannel<String> sc = (REPServerSocketChannel<String>) key.channel();
-					REPSocketChannel<String> channel;
-					try {
+					if(key.isAcceptable()){
+						ns.writeLog(this, "gets acceptable channel", 1);
+						REPServerSocketChannel<String> sc = (REPServerSocketChannel<String>) key.channel();
+						REPSocketChannel<String> channel;
 						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();
-					REPSocketChannel<String> channel = (REPSocketChannel<String>) key.channel();
-					try {
+						ns.writeLog(this, "accepts a client.", 1);
+
+					}else if(key.isReadable()){
+						ns.writeLog(this, "gets readable channel", 1);
+						//SelectableChannelSimulator<String> channel = key.channel();
+						REPSocketChannel<String> channel = (REPSocketChannel<String>) key.channel();
 						String packet;
 						packet = channel.read();
 						ns.writeLog(this, "receives String==> `"+packet+"\'", 1);
-					} catch (IOException e) {
+						channel.write("from SeMa"+this.getName()+": world");
 					}
-					channel.write("from SeMa"+this.getName()+": world");
 				}
 			}
+			catch (IOException e) { e.printStackTrace();}
 		}
-		
+
 	}
 }