Search in sources :

Example 21 with DataPointWithEventDetectors

use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors 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 22 with DataPointWithEventDetectors

use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by infiniteautomation.

the class DataPointService method update.

@Override
protected DataPointVO update(DataPointVO existing, DataPointVO vo) throws PermissionException, ValidationException {
    PermissionHolder user = Common.getUser();
    ensureEditPermission(user, existing);
    vo.setId(existing.getId());
    for (DataPointChangeDefinition def : changeDefinitions) {
        def.preUpdate(vo);
    }
    ensureValid(existing, vo);
    getRuntimeManager().stopDataPoint(vo.getId());
    dao.update(existing, vo);
    for (DataPointChangeDefinition def : changeDefinitions) {
        def.postUpdate(vo);
    }
    if (vo.isEnabled()) {
        List<AbstractPointEventDetectorVO> detectors = eventDetectorDao.getWithSource(vo.getId(), vo);
        getRuntimeManager().startDataPoint(new DataPointWithEventDetectors(vo, detectors));
    }
    return vo;
}
Also used : DataPointChangeDefinition(com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 23 with DataPointWithEventDetectors

use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by infiniteautomation.

the class DataPointService method getWithEventDetectors.

/**
 * Get a data point and its detectors from the database
 */
public DataPointWithEventDetectors getWithEventDetectors(String xid) throws PermissionException, NotFoundException {
    DataPointVO vo = get(xid);
    List<AbstractPointEventDetectorVO> detectors = eventDetectorDao.getWithSource(vo.getId(), vo);
    return new DataPointWithEventDetectors(vo, detectors);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors)

Example 24 with DataPointWithEventDetectors

use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by infiniteautomation.

the class RateOfChangeDetectorTest method testOneSecondPeriodTwoInitialValuesTwoValuesOutOfRangeForOneSecondAverage.

@Test
public void testOneSecondPeriodTwoInitialValuesTwoValuesOutOfRangeForOneSecondAverage() {
    DataPointWithEventDetectors dp = createDisabledPoint(1.0, null, TimePeriods.SECONDS, false, CalculationMode.AVERAGE, 1, TimePeriods.SECONDS, ComparisonMode.GREATER_THAN, 1, TimePeriods.SECONDS);
    // Save some values
    PointValueDao dao = Common.getBean(PointValueDao.class);
    dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(0.1, 0));
    dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(1.101, 100));
    timer.fastForwardTo(1000);
    dp.getDataPoint().setEnabled(true);
    Common.runtimeManager.startDataPoint(dp);
    DataPointRT rt = Common.runtimeManager.getDataPoint(dp.getDataPoint().getId());
    assertEquals(0, listener.raised.size());
    ensureSetPointValue(rt, new PointValueTime(2.5, timer.currentTimeMillis()));
    timer.fastForwardTo(1500);
    assertEquals(0, listener.raised.size());
    assertEquals(0, listener.rtn.size());
    ensureSetPointValue(rt, new PointValueTime(3.6, timer.currentTimeMillis()));
    timer.fastForwardTo(2000);
    assertEquals(1, listener.raised.size());
    assertEquals(2000, listener.raised.get(0).getActiveTimestamp());
    assertEquals(0, listener.rtn.size());
    timer.fastForwardTo(3000);
    assertEquals(1, listener.raised.size());
    assertEquals(1, listener.rtn.size());
    assertEquals(2500, (long) listener.rtn.get(0).getRtnTimestamp());
}
Also used : PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) Test(org.junit.Test)

Example 25 with DataPointWithEventDetectors

use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-core-public by infiniteautomation.

the class RateOfChangeDetectorTest method testOneSecondPeriodTwoInitialValuesTwoValuesInRangeAverage.

@Test
public void testOneSecondPeriodTwoInitialValuesTwoValuesInRangeAverage() {
    DataPointWithEventDetectors dp = createDisabledPoint(1.0, null, TimePeriods.SECONDS, false, CalculationMode.AVERAGE, 1, TimePeriods.SECONDS, ComparisonMode.GREATER_THAN, 0, TimePeriods.SECONDS);
    // Save some values
    PointValueDao dao = Common.getBean(PointValueDao.class);
    dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(0.001, 0));
    dao.savePointValueSync(dp.getDataPoint(), new PointValueTime(0.0003, 100));
    timer.fastForwardTo(timer.currentTimeMillis() + 200);
    dp.getDataPoint().setEnabled(true);
    Common.runtimeManager.startDataPoint(dp);
    DataPointRT rt = Common.runtimeManager.getDataPoint(dp.getDataPoint().getId());
    ensureSetPointValue(rt, new PointValueTime(0.0005, timer.currentTimeMillis()));
    timer.fastForwardTo(timer.currentTimeMillis() + 500);
    ensureSetPointValue(rt, new PointValueTime(0.0009, timer.currentTimeMillis()));
    timer.fastForwardTo(timer.currentTimeMillis() + 4500);
    assertEquals(0, listener.raised.size());
    assertEquals(0, listener.rtn.size());
}
Also used : PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) Test(org.junit.Test)

Aggregations

DataPointWithEventDetectors (com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors)54 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)29 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)25 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)24 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)22 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)20 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)18 PointValueCache (com.infiniteautomation.mango.pointvaluecache.PointValueCache)7 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)6 JsonException (com.serotonin.json.JsonException)6 HashMap (java.util.HashMap)5 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)4 JsonArray (com.serotonin.json.type.JsonArray)4 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)4 MockPointLocatorVO (com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)4 SerialPointLocatorVO (com.infiniteautomation.serial.vo.SerialPointLocatorVO)3 DataPointChangeDefinition (com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition)3