Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/cache/CacheFactory.java @ 1145:dfe1ac687c7f tip
added tags
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:16:15 +0200 |
parents | f953c9a559d8 |
children |
line wrap: on
line source
/* * Copyright (c) 2010 by Intevation GmbH * * This program is free software under the LGPL (>=v2.1) * Read the file LGPL.txt coming with the software for details * or visit http://www.gnu.org/licenses/ if it does not exist. */ package de.intevation.gnv.artifacts.cache; import java.lang.management.ManagementFactory; import javax.management.MBeanServer; import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; import net.sf.ehcache.management.ManagementService; import org.apache.log4j.Logger; import de.intevation.gnv.geobackend.base.query.cache.CacheCleaner; import de.intevation.gnv.state.cache.ThematicDataCacheCleaner; /** * The <code>CacheFactory</code> is used to initialize and retrieve Cache. * * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a> */ public class CacheFactory { /** * the logger, used to log exceptions and additonaly information */ private static Logger log = Logger.getLogger(CacheFactory.class); private final static String CACHENAME = "artifactdata"; /** * The singleton Instance of this Factory. */ private static CacheFactory instance = null; /** * The manager of the Cache */ private CacheManager cacheManager = null; /** * The Cleaner of the Cache */ private CacheCleaner cacheCleaner = null; /** * Basic-Constructor of this Class */ private CacheFactory() { super(); } /** * This Method provides an singleton Instance of this Class. * * @return an singleton Instance of this Class */ public static CacheFactory getInstance() { if (instance == null) { instance = new CacheFactory(); } return instance; } /** * Getting the ConnectionPool * * @return the ConnectionPool */ public Cache getCache() { return this.cacheManager.getCache(CACHENAME); } /** * Initializes the ConnectionPool. Should only be called once on system * startup * * @param configurationFileName */ public void initializeCache(String configurationFileName) { if (cacheManager == null) { cacheManager = new CacheManager(configurationFileName); cacheManager.addCache(CACHENAME); MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer(); ManagementService.registerMBeans( cacheManager, beanServer, false, false, false, true); this.cacheCleaner = new ThematicDataCacheCleaner(); this.cacheCleaner.start(); } } /** * Checks if the ConnectionPool has already been initialized. * * @return true if the ConnectionPool is initialized. */ public boolean isInitialized() { return this.cacheManager != null; } }