Source Code Cross Referenced for EhCacheEngine.java in  » Forum » JForum-2.1.8 » net » jforum » 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 » Forum » JForum 2.1.8 » net.jforum.cache 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * Sony Online Entertainment
003:         * Application Engineering
004:         *
005:         * Unpublished work Copyright 2005 Sony Online Entertainment Inc.
006:         * All rights reserved.
007:         * Created on Oct 11, 2005
008:         ******************************************************************************/package net.jforum.cache;
009:
010:        import java.io.Serializable;
011:        import java.util.ArrayList;
012:        import java.util.Collection;
013:        import java.util.Iterator;
014:        import java.util.List;
015:
016:        import net.jforum.util.preferences.SystemGlobals;
017:        import net.sf.ehcache.Cache;
018:        import net.sf.ehcache.CacheException;
019:        import net.sf.ehcache.CacheManager;
020:        import net.sf.ehcache.Element;
021:
022:        import org.apache.log4j.Logger;
023:
024:        /**
025:         * The rest of the application seems to make some invalid assumptions about how
026:         * things are cached.  Those assumptions might be benign, but it is hard to tell
027:         * without deep testing.  Until this is finishe the JBossCacheEngine should be 
028:         * configured in a local mode.
029:         *
030:         * Created on Oct 11, 2005 
031:         *
032:         * @author Jake Fear
033:         * @version $Id: EhCacheEngine.java,v 1.1 2005/10/14 00:15:54 rafaelsteil Exp $
034:         */
035:        public class EhCacheEngine implements  CacheEngine {
036:
037:            private static final Logger log = Logger
038:                    .getLogger(EhCacheEngine.class);
039:
040:            private CacheManager manager;
041:
042:            public void init() {
043:                try {
044:                    manager = CacheManager.create(SystemGlobals
045:                            .getValue("ehcache.cache.properties"));
046:                } catch (CacheException ce) {
047:                    log.error("EhCache could not be initialized", ce);
048:                    throw new RuntimeException(ce);
049:                }
050:            }
051:
052:            public void stop() {
053:                manager.shutdown();
054:            }
055:
056:            public void add(String key, Object value) {
057:                if (log.isDebugEnabled()) {
058:                    log.debug("Caching " + value + " with key " + key);
059:                }
060:                add(DUMMY_FQN, key, value);
061:            }
062:
063:            public void add(String fullyQualifiedName, String key, Object value) {
064:                if (!manager.cacheExists(fullyQualifiedName)) {
065:                    try {
066:                        manager.addCache(fullyQualifiedName);
067:                    } catch (CacheException ce) {
068:                        log.error(ce, ce);
069:                        throw new RuntimeException(ce);
070:                    }
071:                }
072:                Cache cache = manager.getCache(fullyQualifiedName);
073:
074:                Element element = new Element(key, (Serializable) value);
075:                cache.put(element);
076:            }
077:
078:            public Object get(String fullyQualifiedName, String key) {
079:                try {
080:                    if (!manager.cacheExists(fullyQualifiedName)) {
081:                        manager.addCache(fullyQualifiedName);
082:                        return null;
083:                    }
084:                    Cache cache = manager.getCache(fullyQualifiedName);
085:                    Element element = cache.get(key);
086:                    if (element != null) {
087:                        return element.getValue();
088:                    }
089:
090:                    return null;
091:                } catch (CacheException ce) {
092:                    log.error("EhCache could not be shutdown", ce);
093:                    throw new RuntimeException(ce);
094:                }
095:            }
096:
097:            public Object get(String fullyQualifiedName) {
098:                if (!manager.cacheExists(fullyQualifiedName)) {
099:                    try {
100:                        manager.addCache(fullyQualifiedName);
101:                    } catch (CacheException ce) {
102:                        log.error("EhCache could not be shutdown", ce);
103:                        throw new RuntimeException(ce);
104:                    }
105:                }
106:                Cache cache = manager.getCache(fullyQualifiedName);
107:                return cache;
108:            }
109:
110:            public Collection getValues(String fullyQualifiedName) {
111:                try {
112:                    if (!manager.cacheExists(fullyQualifiedName)) {
113:                        manager.addCache(fullyQualifiedName);
114:                        return new ArrayList();
115:                    }
116:                    Cache cache = manager.getCache(fullyQualifiedName);
117:                    List values = new ArrayList(cache.getSize());
118:                    List keys = cache.getKeys();
119:
120:                    for (Iterator iter = keys.iterator(); iter.hasNext();) {
121:                        values.add(cache.get((Serializable) iter.next()));
122:                    }
123:
124:                    return values;
125:                } catch (CacheException ce) {
126:                    log.error("EhCache could not be shutdown", ce);
127:                    throw new RuntimeException(ce);
128:                }
129:            }
130:
131:            public void remove(String fullyQualifiedName, String key) {
132:                Cache cache = manager.getCache(fullyQualifiedName);
133:
134:                if (cache != null) {
135:                    cache.remove(key);
136:                }
137:            }
138:
139:            public void remove(String fullyQualifiedName) {
140:                if (manager.cacheExists(fullyQualifiedName)) {
141:                    manager.removeCache(fullyQualifiedName);
142:                }
143:            }
144:
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.