comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/cache/CacheFactory.java @ 99:bb45c5097cb6

ehcache Integration for storing the chartresultvalues gnv-artifacts/trunk@146 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 28 Sep 2009 14:17:15 +0000
parents
children 7fb9441dd8af
comparison
equal deleted inserted replaced
98:156db25ad4b4 99:bb45c5097cb6
1 /**
2 *
3 */
4 package de.intevation.gnv.artifacts.cache;
5
6 import net.sf.ehcache.Cache;
7 import net.sf.ehcache.CacheManager;
8
9 import org.apache.log4j.Logger;
10
11 /**
12 * @author Tim Englich <tim.englich@intevation.de>
13 *
14 */
15 public class CacheFactory {
16
17 /**
18 * the logger, used to log exceptions and additonaly information
19 */
20 private static Logger log = Logger.getLogger(CacheFactory.class);
21
22 private final static String CACHENAME = "artifactdata";
23
24
25 /**
26 * The singleton Instance of this Factory.
27 */
28 private static CacheFactory instance = null;
29
30 /**
31 *
32 */
33 private CacheManager cacheManager = null;
34
35 /**
36 * Basic-Constructor of this Class
37 */
38 private CacheFactory() {
39 super();
40 }
41
42 /**
43 * This Method provides an singleton Instance of this Class.
44 * @return an singleton Instance of this Class
45 */
46 public static CacheFactory getInstance(){
47 if (instance == null){
48 instance = new CacheFactory();
49 }
50 return instance;
51 }
52
53
54 /**
55 * Getting the ConnectionPool
56 * @return the ConnectionPool
57 */
58 public Cache getCache(){
59 return this.cacheManager.getCache(CACHENAME);
60 }
61
62 /**
63 * Initializes the ConnectionPool.
64 * Should only be called once on system startup
65 * @param properties the Properties for the Individual Configuration of the ConnectionPool
66 */
67 public void initializeCache(String configurationFileName){
68 if (cacheManager == null){
69 cacheManager = new CacheManager(configurationFileName);
70 cacheManager.addCache(CACHENAME);
71 }
72 }
73
74 /**
75 * Checks if the ConnectionPool has already been initialized.
76 * @return true if the ConnectionPool is initialized.
77 */
78 public boolean isInitialized(){
79 return this.cacheManager != null;
80 }
81
82 }

http://dive4elements.wald.intevation.org