use of com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors in project ma-modules-public by infiniteautomation.
the class SerialDataSourceTestData method getCustomPoint.
public static DataPointRT getCustomPoint(String name, String xid, String valueRegex, int valueIndex, String pointIdentifier, DataSourceRT<? extends DataSourceVO> ds) {
DataPointVO vo = new DataPointVO();
vo.setName(name);
vo.setXid(xid);
vo.setId(currentId++);
vo.setDataSourceId(ds.getId());
SerialPointLocatorVO plVo = new SerialPointLocatorVO();
plVo.setDataType(DataType.ALPHANUMERIC);
plVo.setValueRegex(valueRegex);
plVo.setValueIndex(valueIndex);
plVo.setPointIdentifier(pointIdentifier);
vo.setPointLocator(plVo);
return new DataPointRT(new DataPointWithEventDetectors(vo, new ArrayList<>()), plVo.createRuntime(), ds, null, Common.getBean(PointValueDao.class), Common.getBean(PointValueCache.class), null);
}
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 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 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 DataPointGroupInitializer method processItem.
@Override
protected Void processItem(List<DataPointWithEventDetectors> subgroup, int itemId) {
long startTs = 0L;
if (log.isInfoEnabled()) {
startTs = Common.timer.currentTimeMillis();
log.info("Initializing group {} of {} data points", itemId, subgroup.size());
}
// Bulk request the latest values
List<DataPointVO> queryPoints = subgroup.stream().map(DataPointWithEventDetectors::getDataPoint).collect(Collectors.toList());
// Find the maximum cache size for all point in the datasource
// This number of values will be retrieved for all points in the datasource
// If even one point has a high cache size this *may* cause issues
int maxCacheSize = queryPoints.stream().map(DataPointVO::getDefaultCacheSize).mapToInt(Integer::intValue).max().orElse(0);
Map<Integer, List<PointValueTime>> latestValuesMap = null;
if (maxCacheSize > 0) {
long start = System.nanoTime();
try {
latestValuesMap = dao.loadCaches(queryPoints, maxCacheSize);
if (log.isDebugEnabled()) {
long finish = System.nanoTime();
log.debug("Took {} ms to retrieve latest {} point values for group {}", TimeUnit.NANOSECONDS.toMillis(finish - start), maxCacheSize, itemId);
}
} catch (Exception e) {
log.warn("Failed to get latest point values for multiple points at once. " + "Mango will fall back to retrieving latest point values per point which will take longer.", e);
}
} else {
latestValuesMap = Collections.emptyMap();
}
// Now start them
int failedCount = 0;
for (DataPointWithEventDetectors dataPoint : subgroup) {
try {
// should only be submitted as null if we failed, gets passed to com.serotonin.m2m2.rt.dataImage.PointValueCache.PointValueCache
// if we didn't fail then we can assume there is no value in the database
List<PointValueTime> cache = null;
if (latestValuesMap != null) {
cache = latestValuesMap.getOrDefault(dataPoint.getDataPoint().getSeriesId(), Collections.emptyList());
}
Common.runtimeManager.startDataPoint(dataPoint, cache);
} catch (Exception e) {
// Ensure only 1 can fail at a time
failedCount++;
log.error("Failed to start data point with xid: {}", dataPoint.getDataPoint().getXid(), e);
}
}
if (log.isInfoEnabled()) {
log.info("Group {} successfully initialized {} of {} data points in {} ms", itemId, subgroup.size() - failedCount, subgroup.size(), Common.timer.currentTimeMillis() - startTs);
}
return null;
}
Aggregations