use of com.infiniteautomation.mango.pointvaluecache.PointValueCache in project ma-core-public by infiniteautomation.
the class DataSourceRT method initializePoints.
/**
* The {@link DataPointGroupInitializer} calls
* {@link RuntimeManager#startDataPoint(DataPointWithEventDetectors, List) startDataPoint()}
* which adds the data points to the cache in the RTM and initializes them.
*/
private void initializePoints() {
DataPointDao dataPointDao = Common.getBean(DataPointDao.class);
ExecutorService executorService = Common.getBean(ExecutorService.class);
PointValueCache pointValueCache = Common.getBean(PointValueCache.class);
// Add the enabled points to the data source.
List<DataPointWithEventDetectors> dataSourcePoints = dataPointDao.getDataPointsForDataSourceStart(getId());
// Startup multi threaded
int pointsPerThread = Common.envProps.getInt("runtime.datapoint.startupThreads.pointsPerThread", 1000);
int startupThreads = Common.envProps.getInt("runtime.datapoint.startupThreads", Runtime.getRuntime().availableProcessors());
DataPointGroupInitializer pointInitializer = new DataPointGroupInitializer(executorService, startupThreads, pointValueCache);
pointInitializer.initialize(dataSourcePoints, pointsPerThread);
// Signal to the data source that all points are added.
initialized();
}
use of com.infiniteautomation.mango.pointvaluecache.PointValueCache in project ma-core-public by infiniteautomation.
the class PublisherRTQueueMonitorTest method before.
@Before
@Override
public void before() {
super.before();
// Due to the test framework order of runtime manager injection had to add this
ExecutorService executorService = Common.getBean(ExecutorService.class);
DataSourceDao dataSourceDao = Common.getBean(DataSourceDao.class);
PublisherDao publisherDao = Common.getBean(PublisherDao.class);
DataPointDao dataPointDao = Common.getBean(DataPointDao.class);
PointValueDao pointValueDao = Common.getBean(PointValueDao.class);
PointValueCache pointValueCache = Common.getBean(PointValueCache.class);
Common.runtimeManager = new RuntimeManagerImpl(executorService, dataSourceDao, publisherDao, dataPointDao, pointValueDao, pointValueCache);
Common.runtimeManager.initialize(false);
this.timer.setStartTime(System.currentTimeMillis());
}
use of com.infiniteautomation.mango.pointvaluecache.PointValueCache in project ma-core-public by infiniteautomation.
the class DataPointRTPointValueCacheTest method test0.
/**
* Test with null cache
*/
@Test
public void test0() {
DataPointVO vo = new DataPointVO();
vo.setId(1);
PointValueDao dao = Common.getBean(PointValueDao.class);
PointValueCache pointValueCache = Common.getBean(PointValueCache.class);
List<PointValueTime> initialCache = createCache(vo, 5);
DataPointRTPointValueCache cache = new DataPointRTPointValueCache(vo, 1, null, dao, pointValueCache);
Assert.assertEquals(initialCache.get(0).getValue(), cache.getLatestPointValue().getValue());
Assert.assertEquals(initialCache.get(0).getTime(), cache.getLatestPointValue().getTime());
}
use of com.infiniteautomation.mango.pointvaluecache.PointValueCache in project ma-core-public by infiniteautomation.
the class DataPointRTPointValueCacheTest method test2.
/**
* Test expanding the cache
*/
@Test
public void test2() {
DataPointVO vo = new DataPointVO();
vo.setId(1);
PointValueDao dao = Common.getBean(PointValueDao.class);
PointValueCache pointValueCache = Common.getBean(PointValueCache.class);
List<PointValueTime> initialCache = createCache(vo, 5);
DataPointRTPointValueCache cache = new DataPointRTPointValueCache(vo, 1, initialCache.subList(0, 1), dao, pointValueCache);
List<PointValueTime> latest = cache.getLatestPointValues(5);
for (int i = 0; i < 5; i++) {
Assert.assertEquals(initialCache.get(i).getValue(), latest.get(i).getValue());
Assert.assertEquals(initialCache.get(i).getTime(), latest.get(i).getTime());
}
Assert.assertEquals(1, cache.getCacheContents().size());
}
use of com.infiniteautomation.mango.pointvaluecache.PointValueCache in project ma-core-public by infiniteautomation.
the class DataPointRTPointValueCacheTest method test4.
/**
* Test saving into cache
*/
@Test
public void test4() {
DataPointVO vo = new DataPointVO();
vo.setId(1);
PointValueDao dao = Common.getBean(PointValueDao.class);
PointValueCache pointValueCache = Common.getBean(PointValueCache.class);
List<PointValueTime> initialCache = createCache(vo, 5);
DataPointRTPointValueCache cache = new DataPointRTPointValueCache(vo, 5, initialCache, dao, pointValueCache);
List<PointValueTime> latest = cache.getLatestPointValues(5);
for (int i = 0; i < 5; i++) {
Assert.assertEquals(initialCache.get(i).getValue(), latest.get(i).getValue());
Assert.assertEquals(initialCache.get(i).getTime(), latest.get(i).getTime());
}
List<PointValueTime> newLatest = new ArrayList<>();
// Save into cache
for (int i = 0; i < 10; i++) {
long time = Common.timer.currentTimeMillis();
PointValueTime pvt = new PointValueTime((double) (5 + i), time);
cache.savePointValue(pvt, null, true, true);
newLatest.add(pvt);
this.timer.fastForwardTo(this.timer.currentTimeMillis() + 1);
}
newLatest.sort((v1, v2) -> {
return (int) (v2.getTime() - v1.getTime());
});
// Check size
Assert.assertEquals(5, cache.getCacheContents().size());
List<PointValueTime> latestCached = cache.getLatestPointValues(5);
for (int i = 0; i < 5; i++) {
Assert.assertEquals(newLatest.get(i).getValue(), latestCached.get(i).getValue());
Assert.assertEquals(newLatest.get(i).getTime(), latestCached.get(i).getTime());
}
}
Aggregations