1 2 24 25 package com.lutris.appserver.server.sessionEnhydra; 26 27 import java.util.Enumeration ; 28 import java.util.Hashtable ; 29 30 import com.lutris.appserver.server.Enhydra; 31 import com.lutris.appserver.server.user.User; 32 import com.lutris.logging.Logger; 33 import com.lutris.util.Config; 34 35 50 class BasicSessionUserTable implements StandardSessionUserTable { 51 52 57 private Hashtable userSessionTable = new Hashtable (); 58 59 62 static final private Hashtable emptyTable = new Hashtable (); 63 64 71 public BasicSessionUserTable(Config config) { 72 } 73 74 82 public void add(String sessionKey, User user) { 83 Hashtable sessions = (Hashtable )userSessionTable.get(user.getName()); 84 if (sessions == null) { 85 sessions = new Hashtable (); 86 userSessionTable.put(user.getName(), sessions); 87 } 88 debug(2, "add session: user=" + user.getName() 89 + ": sessionKey=" + sessionKey); 90 sessions.put(sessionKey, sessionKey); } 92 93 101 public void remove(String sessionKey, User user) { 102 Hashtable sessions = (Hashtable )userSessionTable.get(user.getName()); 103 if (sessions != null) { 104 sessions.remove(sessionKey); 105 if (sessions.size() == 0) { 106 userSessionTable.remove(user.getName()); 108 } 109 } 110 debug(2, "remove session: user=" + user.getName() 111 + ": sessionKey=" + sessionKey); 112 } 113 114 120 public void remove(String sessionKey) { 121 Enumeration users = userSessionTable.keys(); 122 while (users.hasMoreElements()) { 123 String userName = (String )users.nextElement(); 124 Hashtable sessions = (Hashtable )userSessionTable.get(userName); 125 if (sessions != null) { 126 sessions.remove(sessionKey); 127 if (sessions.size() == 0) { 128 userSessionTable.remove(userName); 130 } 131 } 132 } 133 debug(2, "remove sessionKey from user table:" + sessionKey); 134 } 135 136 143 public int numSessions(User user) { 144 Hashtable sessions = (Hashtable )userSessionTable.get(user.getName()); 145 if (sessions == null) { 146 return 0; 147 } else { 148 return sessions.size(); 149 } 150 } 151 152 159 public Enumeration getSessionKeys(User user) { 160 Hashtable sessions = (Hashtable )userSessionTable.get(user.getName()); 161 if (sessions == null) { 162 debug(2, "getSessionKeys: " + user.getName() 163 + ": totalKeys=0"); 164 return emptyTable.elements(); 165 } else { 166 debug(2, "getSessionKeys: " + user.getName() 167 + ": totalKeys=" + sessions.size()); 168 return sessions.elements(); 169 } 170 } 171 172 176 public void shutdown() { 177 } 179 180 185 private void debug(String msg) { 186 debug(0, msg); 187 } 188 189 195 protected void debug(int level, String msg) { 196 int dbg = Logger.DEBUG; 197 switch (level) { 198 case 1: 199 dbg = Logger.DEBUG1; 200 break; 201 case 2: 202 dbg = Logger.DEBUG2; 203 break; 204 case 3: 205 dbg = Logger.DEBUG3; 206 break; 207 case 4: 208 dbg = Logger.DEBUG4; 209 break; 210 case 5: 211 dbg = Logger.DEBUG5; 212 break; 213 case 6: 214 dbg = Logger.DEBUG6; 215 break; 216 case 7: 217 dbg = Logger.DEBUG7; 218 break; 219 case 8: 220 dbg = Logger.DEBUG8; 221 break; 222 case 9: 223 dbg = Logger.DEBUG9; 224 break; 225 default: 226 dbg = Logger.DEBUG; 227 break; 228 } 229 Enhydra.getLogChannel().write(dbg, "PersistentSessionHome(" 230 + Thread.currentThread().getName() 231 + "): " + msg); 232 } 233 } 234 | Popular Tags |