Mercurial > hg > RemoteEditor > REPSessionManager
comparison rep/SessionManager.java @ 191:dbf59f82273e
*** empty log message ***
author | pin |
---|---|
date | Fri, 29 Aug 2008 18:52:36 +0900 |
parents | d22384c0026c |
children | 6fb97c7a0b42 |
comparison
equal
deleted
inserted
replaced
190:63701e2a2fe8 | 191:dbf59f82273e |
---|---|
38 | 38 |
39 | 39 |
40 //private SessionList sessionlist; | 40 //private SessionList sessionlist; |
41 private LinkedList<Session> sessionList; | 41 private LinkedList<Session> sessionList; |
42 private SessionManagerGUI gui; | 42 private SessionManagerGUI gui; |
43 private Selector selector; | 43 private REPSelector selector; |
44 private SessionManagerList smList; | 44 private SessionManagerList smList; |
45 private String myHost; | 45 private String myHost; |
46 private boolean isMaster = true; | 46 private boolean isMaster = true; |
47 //private EditorList ownEditorList; | 47 //private EditorList ownEditorList; |
48 private List<Editor> editorList; | 48 private List<Editor> editorList; |
55 private static int send_port; | 55 private static int send_port; |
56 | 56 |
57 static final int DEFAULT_PORT = 8766; | 57 static final int DEFAULT_PORT = 8766; |
58 | 58 |
59 public SessionManager(int port) { | 59 public SessionManager(int port) { |
60 gui = new SessionManagerGUI(this); | 60 |
61 } | 61 } |
62 | 62 |
63 public void openSelector() throws IOException{ | 63 public void openSelector() throws IOException{ |
64 selector = REPSelector.open(); | 64 selector = REPSelector.create(); |
65 } | 65 } |
66 | 66 |
67 public void init(int port) throws InterruptedException, IOException { | 67 public void init(int port) throws InterruptedException, IOException { |
68 | 68 |
69 REPServerSocketChannel<REPCommand> ssc = REPServerSocketChannel.<REPCommand>open(new REPCommandPacker()); | 69 REPServerSocketChannel<REPCommand> ssc = REPServerSocketChannel.<REPCommand>open(new REPCommandPacker()); |
70 ssc.configureBlocking(false); //reuse address 必須 | 70 ssc.configureBlocking(false); //reuse address 必須 |
71 ssc.socket().setReuseAddress(true); | 71 ssc.socket().setReuseAddress(true); |
72 ssc.socket().bind(new InetSocketAddress(port)); | 72 ssc.socket().bind(new InetSocketAddress(port)); |
73 ssc.register(selector, SelectionKey.OP_ACCEPT); | 73 //ssc.register(selector, SelectionKey.OP_ACCEPT); |
74 registerChannel(selector, ssc, SelectionKey.OP_ACCEPT); | |
74 | 75 |
75 | 76 |
76 //sessionlist = new SessionList(); | 77 //sessionlist = new SessionList(); |
77 sessionList = new LinkedList<Session>(); | 78 sessionList = new LinkedList<Session>(); |
78 smList = new SessionManagerList(); | 79 smList = new SessionManagerList(); |
79 //ownEditorList = new EditorList(); | 80 //ownEditorList = new EditorList(); |
80 editorList = new LinkedList<Editor>(); | 81 editorList = new LinkedList<Editor>(); |
81 packetSetList = new LinkedList<PacketSet>(); | 82 packetSetList = new LinkedList<PacketSet>(); |
82 | 83 |
83 // main loop | 84 // main loop |
84 mainLoop(); | 85 //mainLoop(); |
85 } | 86 } |
86 | 87 |
87 private void mainLoop() throws IOException { | 88 private void mainLoop() throws IOException { |
88 while(true){ | 89 while(true){ |
89 if(checkSend()){ | 90 if(checkSend()){ |
430 editor.setHost(myHost2); | 431 editor.setHost(myHost2); |
431 } | 432 } |
432 } | 433 } |
433 | 434 |
434 public static void main(String[] args) throws InterruptedException, IOException { | 435 public static void main(String[] args) throws InterruptedException, IOException { |
436 | |
437 REPServerSocketChannel.isSimulation = true; | |
438 | |
435 int port = DEFAULT_PORT; | 439 int port = DEFAULT_PORT; |
436 int port_s = DEFAULT_PORT; | 440 int port_s = DEFAULT_PORT; |
437 //System.setProperty("file.encoding", "UTF-8"); | 441 //System.setProperty("file.encoding", "UTF-8"); |
438 if(args.length > 0){ | 442 if(args.length > 0){ |
439 port = Integer.parseInt(args[0]); | 443 port = Integer.parseInt(args[0]); |
441 } | 445 } |
442 temp_port = port; | 446 temp_port = port; |
443 send_port = port_s; | 447 send_port = port_s; |
444 SessionManager sm = new SessionManager(port); | 448 SessionManager sm = new SessionManager(port); |
445 sm.openSelector(); | 449 sm.openSelector(); |
446 sm.openWindow(); | |
447 sm.init(port); | 450 sm.init(port); |
451 sm.startGUI(sm); | |
448 sm.mainLoop(); | 452 sm.mainLoop(); |
449 } | 453 |
450 | 454 } |
451 private void openWindow() { | 455 |
456 private void startGUI(SessionManager sm) { | |
457 gui = new SessionManagerGUI(this); | |
452 Thread th = new Thread( gui ); | 458 Thread th = new Thread( gui ); |
453 th.start(); | 459 th.start(); |
454 gui.addConnectionListener(this); | |
455 gui.addREPActionListener(this); | |
456 } | 460 } |
457 | 461 |
458 public void connectSession(String host) { | 462 public void connectSession(String host) { |
459 int port = DEFAULT_PORT; | 463 int port = DEFAULT_PORT; |
460 port = send_port; | 464 port = send_port; |