KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > web > util > SessionManager


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.web.util;
20
21 import java.util.*;
22
23 public class SessionManager {
24     private static HashMap activeSessionsStarted = new HashMap();
25     private static HashMap activeSessionsLastAccess = new HashMap();
26     private static HashMap activeSessionsReset = new HashMap();
27
28     public SessionManager() {
29     }
30
31     public static int getNumActiveSessions() {
32         return activeSessionsStarted.size();
33     }
34
35     public static Date getSessionStart(String JavaDoc login) {
36         return ((Date) activeSessionsStarted.get(login));
37     }
38
39     public static Date getSessionLastAccess(String JavaDoc login) {
40         return ((Date) activeSessionsLastAccess.get(login));
41     }
42
43     public static boolean getSessionNeedsReset(String JavaDoc login) {
44         return (activeSessionsReset.get(login) != null ? true : false);
45     }
46
47     public static void updateSessionLastAccess(String JavaDoc login) {
48         activeSessionsLastAccess.put(login, new Date());
49     }
50
51     public static void createSession(String JavaDoc login) {
52         Date now = new Date();
53         activeSessionsStarted.put(login, now);
54         activeSessionsLastAccess.put(login, now);
55     }
56
57     public static void invalidateSession(String JavaDoc login) {
58         activeSessionsLastAccess.remove(login);
59         activeSessionsStarted.remove(login);
60         activeSessionsReset.remove(login);
61     }
62
63     public static void setSessionNeedsReset(String JavaDoc login) {
64         activeSessionsReset.put(login, new Integer JavaDoc(1));
65     }
66
67     public static void setAllSessionsNeedsReset() {
68         for(Iterator iter = activeSessionsStarted.keySet().iterator(); iter.hasNext(); ) {
69             activeSessionsReset.put((String JavaDoc) iter.next(), new Integer JavaDoc(1));
70         }
71     }
72
73     public static void clearSessionNeedsReset(String JavaDoc login) {
74         activeSessionsReset.remove(login);
75     }
76 }
Popular Tags