use of com.serotonin.m2m2.rt.dataImage.DataPointRT 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();
}
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT 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);
}
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT 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);
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-core-public by infiniteautomation.
the class ImageValueServlet method doGet.
/**
* @TODO(security): Validate the point access against the user. If anonymous, make sure the view allows public
* access to the point.
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
String imageInfo = request.getPathInfo();
try {
// Remove the / and the extension
int dot = imageInfo.indexOf('.');
String extension = imageInfo.substring(dot + 1, imageInfo.length()).toLowerCase();
imageInfo = imageInfo.substring(1, dot);
// Split by underscore.
String[] imageBits = imageInfo.split("_");
// Get the data.
String timestamp = imageBits[0];
int dataPointId = Integer.parseInt(imageBits[1]);
int scalePercent = getIntRequestParameter(request, "p", -1);
int width = getIntRequestParameter(request, "w", -1);
int height = getIntRequestParameter(request, "h", -1);
// DataPointRT dp = Common.ctx.getRuntimeManager().getDataPoint(dataPointId);
// Permissions.ensureDataPointReadPermission(Common.getUser(request), dp.getVO());
PointValueFacade pointValueFacade = new PointValueFacade(dataPointId);
PointValueTime pvt = null;
if (timestamp.startsWith(historyPrefix)) {
// Find the point with the given timestamp
long time = Long.parseLong(timestamp.substring(historyPrefix.length()));
pvt = pointValueFacade.getPointValueAt(time);
} else
// Use the latest value
pvt = pointValueFacade.getPointValue();
if (pvt == null || pvt.getValue() == null || !(pvt.getValue() instanceof ImageValue)) {
LOG.warn("Invalid pvt: " + pvt);
response.sendError(HttpStatus.SC_NOT_FOUND);
} else {
ImageValue imageValue = (ImageValue) pvt.getValue();
byte[] data = imageValue.getImageData();
if (scalePercent != -1) {
// Definitely going to be JPEG
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
// Scale the image
PercentScaledImage scaler = new PercentScaledImage(((float) scalePercent) / 100);
data = ImageUtils.scaleImage(scaler, data, new JpegImageFormat(0.85f));
} else if (width != -1 && height != -1) {
// Definitely going to be JPEG
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
// Scale the image
BoxScaledImage scaler = new BoxScaledImage(width, height);
data = ImageUtils.scaleImage(scaler, data, new JpegImageFormat(0.85f));
} else {
// Use the Image extension to se the Content Type
if ("jpg".equals(extension))
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
else if ("png".equals(extension))
response.setContentType(MediaType.IMAGE_PNG_VALUE);
else if ("gif".equals(extension))
response.setContentType(MediaType.IMAGE_GIF_VALUE);
}
response.getOutputStream().write(data);
}
} catch (FileNotFoundException e) {
LOG.warn("", e);
} catch (InterruptedException e) {
LOG.warn("", e);
} catch (StringIndexOutOfBoundsException e) {
LOG.warn("", e);
} catch (NumberFormatException e) {
LOG.warn("", e);
} catch (ArrayIndexOutOfBoundsException e) {
LOG.warn("", e);
} catch (IllegalArgumentException e) {
LOG.warn("", e);
}
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-core-public by infiniteautomation.
the class DataPointRTTest method testIntervalOnChangeLogging.
/**
* Test Interval Logged Values w/ On Change Option
*/
@Test
public void testIntervalOnChangeLogging() {
PointValueDao dao = Common.databaseProxy.newPointValueDao();
MockPointLocatorVO plVo = new MockPointLocatorVO(DataTypes.NUMERIC, true);
DataPointVO dpVo = new DataPointVO();
dpVo.setId(1);
// Configure Interval on change logging
dpVo.setLoggingType(DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL);
dpVo.setTolerance(0.5);
dpVo.setIntervalLoggingPeriod(5);
dpVo.setIntervalLoggingPeriodType(TimePeriods.SECONDS);
dpVo.setPointLocator(plVo);
dpVo.setLoggingType(DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL);
MockDataSourceVO dsVo = new MockDataSourceVO();
MockPointLocatorRT plRt = new MockPointLocatorRT(plVo);
// Setup some initial data
List<PointValueTime> initialCache = new ArrayList<>();
initialCache.add(new PointValueTime(1.0, 0));
SimulationTimer timer = new SimulationTimer();
DataPointRT rt = new DataPointRT(dpVo, plRt, dsVo, initialCache, timer);
rt.initialize();
rt.initializeIntervalLogging(0, false);
// Test no changes
timer.fastForwardTo(5001);
PointValueTime value = dao.getLatestPointValue(dpVo.getId());
// Ensure database has interval logged value
assertEquals(1.0, value.getDoubleValue(), 0.0001);
assertEquals(5000, value.getTime());
// Ensure cache does not have interval logged value
assertEquals(1.0, rt.getPointValue().getDoubleValue(), 0.0001);
assertEquals(0, rt.getPointValue().getTime());
// Next interval
timer.fastForwardTo(6000);
rt.setPointValue(new PointValueTime(2.0, 6000), null);
// Check Log On Change
value = dao.getLatestPointValue(dpVo.getId());
assertEquals(2.0, value.getDoubleValue(), 0.0001);
assertEquals(6000, value.getTime());
assertEquals(2.0, rt.getPointValue().getDoubleValue(), 0.0001);
assertEquals(6000, rt.getPointValue().getTime());
// Interval is reset for 5000ms from now
timer.fastForwardTo(11001);
// Check Interval Log
value = dao.getLatestPointValue(dpVo.getId());
assertEquals(2.0, value.getDoubleValue(), 0.0001);
assertEquals(11000, value.getTime());
assertEquals(2.0, rt.getPointValue().getDoubleValue(), 0.0001);
assertEquals(6000, rt.getPointValue().getTime());
// Test Tolerance (Should not get logged)
timer.fastForwardTo(12000);
rt.setPointValue(new PointValueTime(2.20, 12000), null);
// Check Log On Change
value = dao.getLatestPointValue(dpVo.getId());
assertEquals(2.0, value.getDoubleValue(), 0.0001);
assertEquals(11000, value.getTime());
// Cache will have the set value
assertEquals(2.2, rt.getPointValue().getDoubleValue(), 0.0001);
assertEquals(12000, rt.getPointValue().getTime());
}
Aggregations