view gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/cache/CacheFactory.java @ 779:b1f5f2a8840f

Ordered imports. Removed needless imports. Removed empty headers. gnv-artifacts/trunk@854 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 29 Mar 2010 08:51:20 +0000
parents 9a828e5a2390
children c4156275c1e1
line wrap: on
line source
package de.intevation.gnv.artifacts.cache;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;

import org.apache.log4j.Logger;

/**
 * @author Tim Englich <tim.englich@intevation.de>
 *
 */
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;

    /**
     *
     */
    private CacheManager cacheManager = 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 properties
     *            the Properties for the Individual Configuration of the
     *            ConnectionPool
     */
    public void initializeCache(String configurationFileName) {
        if (cacheManager == null) {
            cacheManager = new CacheManager(configurationFileName);
            cacheManager.addCache(CACHENAME);
        }
    }

    /**
     * Checks if the ConnectionPool has already been initialized.
     *
     * @return true if the ConnectionPool is initialized.
     */
    public boolean isInitialized() {
        return this.cacheManager != null;
    }

}

http://dive4elements.wald.intevation.org