Source Code Cross Referenced for SiteCacheImpl.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » site » impl » 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 » ERP CRM Financial » sakai » org.sakaiproject.site.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/site/tags/sakai_2-4-1/site-impl/impl/src/java/org/sakaiproject/site/impl/SiteCacheImpl.java $
003:         * $Id: SiteCacheImpl.java 12713 2006-07-24 04:10:41Z ggolden@umich.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.site.impl;
021:
022:        import java.util.Iterator;
023:        import java.util.Map;
024:
025:        import org.sakaiproject.memory.api.Cache;
026:        import org.sakaiproject.memory.api.DerivedCache;
027:        import org.sakaiproject.memory.api.MemoryService;
028:        import org.sakaiproject.site.api.Group;
029:        import org.sakaiproject.site.api.Site;
030:        import org.sakaiproject.site.api.SitePage;
031:        import org.sakaiproject.site.api.ToolConfiguration;
032:
033:        import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
034:
035:        /**
036:         * <p>
037:         * SiteCacheImpl is a cache tuned for Site (and page / tool) access.
038:         * </p>
039:         */
040:        public class SiteCacheImpl implements  DerivedCache {
041:            /** Map of a tool id to a cached site's tool configuration instance. */
042:            protected Map m_tools = new ConcurrentReaderHashMap();
043:
044:            /** Map of a page id to a cached site's SitePage instance. */
045:            protected Map m_pages = new ConcurrentReaderHashMap();
046:
047:            /** Map of a group id to a cached site's Group instance. */
048:            protected Map m_groups = new ConcurrentReaderHashMap();
049:
050:            /** The base cache. */
051:            protected Cache m_cache = null;
052:
053:            /**
054:             * Construct the Cache. No automatic refresh: expire only, from time and events.
055:             * 
056:             * @param sleep
057:             *        The number of seconds to sleep between expiration checks.
058:             * @param pattern
059:             *        The "startsWith()" string for all resources that may be in this cache - if null, don't watch events for updates.
060:             */
061:            public SiteCacheImpl(MemoryService memoryService, long sleep,
062:                    String pattern) {
063:                m_cache = memoryService.newHardCache(sleep, pattern);
064:
065:                // setup as the derived cache
066:                m_cache.attachDerivedCache(this );
067:            }
068:
069:            /**
070:             * Cache an object
071:             * 
072:             * @param key
073:             *        The key with which to find the object.
074:             * @param payload
075:             *        The object to cache.
076:             * @param duration
077:             *        The time to cache the object (seconds).
078:             */
079:            public void put(Object key, Object payload, int duration) {
080:                m_cache.put(key, payload, duration);
081:            }
082:
083:            /**
084:             * Test for a non expired entry in the cache.
085:             * 
086:             * @param key
087:             *        The cache key.
088:             * @return true if the key maps to a non-expired cache entry, false if not.
089:             */
090:            public boolean containsKey(Object key) {
091:                return m_cache.containsKey(key);
092:            }
093:
094:            /**
095:             * Get the non expired entry, or null if not there (or expired)
096:             * 
097:             * @param key
098:             *        The cache key.
099:             * @return The payload, or null if the payload is null, the key is not found, or the entry has expired (Note: use containsKey() to remove this ambiguity).
100:             */
101:            public Object get(Object key) {
102:                return m_cache.get(key);
103:            }
104:
105:            /**
106:             * Clear all entries.
107:             */
108:            public void clear() {
109:                m_cache.clear();
110:            }
111:
112:            /**
113:             * Remove this entry from the cache.
114:             * 
115:             * @param key
116:             *        The cache key.
117:             */
118:            public void remove(Object key) {
119:                m_cache.remove(key);
120:            }
121:
122:            /**
123:             * Access the tool that is part of a cached site, by tool Id.
124:             * 
125:             * @param toolId
126:             *        The tool's id.
127:             * @return The ToolConfiguration that has this id, from a cached site.
128:             */
129:            public ToolConfiguration getTool(String toolId) {
130:                return (ToolConfiguration) m_tools.get(toolId);
131:            }
132:
133:            /**
134:             * Access the page that is part of a cached site, by page Id.
135:             * 
136:             * @param pageId
137:             *        The page's id.
138:             * @return The SitePage that has this id, from a cached site.
139:             */
140:            public SitePage getPage(String pageId) {
141:                return (SitePage) m_pages.get(pageId);
142:            }
143:
144:            /**
145:             * Access the group that is part of a cached site, by group Id.
146:             * 
147:             * @param id
148:             *        The group id.
149:             * @return The Group that has this id, from a cached site.
150:             */
151:            public Group getGroup(String groupId) {
152:                return (Group) m_groups.get(groupId);
153:            }
154:
155:            /**
156:             * {@inheritDoc}
157:             */
158:            public void notifyCacheClear() {
159:                // clear the tool ids
160:                m_tools.clear();
161:
162:                // clear the pages
163:                m_pages.clear();
164:
165:                // clear the groups
166:                m_groups.clear();
167:            }
168:
169:            /**
170:             * {@inheritDoc}
171:             */
172:            public void notifyCachePut(Object key, Object payload) {
173:                // add the payload (Site) tool ids
174:                if (payload instanceof  Site) {
175:                    Site site = (Site) payload;
176:
177:                    // get the pages and tools, groups and propeties all loaded efficiently
178:                    site.loadAll();
179:
180:                    // add the pages and tools to the cache
181:                    for (Iterator pages = site.getPages().iterator(); pages
182:                            .hasNext();) {
183:                        SitePage page = (SitePage) pages.next();
184:                        m_pages.put(page.getId(), page);
185:                        for (Iterator tools = page.getTools().iterator(); tools
186:                                .hasNext();) {
187:                            ToolConfiguration tool = (ToolConfiguration) tools
188:                                    .next();
189:                            m_tools.put(tool.getId(), tool);
190:                        }
191:                    }
192:
193:                    // add the groups to the cache
194:                    for (Iterator groups = site.getGroups().iterator(); groups
195:                            .hasNext();) {
196:                        Group group = (Group) groups.next();
197:                        m_groups.put(group.getId(), group);
198:                    }
199:                }
200:            }
201:
202:            /**
203:             * {@inheritDoc}
204:             */
205:            public void notifyCacheRemove(Object key, Object payload) {
206:                // clear the tool ids for this site
207:                if ((payload != null) && (payload instanceof  Site)) {
208:                    Site site = (Site) payload;
209:                    for (Iterator pages = site.getPages().iterator(); pages
210:                            .hasNext();) {
211:                        SitePage page = (SitePage) pages.next();
212:                        m_pages.remove(page.getId());
213:                        for (Iterator tools = page.getTools().iterator(); tools
214:                                .hasNext();) {
215:                            ToolConfiguration tool = (ToolConfiguration) tools
216:                                    .next();
217:                            m_tools.remove(tool.getId());
218:                        }
219:                    }
220:
221:                    for (Iterator groups = site.getGroups().iterator(); groups
222:                            .hasNext();) {
223:                        Group group = (Group) groups.next();
224:                        m_groups.remove(group.getId());
225:                    }
226:                }
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.