diff rep/SessionManager.java @ 280:a549bd4dadb8

*** empty log message ***
author kono
date Sat, 27 Sep 2008 15:59:11 +0900
parents e58695b5118d
children c3969dd625b2
line wrap: on
line diff
--- a/rep/SessionManager.java	Sat Sep 27 14:48:02 2008 +0900
+++ b/rep/SessionManager.java	Sat Sep 27 15:59:11 2008 +0900
@@ -43,7 +43,7 @@
 public class SessionManager implements SessionManagerEventListener{
 	
 	private LinkedList<Session> sessionList;
-	private SessionManagerGUIimpl gui;
+	private SessionManagerGUI gui;
 	private REPSelector<REPCommand> selector;
 	private SessionManagerList smList;
 	private String myHost;
@@ -62,8 +62,16 @@
 	public void openSelector() throws IOException{
 		selector = REPSelector.<REPCommand>create();
 	}
-	
-	public void init(int port) throws InterruptedException, IOException {
+
+	public void init(int port, SessionManagerGUI gui) throws IOException, InterruptedException {
+		this.gui = gui;
+		openSelector();
+		init(port);
+		mainLoop(); 
+	}
+
+
+	private void init(int port) throws InterruptedException, IOException {
 	
 		REPServerSocketChannel<REPCommand> ssc = REPServerSocketChannel.<REPCommand>open(new REPCommandPacker());
 		ssc.configureBlocking(false);	//reuse address 必須
@@ -79,9 +87,9 @@
 		waitingQueue = new LinkedBlockingQueue<SessionManagerEvent>();
 		
 		//デフォルトのSessionを作っておく(テスト用に?)
-		if(sessionList.size() > 0) System.out.println("Error : SessionManager.init():");
-		Session defaultSession = new Session(sessionList.size(), "DefaultSession.txt", new Editor(0,null));
-		sessionList.add(defaultSession);
+		//if(sessionList.size() > 0) System.out.println("Error : SessionManager.init():");
+		//Session defaultSession = new Session(sessionList.size(), "DefaultSession.txt", new Editor(0,null));
+		//sessionList.add(defaultSession);
 
 	}
 
@@ -405,10 +413,10 @@
 		//リストのコピーをGUIに渡す
 		LinkedList<Session> sList = new LinkedList<Session>(sessionList);
 		LinkedList<Editor> eList = new LinkedList<Editor>(editorList);
-		for(Editor editor : eList){
-			System.out.println("SessionManager.guiUpdate() : channel = " + editor.getChannel());
-		}
-		
+//		for(Editor editor : eList){
+//			System.out.println("SessionManager.guiUpdate() : channel = " + editor.getChannel());
+//		}
+//		
 		//GUIに反映
 		Runnable doRun = new DoGUIUpdate(sList, eList, gui);
 		gui.invokeLater(doRun);
@@ -487,20 +495,11 @@
 		temp_port = port;
 		send_port = port_s;
 		SessionManager sm = new SessionManager(port);
-		sm.openSelector();
-		sm.init(port);
-		sm.startGUI(sm);
-		sm.mainLoop();
+		sm.init(port,new SessionManagerGUIimpl(sm));
+		
 
 	}
 
-	public void startGUI(SessionManager sm) {
-		gui = new SessionManagerGUIimpl();
-		Thread th = new Thread( gui ); 
-		th.start();
-		gui.addREPActionListener(this);
-	}
-
 	public void connectSession(String host) {
 		int port = DEFAULT_PORT;
 		port = send_port;