Search in sources :

Example 6 with DataSourceRT

use of com.serotonin.m2m2.rt.dataSource.DataSourceRT in project ma-core-public by infiniteautomation.

the class RuntimeManagerImpl method forcePointRead.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.rt.RuntimeManager#forcePointRead(int)
     */
@Override
public void forcePointRead(int dataPointId) {
    DataPointRT dataPoint = dataPoints.get(dataPointId);
    if (dataPoint == null)
        throw new RTException("Point is not enabled");
    // Tell the data source to read the point value;
    DataSourceRT<? extends DataSourceVO<?>> ds = getRunningDataSource(dataPoint.getDataSourceId());
    if (ds != null)
        // The data source may have been disabled. Just make sure.
        ds.forcePointRead(dataPoint);
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT)

Example 7 with DataSourceRT

use of com.serotonin.m2m2.rt.dataSource.DataSourceRT in project ma-core-public by infiniteautomation.

the class RuntimeManagerImpl method relinquish.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.rt.RuntimeManager#relinquish(int)
     */
@Override
public void relinquish(int dataPointId) {
    DataPointRT dataPoint = dataPoints.get(dataPointId);
    if (dataPoint == null)
        throw new RTException("Point is not enabled");
    if (!dataPoint.getPointLocator().isSettable())
        throw new RTException("Point is not settable");
    if (!dataPoint.getPointLocator().isRelinquishable())
        throw new RTException("Point is not relinquishable");
    // Tell the data source to relinquish value of the point.
    DataSourceRT<? extends DataSourceVO<?>> ds = getRunningDataSource(dataPoint.getDataSourceId());
    // The data source may have been disabled. Just make sure.
    if (ds != null)
        ds.relinquish(dataPoint);
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT)

Example 8 with DataSourceRT

use of com.serotonin.m2m2.rt.dataSource.DataSourceRT in project ma-core-public by infiniteautomation.

the class RuntimeManagerImpl method stopDataSourceShutdown.

/**
 * Should only be called at Shutdown as synchronization has been reduced for performance
 */
@Override
public void stopDataSourceShutdown(int id) {
    DataSourceRT<? extends DataSourceVO<?>> dataSource = getRunningDataSource(id);
    if (dataSource == null)
        return;
    try {
        // Stop the data points.
        for (DataPointRT p : dataPoints.values()) {
            if (p.getDataSourceId() == id)
                stopDataPointShutdown(p.getId());
        }
        synchronized (runningDataSources) {
            runningDataSources.remove(dataSource.getId());
        }
        dataSource.terminate();
        dataSource.joinTermination();
        LOG.info("Data source '" + dataSource.getName() + "' stopped");
    } catch (Exception e) {
        LOG.error("Data source '" + dataSource.getName() + "' failed proper termination.", e);
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 9 with DataSourceRT

use of com.serotonin.m2m2.rt.dataSource.DataSourceRT in project ma-core-public by infiniteautomation.

the class RuntimeManagerImpl method setDataPointValue.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.rt.RuntimeManager#setDataPointValue(int, com.serotonin.m2m2.rt.dataImage.PointValueTime, com.serotonin.m2m2.rt.dataImage.SetPointSource)
     */
@Override
public void setDataPointValue(int dataPointId, PointValueTime valueTime, SetPointSource source) {
    DataPointRT dataPoint = dataPoints.get(dataPointId);
    if (dataPoint == null)
        throw new RTException("Point is not enabled");
    if (!dataPoint.getPointLocator().isSettable())
        throw new RTException("Point is not settable");
    // Tell the data source to set the value of the point.
    DataSourceRT<? extends DataSourceVO<?>> ds = getRunningDataSource(dataPoint.getDataSourceId());
    // The data source may have been disabled. Just make sure.
    if (ds != null)
        ds.setPointValue(dataPoint, valueTime, source);
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT)

Example 10 with DataSourceRT

use of com.serotonin.m2m2.rt.dataSource.DataSourceRT in project ma-core-public by infiniteautomation.

the class RuntimeManagerImpl method initializeDataSourceStartup.

/**
 * Only to be used at startup as the synchronization has been reduced for performance
 * @param vo
 * @return
 */
@Override
public boolean initializeDataSourceStartup(DataSourceVO<?> vo) {
    long startTime = System.nanoTime();
    // If the data source is already running, just quit.
    if (isDataSourceRunning(vo.getId()))
        return false;
    // Ensure that the data source is enabled.
    Assert.isTrue(vo.isEnabled(), "Data source not enabled.");
    // Create and initialize the runtime version of the data source.
    DataSourceRT<? extends DataSourceVO<?>> dataSource = vo.createDataSourceRT();
    dataSource.initialize();
    // Add it to the list of running data sources.
    synchronized (runningDataSources) {
        runningDataSources.put(dataSource.getId(), dataSource);
    }
    // Add the enabled points to the data source.
    List<DataPointVO> dataSourcePoints = DataPointDao.instance.getDataPointsForDataSourceStart(vo.getId());
    Map<Integer, List<PointValueTime>> latestValuesMap = null;
    PointValueDao pvDao = Common.databaseProxy.newPointValueDao();
    if (pvDao instanceof EnhancedPointValueDao) {
        // 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 = 0;
        for (DataPointVO dataPoint : dataSourcePoints) {
            if (dataPoint.getDefaultCacheSize() > maxCacheSize)
                maxCacheSize = dataPoint.getDefaultCacheSize();
        }
        try {
            latestValuesMap = ((EnhancedPointValueDao) pvDao).getLatestPointValuesForDataSource(vo, maxCacheSize);
        } catch (Exception e) {
            LOG.error("Failed to get latest point values for datasource " + vo.getXid() + ". Mango will try to retrieve latest point values per point which will take longer.", e);
        }
    }
    for (DataPointVO dataPoint : dataSourcePoints) {
        if (dataPoint.isEnabled()) {
            List<PointValueTime> latestValuesForPoint = null;
            if (latestValuesMap != null) {
                latestValuesForPoint = latestValuesMap.get(dataPoint.getId());
                if (latestValuesForPoint == null) {
                    latestValuesForPoint = new ArrayList<>();
                }
            }
            try {
                startDataPointStartup(dataPoint, latestValuesForPoint);
            } catch (Exception e) {
                LOG.error("Failed to start data point " + dataPoint.getXid(), e);
            }
        }
    }
    LOG.info("Data source '" + vo.getName() + "' initialized");
    long endTime = System.nanoTime();
    long duration = endTime - startTime;
    LOG.info("Data source '" + vo.getName() + "' took " + (double) duration / (double) 1000000 + "ms to start");
    return true;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) EnhancedPointValueDao(com.serotonin.m2m2.db.dao.EnhancedPointValueDao) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) EnhancedPointValueDao(com.serotonin.m2m2.db.dao.EnhancedPointValueDao)

Aggregations

DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)6 ArrayList (java.util.ArrayList)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)3 DataSourceRT (com.serotonin.m2m2.rt.dataSource.DataSourceRT)2 PollingDataSource (com.serotonin.m2m2.rt.dataSource.PollingDataSource)2 GenericRestException (com.infiniteautomation.mango.rest.v2.exception.GenericRestException)1 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)1 LongLongPair (com.serotonin.db.pair.LongLongPair)1 StringStringPair (com.serotonin.db.pair.StringStringPair)1 EnhancedPointValueDao (com.serotonin.m2m2.db.dao.EnhancedPointValueDao)1 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)1 DataPointListener (com.serotonin.m2m2.rt.dataImage.DataPointListener)1 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1