Search in sources :

Example 1 with PointValueCache

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();
}
Also used : DataPointGroupInitializer(com.serotonin.m2m2.rt.DataPointGroupInitializer) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) ExecutorService(java.util.concurrent.ExecutorService) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors)

Example 2 with PointValueCache

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());
}
Also used : PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) DataSourceDao(com.serotonin.m2m2.db.dao.DataSourceDao) ExecutorService(java.util.concurrent.ExecutorService) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache) PublisherDao(com.serotonin.m2m2.db.dao.PublisherDao) RuntimeManagerImpl(com.serotonin.m2m2.rt.RuntimeManagerImpl) Before(org.junit.Before)

Example 3 with PointValueCache

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());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) BasicSQLPointValueDao(com.serotonin.m2m2.db.dao.BasicSQLPointValueDao) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache) Test(org.junit.Test)

Example 4 with PointValueCache

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());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) BasicSQLPointValueDao(com.serotonin.m2m2.db.dao.BasicSQLPointValueDao) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache) Test(org.junit.Test)

Example 5 with PointValueCache

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());
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) BasicSQLPointValueDao(com.serotonin.m2m2.db.dao.BasicSQLPointValueDao) ArrayList(java.util.ArrayList) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache) Test(org.junit.Test)

Aggregations

PointValueCache (com.infiniteautomation.mango.pointvaluecache.PointValueCache)7 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)6 BasicSQLPointValueDao (com.serotonin.m2m2.db.dao.BasicSQLPointValueDao)5 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)5 Test (org.junit.Test)5 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)2 ExecutorService (java.util.concurrent.ExecutorService)2 DataSourceDao (com.serotonin.m2m2.db.dao.DataSourceDao)1 PublisherDao (com.serotonin.m2m2.db.dao.PublisherDao)1 DataPointGroupInitializer (com.serotonin.m2m2.rt.DataPointGroupInitializer)1 RuntimeManagerImpl (com.serotonin.m2m2.rt.RuntimeManagerImpl)1 DataPointWithEventDetectors (com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1