tim@99: package de.intevation.gnv.artifacts.cache; tim@99: ingo@1065: import java.lang.management.ManagementFactory; ingo@1065: ingo@1065: import javax.management.MBeanServer; ingo@1065: tim@99: import net.sf.ehcache.Cache; tim@99: import net.sf.ehcache.CacheManager; tim@99: ingo@1065: import net.sf.ehcache.management.ManagementService; ingo@1065: tim@99: import org.apache.log4j.Logger; tim@99: tim@845: import de.intevation.gnv.geobackend.base.query.cache.CacheCleaner; tim@845: import de.intevation.gnv.state.cache.ThematicDataCacheCleaner; tim@845: 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: /** tim@845: * The manager of the Cache tim@99: */ tim@99: private CacheManager cacheManager = null; tim@99: tim@99: /** tim@845: * The Cleaner of the Cache tim@845: */ tim@845: private CacheCleaner cacheCleaner = null; tim@845: tim@845: /** 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); ingo@1065: ingo@1065: MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer(); ingo@1065: ManagementService.registerMBeans( ingo@1065: cacheManager, beanServer, false, false, false, true); ingo@1065: tim@845: this.cacheCleaner = new ThematicDataCacheCleaner(); tim@845: this.cacheCleaner.start(); 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: }