comparison rep/SessionList.java @ 1:3f5bf0255f5e

*** empty log message ***
author pin
date Wed, 21 Feb 2007 15:08:52 +0900
parents e41994ce73c7
children 02fa9a68d9a2
comparison
equal deleted inserted replaced
0:e41994ce73c7 1:3f5bf0255f5e
6 import java.util.List; 6 import java.util.List;
7 7
8 public class SessionList { 8 public class SessionList {
9 9
10 //List<LinkedList<SocketChannel>> sessions = new LinkedList<LinkedList<SocketChannel>>(); 10 //List<LinkedList<SocketChannel>> sessions = new LinkedList<LinkedList<SocketChannel>>();
11 Hashtable<Integer, LinkedList<SocketChannel>> sessions2 = new Hashtable<Integer, LinkedList<SocketChannel>>(); 11 //Hashtable<Integer, LinkedList<SocketChannel>> sessions2 = new Hashtable<Integer, LinkedList<SocketChannel>>();
12 //Hashtable editors = new Hashtable(); 12 Hashtable<Integer, Session> session3 = new Hashtable<Integer, Session>();
13 private int sessionID; 13 private int sessionID = 0;
14 private int editorCount = 0;
14 15
15 private int editorCount; 16 private SocketChannel smchannel;
16 17
17 public void add(SocketChannel channel) { 18 public void add(SocketChannel channel) {
18 19
19 } 20 }
20 21
27 28
28 } 29 }
29 30
30 public int addSession(SocketChannel channel, String string) { 31 public int addSession(SocketChannel channel, String string) {
31 sessionID++; 32 sessionID++;
32 sessions2.put(sessionID, new LinkedList<SocketChannel>()); 33 //sessions2.put(sessionID, new LinkedList<SocketChannel>());
33 //sessions.add(new LinkedList<SocketChannel>()); 34 //sessions.add(new LinkedList<SocketChannel>());
34 //return sessions2.size(); 35 //return sessions2.size();
36 session3.put(sessionID, new Session(sessionID, string, channel));
35 return sessionID; 37 return sessionID;
36 38
37 } 39 }
38 40
39 public void addEditor(SocketChannel channel, int sid) { 41 public void addEditor(SocketChannel channel, int sid, REPCommand repCmd) {
42 int editorID = repCmd.eid;
40 //editorCount++; 43 //editorCount++;
41 //sessions.get(sid-1).add(channel); 44 //sessions.get(sid-1).add(channel);
42 sessions2.get(sid).add(channel); 45 //sessions2.get(sid).add(channel);
46 session3.get(sid).addEditor(editorID, channel);
43 } 47 }
44 48
45 public int getSessionID(SocketChannel channel) { 49 public int getSessionID(SocketChannel channel) {
46 return 0; 50 return 0;
47 } 51 }
51 return editorCount; 55 return editorCount;
52 } 56 }
53 57
54 public void sendCmd(SocketChannel channel2, REPCommand repCmd) { 58 public void sendCmd(SocketChannel channel2, REPCommand repCmd) {
55 //int sessionID = repCmd.sid; 59 //int sessionID = repCmd.sid;
56 LinkedList <SocketChannel> channelList = sessions2.get(repCmd.sid); 60 //LinkedList <SocketChannel> channelList = sessions2.get(repCmd.sid);
57 for(SocketChannel channel : channelList){ 61 LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList();
62 for(Editor editor : editorList){
63 SocketChannel channel = editor.getChannel();
58 if(channel.equals(channel2)) { 64 if(channel.equals(channel2)) {
59 System.out.println("equals"); 65 System.out.println("equals");
60 continue; 66 continue;
61 } 67 }
62 REPPacketSend repSend = new REPPacketSend(channel); 68 REPPacketSend repSend = new REPPacketSend(channel);
63 repSend.send(repCmd); 69 repSend.send(repCmd);
64 } 70 }
65 } 71 }
66 72
73 public void addSessionManager(SocketChannel channel, REPCommand repCmd) {
74 smchannel = channel;
75
76 }
77
78 public void sendAddedSession(REPCommand repCmd) {
79 // TODO Auto-generated method stub
80 repCmd.setCMD(REP.SMCMD_SESSION_JOIN);
81 REPPacketSend repSend = new REPPacketSend(smchannel);
82 //repSend.send(repCmd);
83 }
84
67 } 85 }