tim@99: package de.intevation.gnv.artifacts.cache;
tim@99:
tim@99: import net.sf.ehcache.Cache;
tim@99: import net.sf.ehcache.CacheManager;
tim@99:
tim@99: import org.apache.log4j.Logger;
tim@99:
tim@99: /**
ingo@790: * The CacheFactory
is used to initialize and retrieve Cache.
sascha@803: *
sascha@780: * @author Tim Englich
tim@99: */
tim@99: public class CacheFactory {
tim@99:
tim@99: /**
tim@99: * the logger, used to log exceptions and additonaly information
tim@99: */
tim@99: private static Logger log = Logger.getLogger(CacheFactory.class);
tim@171:
tim@99: private final static String CACHENAME = "artifactdata";
tim@99:
tim@99: /**
tim@99: * The singleton Instance of this Factory.
tim@99: */
tim@99: private static CacheFactory instance = null;
tim@99:
tim@99: /**
sascha@778: *
tim@99: */
tim@99: private CacheManager cacheManager = null;
tim@99:
tim@99: /**
tim@99: * Basic-Constructor of this Class
tim@99: */
tim@99: private CacheFactory() {
tim@99: super();
tim@99: }
tim@99:
tim@99: /**
tim@99: * This Method provides an singleton Instance of this Class.
sascha@778: *
tim@99: * @return an singleton Instance of this Class
tim@99: */
tim@171: public static CacheFactory getInstance() {
tim@171: if (instance == null) {
tim@99: instance = new CacheFactory();
tim@99: }
tim@99: return instance;
tim@99: }
tim@171:
tim@99: /**
tim@99: * Getting the ConnectionPool
sascha@778: *
tim@99: * @return the ConnectionPool
tim@99: */
tim@171: public Cache getCache() {
tim@99: return this.cacheManager.getCache(CACHENAME);
tim@99: }
tim@99:
tim@99: /**
tim@171: * Initializes the ConnectionPool. Should only be called once on system
tim@171: * startup
sascha@778: *
ingo@790: * @param configurationFileName
tim@99: */
tim@171: public void initializeCache(String configurationFileName) {
tim@171: if (cacheManager == null) {
tim@99: cacheManager = new CacheManager(configurationFileName);
tim@99: cacheManager.addCache(CACHENAME);
tim@99: }
tim@99: }
tim@99:
tim@99: /**
tim@99: * Checks if the ConnectionPool has already been initialized.
sascha@778: *
tim@99: * @return true if the ConnectionPool is initialized.
tim@99: */
tim@171: public boolean isInitialized() {
tim@99: return this.cacheManager != null;
tim@99: }
tim@99:
tim@99: }