All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.diirt.datasource.timecache.CacheImpl Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2010-14 diirt developers. See COPYRIGHT.TXT
 * All rights reserved. Use is subject to license terms. See LICENSE.TXT
 */
package org.diirt.datasource.timecache;

import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import org.diirt.datasource.timecache.query.Query;
import org.diirt.datasource.timecache.query.QueryImpl;
import org.diirt.datasource.timecache.query.QueryParameters;
import org.diirt.vtype.VType;

/**
 * @author Fred Arnaud (Sopra Group) - ITER
 */
public class CacheImpl implements Cache {

	private boolean statisticsEnabled = false;
	private Map cachedPVs = new ConcurrentHashMap();

	/** {@inheritDoc} */
	@Override
	public  Query createQuery(String channelName,
			Class type, QueryParameters parameters) {
		PVCache pvCache = (PVCache) cachedPVs.get(channelName);
		if (pvCache == null) {
			pvCache = PVCacheFactory.createPVCache(channelName, type);
			pvCache.setStatisticsEnabled(statisticsEnabled);
			cachedPVs.put(channelName, pvCache);
		}
		Query query = new QueryImpl(pvCache);
		query.update(parameters);
		return query;
	}

	/**
	 * @return number of initialised {@link PVCache}.
	 */
	public int getCount() {
		return cachedPVs.size();
	}

	/** {@inheritDoc} */
	@Override
	public void setStatisticsEnabled(boolean enabled) {
		this.statisticsEnabled = enabled;
		for (PVCache pvCache : cachedPVs.values())
			pvCache.setStatisticsEnabled(statisticsEnabled);
	}

	/** {@inheritDoc} */
	@Override
	public CacheStatistics getStatistics() {
		final CacheStatistics stats = new CacheStatistics();
		for (Entry entry : cachedPVs.entrySet())
			stats.addStats(entry.getKey(), entry.getValue().getStatistics());
		return stats;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy