Mercurial > hg > RemoteEditor > REPSessionManager
comparison rep/SessionManager.java @ 198:ff3fcdcccc85
*** empty log message ***
author | pin |
---|---|
date | Sat, 30 Aug 2008 01:11:27 +0900 |
parents | 6fb97c7a0b42 |
children | 456ba58cd042 |
comparison
equal
deleted
inserted
replaced
197:8d7c74610b05 | 198:ff3fcdcccc85 |
---|---|
9 import java.util.Iterator; | 9 import java.util.Iterator; |
10 import java.util.LinkedList; | 10 import java.util.LinkedList; |
11 import java.util.List; | 11 import java.util.List; |
12 import java.util.concurrent.BlockingQueue; | 12 import java.util.concurrent.BlockingQueue; |
13 import java.util.concurrent.LinkedBlockingQueue; | 13 import java.util.concurrent.LinkedBlockingQueue; |
14 | |
15 import javax.swing.SwingUtilities; | |
14 | 16 |
15 import rep.channel.REPServerSocketChannel; | 17 import rep.channel.REPServerSocketChannel; |
16 import rep.channel.REPSocketChannel; | 18 import rep.channel.REPSocketChannel; |
17 import rep.handler.PacketSet; | 19 import rep.handler.PacketSet; |
18 import rep.handler.REPHandler; | 20 import rep.handler.REPHandler; |
19 import rep.handler.REPHandlerImpl; | 21 import rep.handler.REPHandlerImpl; |
20 import rep.handler.REPHandlerInMerge; | 22 import rep.handler.REPHandlerInMerge; |
21 import rep.channel.REPSelector; | 23 import rep.channel.REPSelector; |
22 import rep.xml.SessionXMLDecoder; | 24 import rep.xml.SessionXMLDecoder; |
23 import rep.xml.SessionXMLEncoder; | 25 import rep.xml.SessionXMLEncoder; |
24 | 26 import rep.channel.REPSelectionKey; |
27 /* | |
25 //+-------+--------+--------+-------+--------+---------+------+ | 28 //+-------+--------+--------+-------+--------+---------+------+ |
26 //| cmd | session| editor | seqid | lineno | textsiz | text | | 29 //| cmd | session| editor | seqid | lineno | textsiz | text | |
27 //| | id | id | | | | | | 30 //| | id | id | | | | | |
28 //+-------+--------+--------+-------+--------+---------+------+ | 31 //+-------+--------+--------+-------+--------+---------+------+ |
29 //o-------header section (network order)-------------o | 32 //o-------header section (network order)-------------o |
30 /*int cmd; // command | 33 int cmd; // command |
31 int sid; // session ID : uniqu to editing file | 34 int sid; // session ID : uniqu to editing file |
32 int eid; // editor ID : owner editor ID = 1。Session に対して unique | 35 int eid; // editor ID : owner editor ID = 1。Session に対して unique |
33 int seqno; // Sequence number : sequence number はエディタごとに管理 | 36 int seqno; // Sequence number : sequence number はエディタごとに管理 |
34 int lineno; // line number | 37 int lineno; // line number |
35 int textsize; // textsize : bytesize | 38 int textsize; // textsize : bytesize |
36 byte[] text;*/ | 39 byte[] text; |
40 */ | |
37 | 41 |
38 public class SessionManager implements ConnectionListener, REPActionListener{ | 42 public class SessionManager implements ConnectionListener, REPActionListener{ |
39 | 43 |
40 | |
41 //private SessionList sessionlist; | |
42 private LinkedList<Session> sessionList; | 44 private LinkedList<Session> sessionList; |
43 private SessionManagerGUI gui; | 45 private SessionManagerGUI gui; |
44 private REPSelector selector; | 46 private REPSelector<REPCommand> selector; |
45 private SessionManagerList smList; | 47 private SessionManagerList smList; |
46 private String myHost; | 48 private String myHost; |
47 private boolean isMaster = true; | 49 private boolean isMaster = true; |
48 //private EditorList ownEditorList; | |
49 private List<Editor> editorList; | 50 private List<Editor> editorList; |
50 private String maxHost; | 51 private String maxHost; |
51 private boolean isSimulation; | 52 private boolean isSimulation; |
52 private List<PacketSet> packetSetList; | 53 private List<PacketSet> packetSetList; |
53 private BlockingQueue<SessionManagerEvent> waitingQueue; | 54 private BlockingQueue<SessionManagerEvent> waitingQueue; |
54 //private List<SessionManagerNode> managerList; | |
55 private static int temp_port; | 55 private static int temp_port; |
56 private static int send_port; | 56 private static int send_port; |
57 | |
58 static final int DEFAULT_PORT = 8766; | 57 static final int DEFAULT_PORT = 8766; |
59 | 58 |
60 public SessionManager(int port) { | 59 public SessionManager(int port) { |
61 | 60 |
62 } | 61 } |
116 private void select() throws IOException { | 115 private void select() throws IOException { |
117 SessionManagerEvent e = waitingQueue.poll(); | 116 SessionManagerEvent e = waitingQueue.poll(); |
118 if(e != null) { | 117 if(e != null) { |
119 e.exec(); | 118 e.exec(); |
120 } | 119 } |
121 for(SelectionKey key : selector.selectedKeys()){ | 120 for(REPSelectionKey<REPCommand> key : selector.selectedKeys1()){ |
122 if(key.isAcceptable()){ | 121 if(key.isAcceptable()){ |
123 /*** serverChannelはenableになったSelectionKeyのchannel ***/ | 122 /*** serverChannelはenableになったSelectionKeyのchannel ***/ |
124 REPServerSocketChannel serverChannel = (REPServerSocketChannel)key.channel(); | 123 REPServerSocketChannel serverChannel = (REPServerSocketChannel)key.channel(); |
125 REPSocketChannel channel = serverChannel.accept1(); //keyからchannelを取って、accept | 124 REPSocketChannel channel = serverChannel.accept1(); //keyからchannelを取って、accept |
126 registerChannel (selector, channel, SelectionKey.OP_READ); | 125 registerChannel (selector, channel, SelectionKey.OP_READ); |
159 //どのSessionにも属さないエディタをリストに追加 | 158 //どのSessionにも属さないエディタをリストに追加 |
160 Editor editor = new Editor(editorList.size(), channel); | 159 Editor editor = new Editor(editorList.size(), channel); |
161 editor.setHost(myHost); | 160 editor.setHost(myHost); |
162 editorList.add(editor); | 161 editorList.add(editor); |
163 | 162 |
163 //リストのコピーをGUIに渡す | |
164 LinkedList<Session> sList = new LinkedList<Session>(sessionList); | |
165 LinkedList<Editor> eList = new LinkedList<Editor>(editorList); | |
164 //GUIに反映 | 166 //GUIに反映 |
165 //gui.setComboEditor(editor.getEID(), channel); | 167 Runnable doRun = new DoGUIUpdate(sList, eList, gui); |
166 gui.update(); | 168 SwingUtilities.invokeLater(doRun); |
167 } | 169 } |
168 | |
169 | 170 |
170 break; | 171 break; |
171 | 172 |
172 case REP.SMCMD_JOIN_ACK: | 173 case REP.SMCMD_JOIN_ACK: |
173 | 174 |