Search in sources :

Example 1 with DataPointWithEventDetectors

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);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) ArrayList(java.util.ArrayList) SerialPointLocatorVO(com.infiniteautomation.serial.vo.SerialPointLocatorVO) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) PointValueCache(com.infiniteautomation.mango.pointvaluecache.PointValueCache)

Example 2 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 3 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 4 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 5 with DataPointWithEventDetectors

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;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) DataPointWithEventDetectors(com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

DataPointWithEventDetectors (com.serotonin.m2m2.vo.dataPoint.DataPointWithEventDetectors)29 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)16 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)14 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)13 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)12 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)11 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)9 PointValueCache (com.infiniteautomation.mango.pointvaluecache.PointValueCache)5 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)3 SerialPointLocatorVO (com.infiniteautomation.serial.vo.SerialPointLocatorVO)3 JsonException (com.serotonin.json.JsonException)3 HashMap (java.util.HashMap)3 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)2 JsonArray (com.serotonin.json.type.JsonArray)2 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 DataPointChangeDefinition (com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition)2 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)2 AbstractEventHandlerVO (com.serotonin.m2m2.vo.event.AbstractEventHandlerVO)2