Search in sources :

Example 61 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-core-public by infiniteautomation.

the class RuntimeManagerImpl method startDataPointStartup.

/**
 * Only to be used at startup as synchronization has been reduced for performance
 * @param vo
 * @param latestValue
 */
private void startDataPointStartup(DataPointVO vo, List<PointValueTime> initialCache) {
    Assert.isTrue(vo.isEnabled(), "Data point not enabled");
    // Only add the data point if its data source is enabled.
    DataSourceRT<? extends DataSourceVO<?>> ds = getRunningDataSource(vo.getDataSourceId());
    if (ds != null) {
        // Change the VO into a data point implementation.
        DataPointRT dataPoint = new DataPointRT(vo, vo.getPointLocator().createRuntime(), ds.getVo(), initialCache);
        // Add/update it in the data image.
        synchronized (dataPoints) {
            dataPoints.compute(dataPoint.getId(), (k, rt) -> {
                if (rt != null) {
                    try {
                        getRunningDataSource(rt.getDataSourceId()).removeDataPoint(rt);
                    } catch (Exception e) {
                        LOG.error("Failed to stop point RT with ID: " + vo.getId() + " stopping point.", e);
                    }
                    DataPointListener l = getDataPointListeners(vo.getId());
                    if (l != null)
                        l.pointTerminated();
                    rt.terminate();
                }
                return dataPoint;
            });
        }
        // Initialize it.
        dataPoint.initialize();
        // If we are a polling data source then we need to wait to start our interval logging
        // until the first poll due to quantization
        boolean isPolling = ds instanceof PollingDataSource;
        // If we are not polling go ahead and start the interval logging, otherwise we will let the data source do it on the first poll
        if (!isPolling)
            dataPoint.initializeIntervalLogging(0l, false);
        DataPointListener l = getDataPointListeners(vo.getId());
        if (l != null)
            l.pointInitialized();
        // Add/update it in the data source.
        try {
            ds.addDataPoint(dataPoint);
        } catch (Exception e) {
            // This can happen if there is a corrupt DB with a point for a different
            // data source type linked to this data source...
            LOG.error("Failed to start point with xid: " + dataPoint.getVO().getXid() + " disabling point.", e);
            // TODO Fire Alarm to warn user.
            dataPoint.getVO().setEnabled(false);
            // Stop it
            saveDataPoint(dataPoint.getVO());
        }
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) DataPointListener(com.serotonin.m2m2.rt.dataImage.DataPointListener) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) PollingDataSource(com.serotonin.m2m2.rt.dataSource.PollingDataSource)

Example 62 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO 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 63 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO 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 64 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO 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 65 with DataSourceVO

use of com.serotonin.m2m2.vo.dataSource.DataSourceVO 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)

Aggregations

User (com.serotonin.m2m2.vo.User)31 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)28 ArrayList (java.util.ArrayList)21 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)19 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)18 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)18 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)15 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)15 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)11 List (java.util.List)10 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)9 AbstractDataSourceModel (com.serotonin.m2m2.web.mvc.rest.v1.model.dataSource.AbstractDataSourceModel)8 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)6 MockDataSourceVO (com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO)6 DataPointPropertiesTemplateVO (com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO)6 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)5 URI (java.net.URI)5 HashMap (java.util.HashMap)5