Source Code Cross Referenced for Activator.java in  » Web-Server » simple » simple » http » session » 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 » simple » simple.http.session 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Activator.java May 2004
003:         *
004:         * Copyright (C) 2004, Niall Gallagher <niallg@users.sf.net>
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:         * GNU Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General
016:         * Public License along with this library; if not, write to the
017:         * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
018:         * Boston, MA  02111-1307  USA
019:         */
020:
021:        package simple.http.session;
022:
023:        import simple.util.lease.Lease;
024:        import simple.util.lease.LeaseException;
025:        import simple.util.net.Cookie;
026:        import simple.http.State;
027:
028:        /**
029:         * The <code>Activator</code> object is responsible for creating
030:         * and retrieving <code>Session</code> objects. This deals with
031:         * <code>Module</code> objects, which it uses to create sessions
032:         * and renew the leases for the sessions. To ensure maximum
033:         * flexibility in renewing leases for the system this makes use
034:         * of a <code>Maintainer</code> component. This component is
035:         * used to renew the lease for a session once that session has
036:         * been referenced. If the session lease cannot be renewed this
037:         * will attempt to create a new one.
038:         *
039:         * @author Niall Gallagher
040:         *
041:         * @see simple.http.session.Maintainer
042:         * @see simple.http.session.Identifier
043:         */
044:        final class Activator {
045:
046:            /**
047:             * This is used to manage session modules for the system.
048:             */
049:            private Registry registry;
050:
051:            /**
052:             * This is used to renew the leases for session modules.
053:             */
054:            private Maintainer manager;
055:
056:            /**
057:             * This is used to identify the session reference cookie.
058:             */
059:            private Identifier lookup;
060:
061:            /**
062:             * Constructor for the <code>Activator</code> object. This is
063:             * used to create a session management system that will lease
064:             * the sessions created for a peroid of time. Each time this
065:             * instance is used to activate the session the lease is
066:             * renewed for the same fixed peroid of time.
067:             */
068:            public Activator() {
069:                this (new Registry());
070:            }
071:
072:            /**
073:             * Constructor for the <code>Activator</code> object. This is
074:             * used to create a session management system that will lease
075:             * the sessions created for a peroid of time. Each time this
076:             * instance is used to activate the session the lease is
077:             * renewed for the same fixed peroid of time.
078:             *
079:             * @param registry this is used to manage session modules
080:             */
081:            private Activator(Registry registry) {
082:                this .manager = MaintainerFactory.getInstance();
083:                this .lookup = IdentifierFactory.getInstance();
084:                this .registry = registry;
085:            }
086:
087:            /**
088:             * This will either retrieve an active session or create a
089:             * new one. The <code>Session</code> object is created if the
090:             * <code>State</code> does not have a reference to an active
091:             * session. If a session has expired and the session reference
092:             * is provided, this will create a new session using the
093:             * existing reference. Once a <code>Session</code> has been
094:             * created a <code>Cookie</code> is set with its reference.
095:             *
096:             * @param state contains all the cookies with a request
097:             *
098:             * @return returns an active <code>Session</code> object
099:             */
100:            public Session activate(State state) {
101:                return activate(state, null);
102:            }
103:
104:            /**
105:             * This will either retrieve an active session or create a
106:             * new one. The <code>Session</code> object is created if the
107:             * <code>State</code> does not have a reference to an active
108:             * session. If a session has expired and the session reference
109:             * is provided, this will create a new session using the
110:             * existing reference. Once a <code>Session</code> has been
111:             * created a <code>Cookie</code> is set with its reference.
112:             *
113:             * @param state contains all the cookies with a request
114:             * @param data this is used to initialize the storage object
115:             *
116:             * @return returns an active <code>Session</code> object
117:             */
118:            public Session activate(State state, Object data) {
119:                return activate(lookup.getIdentity(state), data);
120:            }
121:
122:            /**
123:             * This will either retrieve an active session or create a
124:             * new one. The <code>Session</code> object is created if the
125:             * issued <code>Cookie</code> is not a reference to an active
126:             * session. If a session has expired the session reference
127:             * provided is used to reference the new session.
128:             *
129:             * @param cookie the cookie used as the session reference
130:             * @param data this is used to initialize the storage object
131:             *
132:             * @return returns an active <code>Session</code> object
133:             */
134:            private Session activate(Cookie cookie, Object data) {
135:                try {
136:                    Module module = retrieve(cookie, data);
137:                    return new Delegate(module, cookie);
138:                } catch (LeaseException e) {
139:                    return null;
140:                }
141:            }
142:
143:            /**
144:             * This will retrieve or create a <code>Module</code> object
145:             * to represent a <code>Session</code>. The module is created
146:             * if the issued <code>Cookie</code> is not a reference to an
147:             * active session. Once the module is created the lease for
148:             * it is renewed using the <code>Maintainer</code> object.
149:             *
150:             * @param cookie the cookie used as the session reference
151:             * @param data this is used to initialize the storage object
152:             *
153:             * @return returns an active <code>Module</code> object
154:             */
155:            private Module retrieve(Cookie cookie, Object data)
156:                    throws LeaseException {
157:                Module module = registry.lookup(cookie, data);
158:                try {
159:                    Lease lease = module.getLease();
160:                    Store store = module.getStore();
161:
162:                    manager.renew(lease, store);
163:                } catch (LeaseException e) {
164:                    throw new LeaseException("Lease expired");
165:                }
166:                return module;
167:            }
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.