Source Code Cross Referenced for StoreBase.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » catalina » 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 » Sevlet Container » apache tomcat 6.0.14 » org.apache.catalina.session 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.catalina.session;
019:
020:        import java.beans.PropertyChangeListener;
021:        import java.beans.PropertyChangeSupport;
022:        import java.io.IOException;
023:
024:        import org.apache.catalina.Lifecycle;
025:        import org.apache.catalina.LifecycleException;
026:        import org.apache.catalina.LifecycleListener;
027:        import org.apache.catalina.Manager;
028:        import org.apache.catalina.Store;
029:        import org.apache.catalina.util.LifecycleSupport;
030:        import org.apache.catalina.util.StringManager;
031:
032:        /**
033:         * Abstract implementation of the Store interface to
034:         * support most of the functionality required by a Store.
035:         *
036:         * @author Bip Thelin
037:         * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
038:         */
039:
040:        public abstract class StoreBase implements  Lifecycle, Store {
041:
042:            // ----------------------------------------------------- Instance Variables
043:
044:            /**
045:             * The descriptive information about this implementation.
046:             */
047:            protected static String info = "StoreBase/1.0";
048:
049:            /**
050:             * Name to register for this Store, used for logging.
051:             */
052:            protected static String storeName = "StoreBase";
053:
054:            /**
055:             * Has this component been started yet?
056:             */
057:            protected boolean started = false;
058:
059:            /**
060:             * The lifecycle event support for this component.
061:             */
062:            protected LifecycleSupport lifecycle = new LifecycleSupport(this );
063:
064:            /**
065:             * The property change support for this component.
066:             */
067:            protected PropertyChangeSupport support = new PropertyChangeSupport(
068:                    this );
069:
070:            /**
071:             * The string manager for this package.
072:             */
073:            protected StringManager sm = StringManager
074:                    .getManager(Constants.Package);
075:
076:            /**
077:             * The Manager with which this JDBCStore is associated.
078:             */
079:            protected Manager manager;
080:
081:            // ------------------------------------------------------------- Properties
082:
083:            /**
084:             * Return the info for this Store.
085:             */
086:            public String getInfo() {
087:                return (info);
088:            }
089:
090:            /**
091:             * Return the name for this Store, used for logging.
092:             */
093:            public String getStoreName() {
094:                return (storeName);
095:            }
096:
097:            /**
098:             * Set the Manager with which this Store is associated.
099:             *
100:             * @param manager The newly associated Manager
101:             */
102:            public void setManager(Manager manager) {
103:                Manager oldManager = this .manager;
104:                this .manager = manager;
105:                support.firePropertyChange("manager", oldManager, this .manager);
106:            }
107:
108:            /**
109:             * Return the Manager with which the Store is associated.
110:             */
111:            public Manager getManager() {
112:                return (this .manager);
113:            }
114:
115:            // --------------------------------------------------------- Public Methods
116:
117:            /**
118:             * Add a lifecycle event listener to this component.
119:             *
120:             * @param listener The listener to add
121:             */
122:            public void addLifecycleListener(LifecycleListener listener) {
123:                lifecycle.addLifecycleListener(listener);
124:            }
125:
126:            /**
127:             * Get the lifecycle listeners associated with this lifecycle. If this 
128:             * Lifecycle has no listeners registered, a zero-length array is returned.
129:             */
130:            public LifecycleListener[] findLifecycleListeners() {
131:
132:                return lifecycle.findLifecycleListeners();
133:
134:            }
135:
136:            /**
137:             * Remove a lifecycle event listener from this component.
138:             *
139:             * @param listener The listener to add
140:             */
141:            public void removeLifecycleListener(LifecycleListener listener) {
142:                lifecycle.removeLifecycleListener(listener);
143:            }
144:
145:            /**
146:             * Add a property change listener to this component.
147:             *
148:             * @param listener a value of type 'PropertyChangeListener'
149:             */
150:            public void addPropertyChangeListener(
151:                    PropertyChangeListener listener) {
152:                support.addPropertyChangeListener(listener);
153:            }
154:
155:            /**
156:             * Remove a property change listener from this component.
157:             *
158:             * @param listener The listener to remove
159:             */
160:            public void removePropertyChangeListener(
161:                    PropertyChangeListener listener) {
162:                support.removePropertyChangeListener(listener);
163:            }
164:
165:            // --------------------------------------------------------- Protected Methods
166:
167:            /**
168:             * Called by our background reaper thread to check if Sessions
169:             * saved in our store are subject of being expired. If so expire
170:             * the Session and remove it from the Store.
171:             *
172:             */
173:            public void processExpires() {
174:                long timeNow = System.currentTimeMillis();
175:                String[] keys = null;
176:
177:                if (!started) {
178:                    return;
179:                }
180:
181:                try {
182:                    keys = keys();
183:                } catch (IOException e) {
184:                    manager.getContainer().getLogger().error(
185:                            "Error getting keys", e);
186:                    return;
187:                }
188:                if (manager.getContainer().getLogger().isDebugEnabled()) {
189:                    manager.getContainer().getLogger().debug(
190:                            getStoreName()
191:                                    + ": processExpires check number of "
192:                                    + keys.length + " sessions");
193:                }
194:
195:                for (int i = 0; i < keys.length; i++) {
196:                    try {
197:                        StandardSession session = (StandardSession) load(keys[i]);
198:                        if (session == null) {
199:                            continue;
200:                        }
201:                        if (session.isValid()) {
202:                            continue;
203:                        }
204:                        if (manager.getContainer().getLogger().isDebugEnabled()) {
205:                            manager
206:                                    .getContainer()
207:                                    .getLogger()
208:                                    .debug(
209:                                            getStoreName()
210:                                                    + ": processExpires expire store session "
211:                                                    + keys[i]);
212:                        }
213:                        if (((PersistentManagerBase) manager).isLoaded(keys[i])) {
214:                            // recycle old backup session
215:                            session.recycle();
216:                        } else {
217:                            // expire swapped out session
218:                            session.expire();
219:                        }
220:                        remove(session.getIdInternal());
221:                    } catch (Exception e) {
222:                        manager.getContainer().getLogger().error(
223:                                "Session: " + keys[i] + "; ", e);
224:                        try {
225:                            remove(keys[i]);
226:                        } catch (IOException e2) {
227:                            manager.getContainer().getLogger().error(
228:                                    "Error removing key", e2);
229:                        }
230:                    }
231:                }
232:            }
233:
234:            // --------------------------------------------------------- Thread Methods
235:
236:            /**
237:             * Prepare for the beginning of active use of the public methods of this
238:             * component.  This method should be called after <code>configure()</code>,
239:             * and before any of the public methods of the component are utilized.
240:             *
241:             * @exception LifecycleException if this component detects a fatal error
242:             *  that prevents this component from being used
243:             */
244:            public void start() throws LifecycleException {
245:                // Validate and update our current component state
246:                if (started)
247:                    throw new LifecycleException(sm.getString(getStoreName()
248:                            + ".alreadyStarted"));
249:                lifecycle.fireLifecycleEvent(START_EVENT, null);
250:                started = true;
251:
252:            }
253:
254:            /**
255:             * Gracefully terminate the active use of the public methods of this
256:             * component.  This method should be the last one called on a given
257:             * instance of this component.
258:             *
259:             * @exception LifecycleException if this component detects a fatal error
260:             *  that needs to be reported
261:             */
262:            public void stop() throws LifecycleException {
263:                // Validate and update our current component state
264:                if (!started)
265:                    throw new LifecycleException(sm.getString(getStoreName()
266:                            + ".notStarted"));
267:                lifecycle.fireLifecycleEvent(STOP_EVENT, null);
268:                started = false;
269:
270:            }
271:
272:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.