Source Code Cross Referenced for BasicSessionUserTable.java in  » J2EE » Enhydra-Application-Framework » com » lutris » appserver » server » sessionEnhydra » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Enhydra Application Framework » com.lutris.appserver.server.sessionEnhydra 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         *
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         *
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         *
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         *
019:         * Contributor(s):
020:         *
021:         * $Id: BasicSessionUserTable.java,v 1.2 2006-06-15 13:44:07 sinisa Exp $
022:         */
023:
024:        package com.lutris.appserver.server.sessionEnhydra;
025:
026:        import java.util.Enumeration;
027:        import java.util.Hashtable;
028:
029:        import com.lutris.appserver.server.Enhydra;
030:        import com.lutris.appserver.server.user.User;
031:        import com.lutris.logging.Logger;
032:        import com.lutris.util.Config;
033:
034:        /**
035:         * Table used by StandardSessionManager to cross reference <CODE>User</CODE>
036:         * objects and sessions.  This table does not hold references to the
037:         * user and session objects.  Instead it only cross-references the
038:         * session keys and user names.  An underlying assumption is that the
039:         * user name can be used as a unique reference to the user.
040:         *
041:         * N.B.  It is assumed that this class is only used by StandardSessionManager
042:         * and that it is responsible for providing high level locks instead of
043:         * synchronizing
044:         *
045:         * @version	$Revision: 1.2 $
046:         * @author      Mark Diekhans
047:         * @author      Kyle Clark
048:         */
049:        class BasicSessionUserTable implements  StandardSessionUserTable {
050:
051:            /**
052:             * Table indexed by a <CODE>User</CODE> object. Each entry contains
053:             * a Hashtable of sessions keys associated with the user name.
054:             * The hash table is indexed by the <CODE>Session</CODE> object.
055:             */
056:            private Hashtable userSessionTable = new Hashtable();
057:
058:            /**
059:             * A empty hash table used to return empty enumerations.
060:             */
061:            static final private Hashtable emptyTable = new Hashtable();
062:
063:            /**
064:             * Creates an instance of this table.  The config options
065:             * are ignored.
066:             *
067:             * @param config
068:             *   configuration options for this table.
069:             */
070:            public BasicSessionUserTable(Config config) {
071:            }
072:
073:            /**
074:             * Add a session key to the user name of the session xref table.
075:             *
076:             * @param session
077:             *   The session key.
078:             * @param user
079:             *   the user to associated with the session key.
080:             */
081:            public void add(String sessionKey, User user) {
082:                Hashtable sessions = (Hashtable) userSessionTable.get(user
083:                        .getName());
084:                if (sessions == null) {
085:                    sessions = new Hashtable();
086:                    userSessionTable.put(user.getName(), sessions);
087:                }
088:                debug(2, "add session: user=" + user.getName()
089:                        + ": sessionKey=" + sessionKey);
090:                sessions.put(sessionKey, sessionKey); // Have to put something!
091:            }
092:
093:            /**
094:             * Remove a session from the user to session mapping table.
095:             * If the session is not it the table, it is ignored.
096:             *
097:             * @param sessionKey The session key, with the user already
098:             * filled in.
099:             * @param user the user associated with the session.
100:             */
101:            public void remove(String sessionKey, User user) {
102:                Hashtable sessions = (Hashtable) userSessionTable.get(user
103:                        .getName());
104:                if (sessions != null) {
105:                    sessions.remove(sessionKey);
106:                    if (sessions.size() == 0) {
107:                        // Remove the user.
108:                        userSessionTable.remove(user.getName());
109:                    }
110:                }
111:                debug(2, "remove session: user=" + user.getName()
112:                        + ": sessionKey=" + sessionKey);
113:            }
114:
115:            /**
116:             * Removes all references to a session from the user session table.
117:             *
118:             * @param sessionKey The session key, with the user already
119:             * filled in.
120:             */
121:            public void remove(String sessionKey) {
122:                Enumeration users = userSessionTable.keys();
123:                while (users.hasMoreElements()) {
124:                    String userName = (String) users.nextElement();
125:                    Hashtable sessions = (Hashtable) userSessionTable
126:                            .get(userName);
127:                    if (sessions != null) {
128:                        sessions.remove(sessionKey);
129:                        if (sessions.size() == 0) {
130:                            // Remove the user.
131:                            userSessionTable.remove(userName);
132:                        }
133:                    }
134:                }
135:                debug(2, "remove sessionKey from user table:" + sessionKey);
136:            }
137:
138:            /**
139:             * Get the number of sessions for a user.
140:             *
141:             * @param user The user object to check for.
142:             * @return The count of the number of sessions associated with this
143:             *  user.
144:             */
145:            public int numSessions(User user) {
146:                Hashtable sessions = (Hashtable) userSessionTable.get(user
147:                        .getName());
148:                if (sessions == null) {
149:                    return 0;
150:                } else {
151:                    return sessions.size();
152:                }
153:            }
154:
155:            /**
156:             * Returns the session keys associated with a particular user.
157:             *
158:             * @param user The user object to check for.
159:             * @return An enumeration of the session keys associated
160:             *   with the user.
161:             */
162:            public Enumeration getSessionKeys(User user) {
163:                Hashtable sessions = (Hashtable) userSessionTable.get(user
164:                        .getName());
165:                if (sessions == null) {
166:                    debug(2, "getSessionKeys: " + user.getName()
167:                            + ": totalKeys=0");
168:                    return emptyTable.elements();
169:                } else {
170:                    debug(2, "getSessionKeys: " + user.getName()
171:                            + ": totalKeys=" + sessions.size());
172:                    return sessions.elements();
173:                }
174:            }
175:
176:            /**
177:             * Shutdown this session user table as required.  The session
178:             * user table should not be used after this method has been called
179:             */
180:            public void shutdown() {
181:                // TODO
182:            }
183:
184:            /**
185:             * Prints debug information under Logger.DEBUG.
186:             *
187:             * @param msg the message to print.
188:             */
189:            private void debug(String msg) {
190:                debug(0, msg);
191:            }
192:
193:            /**
194:             * Prints debug information under Logger.DEBUG.
195:             *
196:             * @param level the debug level.
197:             * @param msg the message to print.
198:             */
199:            protected void debug(int level, String msg) {
200:                int dbg = Logger.DEBUG;
201:                switch (level) {
202:                case 1:
203:                    dbg = Logger.DEBUG1;
204:                    break;
205:                case 2:
206:                    dbg = Logger.DEBUG2;
207:                    break;
208:                case 3:
209:                    dbg = Logger.DEBUG3;
210:                    break;
211:                case 4:
212:                    dbg = Logger.DEBUG4;
213:                    break;
214:                case 5:
215:                    dbg = Logger.DEBUG5;
216:                    break;
217:                case 6:
218:                    dbg = Logger.DEBUG6;
219:                    break;
220:                case 7:
221:                    dbg = Logger.DEBUG7;
222:                    break;
223:                case 8:
224:                    dbg = Logger.DEBUG8;
225:                    break;
226:                case 9:
227:                    dbg = Logger.DEBUG9;
228:                    break;
229:                default:
230:                    dbg = Logger.DEBUG;
231:                    break;
232:                }
233:                Enhydra.getLogChannel().write(
234:                        dbg,
235:                        "PersistentSessionHome("
236:                                + Thread.currentThread().getName() + "): "
237:                                + msg);
238:            }
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.