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();
}
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;
}
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);
}
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());
}
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());
}
Aggregations