KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > plankton > http > SessionManager


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: SessionManager.java,v 1.2 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.plankton.http;
21
22 import java.util.*;
23 import java.lang.ref.*;
24 import javax.servlet.*;
25 import javax.servlet.http.*;
26
27 import org.apache.log4j.*;
28
29 import org.enhydra.barracuda.plankton.data.*;
30
31 /**
32  * This class provides a convenient bridge to any sessions which are being managed/registered
33  * through Barracuda's SessionObjectRepository class (ie. all events that go through ApplicationGateway
34  * use this). You can use this class to get a handle to all the underlying sessions, to log an individual
35  * session out, or to log all sessions out.
36  *
37  * @author christianc@granitepeaks.com
38  * @since //csc_011704_1
39  */

40 public class SessionManager {
41
42     protected static Logger logger = Logger.getLogger(SessionManager.class.getName());
43
44     /**
45      * allows you to look up a session by its unique identifier. You should only need to call
46      * this if you are performing large scale session management (ie. logging out all users, etc)
47      */

48     public static HttpSession getSession(String JavaDoc sessionID) {
49         return (HttpSession) getAllSessions().get(sessionID);
50     }
51     
52     /**
53      * get a Map containing soft references to all the HttpSessions. Simply delegates to
54      * ObjectRepository.getRawSessionStore(). Note that you should be very careful using this
55      * method - the ObjectRespository stores soft references to the session, allowing them
56      * to be recalimed by the garbage collector when they expire. If you use this method to
57      * access the underlying sessions you must be very careful not to hold onto these references
58      * or you may run into problems.
59      */

60     public static SoftHashMap getAllSessions() {
61         return ObjectRepository.getRawSessionStore();
62     }
63
64     /**
65      * allows you to invalidate a session associated with the current thread
66      */

67     public static void invalidateSession() {
68         ObjectRepository.invalidateSession();
69     }
70
71     /**
72      * allows you to invalidate a session by its unique identifier. You should only need to call
73      * this if you are performing large scale session management (ie. logging out all users, etc)
74      */

75     public static void invalidateSession(String JavaDoc sessionID) {
76         ObjectRepository.invalidateSession(sessionID);
77     }
78     
79     /**
80      * allows you to invalidate all sessions. You should only need to call
81      * this if you are performing large scale session management (ie. logging out all users, etc)
82      */

83     public static void invalidateAllSessions() {
84         ObjectRepository.invalidateAllSessions();
85     }
86
87     
88
89
90 }
91
Popular Tags