Source Code Cross Referenced for JigsawHttpSessionContext.java in  » Web-Server » Jigsaw » org » w3c » jigsaw » servlet » 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 » Web Server » Jigsaw » org.w3c.jigsaw.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // JigsawHttpSessionContext.java
002:        // $Id: JigsawHttpSessionContext.java,v 1.15 2007/02/11 10:56:04 ylafon Exp $
003:        // (c) COPYRIGHT MIT and INRIA, 1998.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.jigsaw.servlet;
007:
008:        import javax.servlet.http.HttpSession;
009:        import javax.servlet.http.HttpSessionContext;
010:
011:        import java.util.Date;
012:        import java.util.Enumeration;
013:        import java.util.Hashtable;
014:
015:        import org.w3c.util.ObservableProperties;
016:        import org.w3c.util.PropertyMonitoring;
017:
018:        import org.w3c.jigsaw.http.httpd;
019:
020:        /**
021:         * @version $Revision: 1.15 $
022:         * @author  Benoît Mahé (bmahe@w3.org)
023:         * @deprecated since jsdk2.1
024:         */
025:        public class JigsawHttpSessionContext implements  HttpSessionContext,
026:                PropertyMonitoring {
027:
028:            class SessionSweeper extends Thread {
029:
030:                int delay;
031:                JigsawHttpSessionContext ctxt = null;
032:
033:                public void run() {
034:                    while (true) {
035:                        try {
036:                            sleep(delay);
037:                        } catch (InterruptedException ex) {
038:                        }
039:                        ctxt.sweepSession();
040:                    }
041:                }
042:
043:                void setDelay(int delay) {
044:                    this .delay = delay;
045:                }
046:
047:                SessionSweeper(JigsawHttpSessionContext ctxt, int delay) {
048:                    super ("SessionSweeper");
049:                    this .delay = delay;
050:                    this .ctxt = ctxt;
051:                    setPriority(Thread.MIN_PRIORITY);
052:                    setDaemon(true);
053:                    this .start();
054:                }
055:
056:            }
057:
058:            private Hashtable sessions;
059:            private int sessionNb = 0;
060:            private int sessionCount = 0;
061:            private int maxsession;
062:            private long maxidle;
063:            private JigsawHttpSession oldestIdleSession = null;
064:            private SessionSweeper sweeper = null;
065:            private ServletProps props = null;
066:
067:            /**
068:             * PropertyMonitoring implementation.
069:             */
070:            public boolean propertyChanged(String name) {
071:                if (name.equals(ServletProps.SERVLET_SESSION_IDLE)) {
072:                    this .maxidle = props.getSessionsMaxIdleTime();
073:                } else if (name.equals(ServletProps.SERVLET_MAX_SESSION)) {
074:                    this .maxsession = props.getMaxSessionsNumber();
075:                } else if (name.equals(ServletProps.SERVLET_SESSION_SWEEP)) {
076:                    sweeper.setDelay(props.getSessionsSweepDelay());
077:                }
078:                return true;
079:            }
080:
081:            /**
082:             * Remove sessions with idle time > max idle time
083:             */
084:            protected synchronized void sweepSession() {
085:                long now = System.currentTimeMillis();
086:                Enumeration e = sessions.keys();
087:                oldestIdleSession = null;
088:                while (e.hasMoreElements()) {
089:                    JigsawHttpSession session = (JigsawHttpSession) sessions
090:                            .get(e.nextElement());
091:                    long interval = now - session.getLastAccessedTime();
092:                    int maxinactiveinterval = session.getMaxInactiveInterval() * 1000;
093:                    long maxinterval = (maxinactiveinterval > 0) ? maxinactiveinterval
094:                            : maxidle;
095:                    if (interval > maxinterval)
096:                        session.invalidate();
097:                    else {
098:                        if (oldestIdleSession != null) {
099:                            if (oldestIdleSession.getLastAccessedTime() > session
100:                                    .getLastAccessedTime())
101:                                oldestIdleSession = session;
102:                        } else {
103:                            oldestIdleSession = session;
104:                        }
105:                    }
106:                }
107:            }
108:
109:            protected synchronized void removeOldestIdleSession() {
110:                if (oldestIdleSession != null) {
111:                    oldestIdleSession.invalidate();
112:                    oldestIdleSession = null;
113:                }
114:            }
115:
116:            /**
117:             * Returns an enumeration of all of the session IDs in this context. 
118:             * @return an enumeration of all session IDs in this context.
119:             * @deprecated since jsdk2.1
120:             */
121:            public Enumeration getIds() {
122:                return sessions.keys();
123:            }
124:
125:            /**
126:             * Returns the session bound to the specified session ID.
127:             * @param sessionID - the ID of a particular session object 
128:             * @return the session. Returns null if the session ID does 
129:             * not refer to a valid session. 
130:             * @deprecated since jsdk2.1
131:             */
132:            public HttpSession getSession(String sessionId) {
133:                return (HttpSession) sessions.get(sessionId);
134:            }
135:
136:            /**
137:             * Add a session in this context.
138:             * @param session - The JigsawHttpSession to add.
139:             * @return The session ID.
140:             */
141:            protected synchronized String addSession(JigsawHttpSession session) {
142:                if (sessionCount >= maxsession)
143:                    removeOldestIdleSession();
144:                String id = getNewSessionId();
145:                sessions.put(id, session);
146:                sessionCount++;
147:                return id;
148:            }
149:
150:            /**
151:             * Remove a session of this session context.
152:             * @param id - The session ID.
153:             */
154:            protected void removeSession(String id) {
155:                sessions.remove(id);
156:                sessionCount--;
157:            }
158:
159:            private String getNewSessionId() {
160:                return "J" + String.valueOf(new Date().hashCode()) + "-"
161:                        + (sessionNb++);
162:            }
163:
164:            public JigsawHttpSessionContext(httpd server, ServletProps props) {
165:                this .props = props;
166:                this .sessions = new Hashtable(3);
167:                this .maxidle = props.getSessionsMaxIdleTime();
168:                this .maxsession = props.getMaxSessionsNumber();
169:                this .sweeper = new SessionSweeper(this, props
170:                        .getSessionsSweepDelay());
171:                server.getProperties().registerObserver(this);
172:            }
173:
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.