Mercurial > hg > RemoteEditor > REPSessionManager
comparison rep/SessionManager.java @ 280:a549bd4dadb8
*** empty log message ***
author | kono |
---|---|
date | Sat, 27 Sep 2008 15:59:11 +0900 |
parents | e58695b5118d |
children | c3969dd625b2 |
comparison
equal
deleted
inserted
replaced
279:e58695b5118d | 280:a549bd4dadb8 |
---|---|
41 */ | 41 */ |
42 | 42 |
43 public class SessionManager implements SessionManagerEventListener{ | 43 public class SessionManager implements SessionManagerEventListener{ |
44 | 44 |
45 private LinkedList<Session> sessionList; | 45 private LinkedList<Session> sessionList; |
46 private SessionManagerGUIimpl gui; | 46 private SessionManagerGUI gui; |
47 private REPSelector<REPCommand> selector; | 47 private REPSelector<REPCommand> selector; |
48 private SessionManagerList smList; | 48 private SessionManagerList smList; |
49 private String myHost; | 49 private String myHost; |
50 private List<Editor> editorList; | 50 private List<Editor> editorList; |
51 private String maxHost; | 51 private String maxHost; |
60 } | 60 } |
61 | 61 |
62 public void openSelector() throws IOException{ | 62 public void openSelector() throws IOException{ |
63 selector = REPSelector.<REPCommand>create(); | 63 selector = REPSelector.<REPCommand>create(); |
64 } | 64 } |
65 | 65 |
66 public void init(int port) throws InterruptedException, IOException { | 66 public void init(int port, SessionManagerGUI gui) throws IOException, InterruptedException { |
67 this.gui = gui; | |
68 openSelector(); | |
69 init(port); | |
70 mainLoop(); | |
71 } | |
72 | |
73 | |
74 private void init(int port) throws InterruptedException, IOException { | |
67 | 75 |
68 REPServerSocketChannel<REPCommand> ssc = REPServerSocketChannel.<REPCommand>open(new REPCommandPacker()); | 76 REPServerSocketChannel<REPCommand> ssc = REPServerSocketChannel.<REPCommand>open(new REPCommandPacker()); |
69 ssc.configureBlocking(false); //reuse address 必須 | 77 ssc.configureBlocking(false); //reuse address 必須 |
70 ssc.socket().setReuseAddress(true); | 78 ssc.socket().setReuseAddress(true); |
71 //getAllByNameで取れた全てのアドレスに対してbindする | 79 //getAllByNameで取れた全てのアドレスに対してbindする |
77 editorList = new LinkedList<Editor>(); | 85 editorList = new LinkedList<Editor>(); |
78 waitingCommandInMerge = new LinkedList<PacketSet>(); | 86 waitingCommandInMerge = new LinkedList<PacketSet>(); |
79 waitingQueue = new LinkedBlockingQueue<SessionManagerEvent>(); | 87 waitingQueue = new LinkedBlockingQueue<SessionManagerEvent>(); |
80 | 88 |
81 //デフォルトのSessionを作っておく(テスト用に?) | 89 //デフォルトのSessionを作っておく(テスト用に?) |
82 if(sessionList.size() > 0) System.out.println("Error : SessionManager.init():"); | 90 //if(sessionList.size() > 0) System.out.println("Error : SessionManager.init():"); |
83 Session defaultSession = new Session(sessionList.size(), "DefaultSession.txt", new Editor(0,null)); | 91 //Session defaultSession = new Session(sessionList.size(), "DefaultSession.txt", new Editor(0,null)); |
84 sessionList.add(defaultSession); | 92 //sessionList.add(defaultSession); |
85 | 93 |
86 } | 94 } |
87 | 95 |
88 public void mainLoop() throws IOException { | 96 public void mainLoop() throws IOException { |
89 while(true){ | 97 while(true){ |
403 return; | 411 return; |
404 } | 412 } |
405 //リストのコピーをGUIに渡す | 413 //リストのコピーをGUIに渡す |
406 LinkedList<Session> sList = new LinkedList<Session>(sessionList); | 414 LinkedList<Session> sList = new LinkedList<Session>(sessionList); |
407 LinkedList<Editor> eList = new LinkedList<Editor>(editorList); | 415 LinkedList<Editor> eList = new LinkedList<Editor>(editorList); |
408 for(Editor editor : eList){ | 416 // for(Editor editor : eList){ |
409 System.out.println("SessionManager.guiUpdate() : channel = " + editor.getChannel()); | 417 // System.out.println("SessionManager.guiUpdate() : channel = " + editor.getChannel()); |
410 } | 418 // } |
411 | 419 // |
412 //GUIに反映 | 420 //GUIに反映 |
413 Runnable doRun = new DoGUIUpdate(sList, eList, gui); | 421 Runnable doRun = new DoGUIUpdate(sList, eList, gui); |
414 gui.invokeLater(doRun); | 422 gui.invokeLater(doRun); |
415 } | 423 } |
416 | 424 |
485 port_s = Integer.parseInt(args[1]); | 493 port_s = Integer.parseInt(args[1]); |
486 } | 494 } |
487 temp_port = port; | 495 temp_port = port; |
488 send_port = port_s; | 496 send_port = port_s; |
489 SessionManager sm = new SessionManager(port); | 497 SessionManager sm = new SessionManager(port); |
490 sm.openSelector(); | 498 sm.init(port,new SessionManagerGUIimpl(sm)); |
491 sm.init(port); | 499 |
492 sm.startGUI(sm); | 500 |
493 sm.mainLoop(); | |
494 | |
495 } | |
496 | |
497 public void startGUI(SessionManager sm) { | |
498 gui = new SessionManagerGUIimpl(); | |
499 Thread th = new Thread( gui ); | |
500 th.start(); | |
501 gui.addREPActionListener(this); | |
502 } | 501 } |
503 | 502 |
504 public void connectSession(String host) { | 503 public void connectSession(String host) { |
505 int port = DEFAULT_PORT; | 504 int port = DEFAULT_PORT; |
506 port = send_port; | 505 port = send_port; |