0
|
1 package rep;
|
|
2
|
|
3 import java.nio.channels.SocketChannel;
|
|
4 import java.util.LinkedList;
|
130
|
5
|
|
6 import rep.channel.REPSocketChannel;
|
41
|
7 import rep.xml.SessionXMLEncoder;
|
39
|
8
|
0
|
9 public class SessionList {
|
|
10
|
56
|
11 LinkedList<Session> sessionLinkedList = new LinkedList<Session>();
|
38
|
12 LinkedList<String> stringlist = new LinkedList<String>();
|
1
|
13 private int sessionID = 0;
|
|
14 private int editorCount = 0;
|
80
|
15 private String maxHost;
|
120
|
16
|
31
|
17 public SessionList(){
|
|
18 makeDefaultSession();
|
|
19 }
|
0
|
20
|
130
|
21 public void add(REPSocketChannel<REPCommand> channel) {
|
0
|
22
|
|
23 }
|
31
|
24
|
|
25 public void makeDefaultSession(){
|
|
26 }
|
0
|
27
|
|
28 public int getEditorNumber() {
|
|
29 return 0;
|
|
30
|
|
31 }
|
|
32
|
130
|
33 public void add(REPSocketChannel<REPCommand> channel, int sid) {
|
0
|
34
|
|
35 }
|
|
36
|
130
|
37 public int addSession(REPSocketChannel<REPCommand> channel, String string) {
|
0
|
38 sessionID++;
|
|
39 return sessionID;
|
|
40
|
|
41 }
|
|
42
|
317
|
43 public void addEditor(SessionManager manager,REPSocketChannel<REPCommand> channel, int sid, REPCommand repCmd) {
|
1
|
44 int editorID = repCmd.eid;
|
317
|
45 sessionLinkedList.get(sid-1).addEditor(manager,editorID, channel); //本当はforループで検索しないといけないよ。
|
0
|
46 }
|
|
47
|
|
48 public int getNumberOfEditor() {
|
|
49 editorCount++;
|
|
50 return editorCount;
|
|
51 }
|
130
|
52
|
0
|
53
|
1
|
54 public void addSessionManager(SocketChannel channel, REPCommand repCmd) {
|
|
55
|
|
56 }
|
|
57
|
3
|
58 public String getSessionList() {
|
56
|
59 if (sessionLinkedList != null) {
|
|
60 System.out.println(sessionLinkedList.toString());
|
|
61 return sessionLinkedList.toString();
|
3
|
62 }
|
|
63 return "{}";
|
|
64 }
|
|
65
|
122
|
66
|
317
|
67 public void addEditor(SessionManager manager,REPSocketChannel<REPCommand> editorChannel, int sid, int eid) {
|
|
68 sessionLinkedList.get(sid-1).addEditor(manager,eid, editorChannel);
|
8
|
69 }
|
|
70
|
|
71 public void sendSelect(int sid) {
|
158
|
72 REPSocketChannel<REPCommand> channel = sessionLinkedList.get(sid-1).getOwner().getChannel();
|
284
|
73 channel.write(new REPCommand(REP.SMCMD_SELECT, sid, 0, 0, 0, ""));
|
8
|
74 }
|
|
75
|
39
|
76 // public String getXML() {
|
122
|
77 ///* SessionListをXMLに書き出す。ときの形式
|
39
|
78 // * <Session>
|
|
79 // * <editor>
|
|
80 // * <sid/>
|
|
81 // * <host/>
|
|
82 // * <port/>
|
|
83 // * <filename/>
|
|
84 // * </editor>
|
|
85 // * <editor>
|
|
86 // * <sid/>
|
|
87 // * <host/>
|
|
88 // * <port/>
|
|
89 // * </editor>
|
|
90 // * </Session>
|
|
91 // * <SessionManager>
|
|
92 // * <host/>
|
|
93 // * <port/>
|
|
94 // * </SessionManager>
|
|
95 // * <Session>
|
|
96 // * </Session>
|
41
|
97 // *
|
39
|
98 // StringWriter str = null;
|
|
99 // try {
|
|
100 // str = new StringWriter();
|
|
101 // DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
102 // DocumentBuilder builder = factory.newDocumentBuilder();
|
|
103 // Document doc = builder.newDocument();
|
|
104 // Element root = doc.getDocumentElement();
|
|
105 // root = doc.createElement("SessionList");
|
|
106 // for(Session session : session4){
|
|
107 // Element element = doc.createElement("Session");
|
|
108 // root.appendChild(element);
|
|
109 // Element element2 = doc.createElement("editor");
|
|
110 // element.appendChild(element2);
|
|
111 // Editor editor = session.getMaster();
|
|
112 // Element element3 = doc.createElement(editor.getHost());
|
|
113 // Element element4 = doc.createElement(editor.getPort());
|
|
114 // Element element5 = doc.createElement(editor.getName());
|
|
115 // element5 = doc.createElement(session.getName());
|
|
116 // element2.appendChild(element3);
|
|
117 // element2.appendChild(element4);
|
|
118 // element2.appendChild(element5);
|
|
119 //
|
|
120 // }
|
|
121 // doc.appendChild(root);
|
38
|
122 //
|
39
|
123 // TransformerFactory tfactory = TransformerFactory.newInstance();
|
|
124 // Transformer transformer = tfactory.newTransformer();
|
|
125 // StreamResult result = new StreamResult(str);
|
|
126 // //transformer.transform(new DOMSource(doc), new StreamResult(System.out));
|
|
127 // transformer.transform(new DOMSource(doc), result);
|
|
128 // System.out.println(str);
|
|
129 ////
|
|
130 //// XMLEncoder e = new XMLEncoder(System.out);
|
|
131 //// e.writeObject(session4);
|
|
132 //// e.writeObject(stringlist);
|
|
133 //// e.close();
|
|
134 //
|
|
135 // //System.out.println(doc);
|
|
136 // }catch (Exception e){
|
|
137 // e.printStackTrace();
|
|
138 // }
|
|
139 // return str.toString();
|
41
|
140 // }*/
|
39
|
141
|
|
142 public LinkedList<Session> getList() {
|
56
|
143 return sessionLinkedList;
|
39
|
144 }
|
|
145
|
|
146 public String toXML() {
|
56
|
147 SessionXMLEncoder encoder = new SessionXMLEncoder(sessionLinkedList);
|
39
|
148 encoder.sessionListToXML();
|
|
149 return null;
|
|
150 }
|
|
151
|
|
152 public int addSession(Session session) {
|
|
153 sessionID++;
|
56
|
154 session.setSID(sessionID);
|
|
155 sessionLinkedList.add(session);
|
39
|
156 return sessionID;
|
38
|
157 }
|
|
158
|
56
|
159 public void addToRoutingTable(SocketChannel channel) {
|
|
160
|
|
161 }
|
|
162
|
66
|
163 public Session getSession(int sid) {
|
120
|
164 for(Session session : sessionLinkedList){
|
|
165 if(session.getSID() == sid){
|
|
166 return session;
|
|
167 }
|
|
168 }
|
66
|
169 return sessionLinkedList.get(sid - 1);
|
|
170 }
|
|
171
|
80
|
172 public void setMaxHost(String myHost) {
|
|
173 maxHost = myHost;
|
77
|
174 }
|
|
175
|
82
|
176 public String getMaxHost() {
|
80
|
177 return maxHost;
|
77
|
178 }
|
|
179
|
|
180 public void setList(LinkedList<Session> list) {
|
|
181 sessionLinkedList = list;
|
|
182 }
|
|
183
|
130
|
184 public void update(REPSocketChannel<REPCommand> channel, SessionList receivedSessionList) {
|
83
|
185 LinkedList<Session> list = receivedSessionList.getList();
|
|
186 int i = 0;
|
|
187 for(Session session : list){
|
101
|
188 session.getEditorList().get(0).setChannel(channel);
|
83
|
189 ++i;
|
|
190 }
|
|
191 }
|
0
|
192 }
|