org.diirt.datasource.timecache.CacheImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datasource-timecache Show documentation
Show all versions of datasource-timecache Show documentation
Local cache for time series gathered from multiple sources.
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;
}
}