diff rep/SessionManager.java @ 231:b837feb00132

*** empty log message ***
author pin
date Sun, 31 Aug 2008 18:50:08 +0900
parents f816e0cbe6fd
children dae90ded1bcd
line wrap: on
line diff
--- a/rep/SessionManager.java	Sun Aug 31 17:54:52 2008 +0900
+++ b/rep/SessionManager.java	Sun Aug 31 18:50:08 2008 +0900
@@ -7,6 +7,7 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 
@@ -58,7 +59,7 @@
 	}
 	
 	public void openSelector() throws IOException{
-		selector = REPSelector.create();
+		selector = REPSelector.<REPCommand>create();
 	}
 	
 	public void init(int port) throws InterruptedException, IOException {
@@ -83,7 +84,7 @@
 
 	}
 
-	private void mainLoop() throws IOException {
+	public void mainLoop() throws IOException {
 		while(true){
 			if(checkSend()){
 				if(selector.selectNow() > 0){
@@ -92,7 +93,6 @@
 				continue;
 			}
 			int i = selector.select();
-			System.out.println("SessionManager.mainLoop():select:"+i);
 			select();
 		}
 	}
@@ -116,16 +116,17 @@
 		while((e = waitingQueue.poll())!=null){
 			e.exec();
 		}
-		for(REPSelectionKey<REPCommand> key : selector.selectedKeys1()){
+		
+		Set<REPSelectionKey<REPCommand>> keys = selector.selectedKeys1();
+		for(REPSelectionKey<REPCommand> key : keys){
 			if(key.isAcceptable()){
-				/*** serverChannelはenableになったSelectionKeyのchannel ***/
 				REPSocketChannel<REPCommand> channel = key.accept(new REPCommandPacker());
+				System.out.println("SessionManager.select() : channel = " + channel);
 				registerChannel (channel, SelectionKey.OP_READ);
 				channel = null;
 
 			}else if(key.isReadable()){
 				REPHandler handler = (REPHandler)(key.attachment());
-
 				handler.handle(key);
 				
 			}
@@ -388,6 +389,10 @@
 	}
 
 	private void guiUpdate() {
+		if(gui == null){
+			//System.out.println("SessionManager.guiUpdate() : gui = " + gui);
+			return;
+		}
 		//リストのコピーをGUIに渡す
 		LinkedList<Session> sList = new LinkedList<Session>(sessionList);
 		LinkedList<Editor> eList = new LinkedList<Editor>(editorList);