Source Code Cross Referenced for CmsVfsMemoryObjectCache.java in  » Content-Management-System » opencms » org » opencms » cache » 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 » Content Management System » opencms » org.opencms.cache 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/cache/CmsVfsMemoryObjectCache.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:54 $
004:         * Version: $Revision: 1.5 $
005:         *
006:         * This library is part of OpenCms -
007:         * the Open Source Content Management System
008:         *
009:         * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010:         *
011:         * This library is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Lesser General Public
013:         * License as published by the Free Software Foundation; either
014:         * version 2.1 of the License, or (at your option) any later version.
015:         *
016:         * This library is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019:         * Lesser General Public License for more details.
020:         *
021:         * For further information about Alkacon Software GmbH, please see the
022:         * company website: http://www.alkacon.com
023:         *
024:         * For further information about OpenCms, please see the
025:         * project website: http://www.opencms.org
026:         * 
027:         * You should have received a copy of the GNU Lesser General Public
028:         * License along with this library; if not, write to the Free Software
029:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030:         */
031:
032:        package org.opencms.cache;
033:
034:        import org.opencms.file.CmsObject;
035:        import org.opencms.file.CmsResource;
036:        import org.opencms.main.CmsEvent;
037:        import org.opencms.main.CmsLog;
038:        import org.opencms.main.I_CmsEventListener;
039:        import org.opencms.main.OpenCms;
040:        import org.opencms.xml.Messages;
041:
042:        import java.util.List;
043:
044:        import org.apache.commons.logging.Log;
045:
046:        /**
047:         * Implements a memory cache, that stores objects related to VFS files, 
048:         * providing a cache for the "online" and another for the "offline" project.<p>
049:         * 
050:         * @author Alexander Kandzior 
051:         * @author Michael Emmerich
052:         * 
053:         * @version $Revision: 1.5 $
054:         * 
055:         * @since 6.1.3
056:         */
057:        public final class CmsVfsMemoryObjectCache implements 
058:                I_CmsEventListener {
059:
060:            /** The log object for this class. */
061:            private static final Log LOG = CmsLog
062:                    .getLog(CmsVfsMemoryObjectCache.class);
063:
064:            /** A cache that maps VFS resource names to Objects. */
065:            private static CmsVfsMemoryObjectCache m_vfsMemoryObjectCache;
066:
067:            /**
068:             * Constructor, creates a new CmsVfsMemoryObjectCache.<p>
069:             */
070:            private CmsVfsMemoryObjectCache() {
071:
072:                // register the event listeners
073:                registerEventListener();
074:            }
075:
076:            /**
077:             * Returns the VFS memory Object cache.<p>
078:             * 
079:             * @return the VFS memory Object cache
080:             */
081:            public static CmsVfsMemoryObjectCache getVfsMemoryObjectCache() {
082:
083:                if (m_vfsMemoryObjectCache == null) {
084:                    m_vfsMemoryObjectCache = new CmsVfsMemoryObjectCache();
085:                }
086:                return m_vfsMemoryObjectCache;
087:            }
088:
089:            /**
090:             * @see org.opencms.main.I_CmsEventListener#cmsEvent(org.opencms.main.CmsEvent)
091:             */
092:            public void cmsEvent(CmsEvent event) {
093:
094:                CmsResource resource;
095:                switch (event.getType()) {
096:                case I_CmsEventListener.EVENT_PUBLISH_PROJECT:
097:                case I_CmsEventListener.EVENT_CLEAR_CACHES:
098:                    // flush cache   
099:                    OpenCms.getMemoryMonitor().flushVfsObjects();
100:                    if (LOG.isDebugEnabled()) {
101:                        LOG.debug(Messages.get().getBundle().key(
102:                                Messages.LOG_ER_FLUSHED_CACHES_0));
103:                    }
104:                    break;
105:                case I_CmsEventListener.EVENT_RESOURCE_MODIFIED:
106:                    resource = (CmsResource) event.getData().get("resource");
107:                    uncacheSystemId(resource.getRootPath());
108:                    break;
109:                case I_CmsEventListener.EVENT_RESOURCE_DELETED:
110:                case I_CmsEventListener.EVENT_RESOURCE_MOVED:
111:                    List resources = (List) event.getData().get("resources");
112:                    for (int i = 0; i < resources.size(); i++) {
113:                        resource = (CmsResource) resources.get(i);
114:                        uncacheSystemId(resource.getRootPath());
115:                    }
116:                    break;
117:                default:
118:                    // no operation
119:                }
120:            }
121:
122:            /**
123:             * Return an object from the cache.<p>
124:             * 
125:             * @param cms the current users OpenCms context
126:             * @param rootPath the rootPath of the VFS resource to get the object for 
127:             * @return object form cache or null
128:             */
129:            public Object getCachedObject(CmsObject cms, String rootPath) {
130:
131:                String key = getCacheKeyForCurrentProject(cms, rootPath);
132:                return OpenCms.getMemoryMonitor().getCachedVfsObject(key);
133:            }
134:
135:            /**
136:             * Puts an object into the cache.<p>
137:             * 
138:             * @param cms the CmsObject
139:             * @param rootPath the rootPath of the VFS resource to store the object for 
140:             * @param value the object to store
141:             */
142:            public void putCachedObject(CmsObject cms, String rootPath,
143:                    Object value) {
144:
145:                String key = getCacheKeyForCurrentProject(cms, rootPath);
146:                OpenCms.getMemoryMonitor().cacheVfsObject(key, value);
147:            }
148:
149:            /**
150:             * Registers all required event listeners.<p>
151:             */
152:            protected void registerEventListener() {
153:
154:                // register this object as event listener
155:                OpenCms.addCmsEventListener(this , new int[] {
156:                        I_CmsEventListener.EVENT_CLEAR_CACHES,
157:                        I_CmsEventListener.EVENT_PUBLISH_PROJECT,
158:                        I_CmsEventListener.EVENT_RESOURCE_MODIFIED,
159:                        I_CmsEventListener.EVENT_RESOURCE_MOVED,
160:                        I_CmsEventListener.EVENT_RESOURCE_DELETED });
161:            }
162:
163:            /**
164:             * Returns a cache key for the given system id (filename) based on the status 
165:             * of the given project flag.<p>
166:             * 
167:             * @param systemId the system id (filename) to get the cache key for
168:             * @param online indicates if this key is generated for the online project
169:             * 
170:             * @return the cache key for the system id
171:             */
172:            private String getCacheKey(String systemId, boolean online) {
173:
174:                if (online) {
175:                    return "online_".concat(systemId);
176:                }
177:                return "offline_".concat(systemId);
178:            }
179:
180:            /**
181:             * Returns a cache key for the given root path based on the status 
182:             * of the given CmsObject.<p>
183:             * 
184:             * @param cms the cms context
185:             * @param rootPath the filename to get the cache key for
186:             * 
187:             * @return the cache key for the system id
188:             */
189:            private String getCacheKeyForCurrentProject(CmsObject cms,
190:                    String rootPath) {
191:
192:                // check the project
193:                boolean project = (cms != null) ? cms.getRequestContext()
194:                        .currentProject().isOnlineProject() : false;
195:
196:                return getCacheKey(rootPath, project);
197:            }
198:
199:            /**
200:             * Uncaches a system id (filename) from the internal offline temporary and content defintions caches.<p>
201:             * 
202:             * The online resources cached for the online project are only flushed when a project is published.<p>
203:             * 
204:             * @param systemId the system id (filename) to uncache
205:             */
206:            private void uncacheSystemId(String systemId) {
207:
208:                String key = getCacheKey(systemId, false);
209:                Object o = OpenCms.getMemoryMonitor().getCachedVfsObject(key);
210:                OpenCms.getMemoryMonitor().uncacheVfsObject(key);
211:                if ((null != o) && LOG.isDebugEnabled()) {
212:                    LOG.debug(Messages.get().getBundle().key(
213:                            Messages.LOG_ER_UNCACHED_SYS_ID_1, key));
214:                }
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.