Search in sources :

Example 1 with DataPointListener

use of com.serotonin.m2m2.rt.dataImage.DataPointListener in project ma-core-public by infiniteautomation.

the class RuntimeManagerImpl method stopDataPoint.

private void stopDataPoint(int dataPointId) {
    synchronized (dataPoints) {
        // Remove this point from the data image if it is there. If not, just quit.
        DataPointRT p = dataPoints.remove(dataPointId);
        // Remove it from the data source, and terminate it.
        if (p != null) {
            try {
                getRunningDataSource(p.getDataSourceId()).removeDataPoint(p);
            } catch (Exception e) {
                LOG.error("Failed to stop point RT with ID: " + dataPointId + " stopping point.", e);
            }
            DataPointListener l = getDataPointListeners(dataPointId);
            if (l != null)
                l.pointTerminated();
            p.terminate();
        }
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) DataPointListener(com.serotonin.m2m2.rt.dataImage.DataPointListener) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 2 with DataPointListener

use of com.serotonin.m2m2.rt.dataImage.DataPointListener in project ma-core-public by infiniteautomation.

the class RuntimeManagerImpl method restartDataPoint.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.rt.RuntimeManager#restartDataPoint(com.serotonin.m2m2.vo.DataPointVO)
     */
@Override
public void restartDataPoint(DataPointVO vo) {
    boolean restarted = false;
    synchronized (dataPoints) {
        // Remove this point from the data image if it is there. If not, just quit.
        DataPointRT p = dataPoints.remove(vo.getId());
        // Remove it from the data source, and terminate it.
        if (p != null) {
            try {
                getRunningDataSource(p.getDataSourceId()).removeDataPoint(p);
            } 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();
            p.terminate();
            this.startDataPoint(p.getVO(), null);
            restarted = true;
        }
    }
    if (!restarted) {
        // The data poit wasn't really running. Ensure the event detectors and enable
        if (vo.getEventDetectors() == null)
            DataPointDao.instance.setEventDetectors(vo);
        vo.setEnabled(true);
        startDataPoint(vo, null);
        DataPointDao.instance.saveEnabledColumn(vo);
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) DataPointListener(com.serotonin.m2m2.rt.dataImage.DataPointListener) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 3 with DataPointListener

use of com.serotonin.m2m2.rt.dataImage.DataPointListener 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 4 with DataPointListener

use of com.serotonin.m2m2.rt.dataImage.DataPointListener in project ma-core-public by infiniteautomation.

the class RuntimeManagerImpl method stopDataPointShutdown.

/**
 * Only to be used at shutdown as synchronization has been reduced for performance
 */
private void stopDataPointShutdown(int dataPointId) {
    DataPointRT p = null;
    synchronized (dataPoints) {
        // Remove this point from the data image if it is there. If not, just quit.
        p = dataPoints.remove(dataPointId);
    }
    // Remove it from the data source, and terminate it.
    if (p != null) {
        try {
            getRunningDataSource(p.getDataSourceId()).removeDataPoint(p);
        } catch (Exception e) {
            LOG.error("Failed to stop point RT with ID: " + dataPointId + " stopping point.", e);
        }
        DataPointListener l = getDataPointListeners(dataPointId);
        if (l != null)
            l.pointTerminated();
        p.terminate();
    }
}
Also used : DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) DataPointListener(com.serotonin.m2m2.rt.dataImage.DataPointListener) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Aggregations

ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)4 DataPointListener (com.serotonin.m2m2.rt.dataImage.DataPointListener)4 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)4 PollingDataSource (com.serotonin.m2m2.rt.dataSource.PollingDataSource)1