Source Code Cross Referenced for EhCacheManagerFactoryBean.java in  » J2EE » spring-framework-2.0.6 » org » springframework » cache » ehcache » 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 » J2EE » spring framework 2.0.6 » org.springframework.cache.ehcache 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2006 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.cache.ehcache;
018:
019:        import java.io.IOException;
020:
021:        import net.sf.ehcache.CacheException;
022:        import net.sf.ehcache.CacheManager;
023:        import org.apache.commons.logging.Log;
024:        import org.apache.commons.logging.LogFactory;
025:
026:        import org.springframework.beans.factory.DisposableBean;
027:        import org.springframework.beans.factory.FactoryBean;
028:        import org.springframework.beans.factory.InitializingBean;
029:        import org.springframework.core.io.Resource;
030:
031:        /**
032:         * FactoryBean that exposes an EHCache {@link net.sf.ehcache.CacheManager} instance
033:         * (independent or shared), configured from a specified config location.
034:         *
035:         * <p>If no config location is specified, a CacheManager will be configured from
036:         * "ehcache.xml" in the root of the class path (that is, default EHCache initialization
037:         * - as defined in the EHCache docs - will apply).
038:         *
039:         * <p>Setting up a separate EhCacheManagerFactoryBean is also advisable when using
040:         * EhCacheFactoryBean, as it provides a (by default) independent CacheManager instance
041:         * and cares for proper shutdown of the CacheManager. EhCacheManagerFactoryBean is
042:         * also necessary for loading EHCache configuration from a non-default config location.
043:         *
044:         * <p>Note: As of Spring 2.0, this FactoryBean will by default create an independent
045:         * CacheManager instance, which requires EHCache 1.2 or higher. Set the "shared"
046:         * flag to "true" to create a CacheManager instance that is shared at the VM level
047:         * (which is also compatible with EHCache 1.1).
048:         *
049:         * @author Dmitriy Kopylenko
050:         * @author Juergen Hoeller
051:         * @since 1.1.1
052:         * @see #setConfigLocation
053:         * @see #setShared
054:         * @see EhCacheFactoryBean
055:         * @see net.sf.ehcache.CacheManager
056:         */
057:        public class EhCacheManagerFactoryBean implements  FactoryBean,
058:                InitializingBean, DisposableBean {
059:
060:            protected final Log logger = LogFactory.getLog(getClass());
061:
062:            private Resource configLocation;
063:
064:            private boolean shared = false;
065:
066:            private CacheManager cacheManager;
067:
068:            /**
069:             * Set the location of the EHCache config file. A typical value is "/WEB-INF/ehcache.xml".
070:             * <p>Default is "ehcache.xml" in the root of the class path, or if not found,
071:             * "ehcache-failsafe.xml" in the EHCache jar (default EHCache initialization).
072:             */
073:            public void setConfigLocation(Resource configLocation) {
074:                this .configLocation = configLocation;
075:            }
076:
077:            /**
078:             * Set whether the EHCache CacheManager should be shared (as a singleton at the VM level)
079:             * or independent (typically local within the application). Default is "false", creating
080:             * an independent instance.
081:             * <p>Note that independent CacheManager instances are only available on EHCache 1.2 and
082:             * higher. Switch this flag to "true" if you intend to run against an EHCache 1.1 jar.
083:             */
084:            public void setShared(boolean shared) {
085:                this .shared = shared;
086:            }
087:
088:            public void afterPropertiesSet() throws IOException, CacheException {
089:                logger.info("Initializing EHCache CacheManager");
090:                if (this .shared) {
091:                    // Shared CacheManager singleton at the VM level.
092:                    if (this .configLocation != null) {
093:                        this .cacheManager = CacheManager
094:                                .create(this .configLocation.getInputStream());
095:                    } else {
096:                        this .cacheManager = CacheManager.create();
097:                    }
098:                } else {
099:                    // Independent CacheManager instance (the default).
100:                    if (this .configLocation != null) {
101:                        this .cacheManager = new CacheManager(
102:                                this .configLocation.getInputStream());
103:                    } else {
104:                        this .cacheManager = new CacheManager();
105:                    }
106:                }
107:            }
108:
109:            public Object getObject() {
110:                return this .cacheManager;
111:            }
112:
113:            public Class getObjectType() {
114:                return (this .cacheManager != null ? this .cacheManager
115:                        .getClass() : CacheManager.class);
116:            }
117:
118:            public boolean isSingleton() {
119:                return true;
120:            }
121:
122:            public void destroy() {
123:                logger.info("Shutting down EHCache CacheManager");
124:                this.cacheManager.shutdown();
125:            }
126:
127:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.