use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class InternalDataSourceRT method forcePointRead.
@Override
public void forcePointRead(DataPointRT dataPoint) {
InternalPointLocatorRT locator = dataPoint.getPointLocator();
ValueMonitor<?> m = Common.MONITORED_VALUES.getValueMonitor(locator.getPointLocatorVO().getMonitorId());
if (m != null) {
if (m instanceof IntegerMonitor)
dataPoint.updatePointValue(new PointValueTime((double) ((IntegerMonitor) m).getValue(), Common.timer.currentTimeMillis()));
else if (m instanceof LongMonitor)
dataPoint.updatePointValue(new PointValueTime((double) ((LongMonitor) m).getValue(), Common.timer.currentTimeMillis()));
else if (m instanceof DoubleMonitor)
dataPoint.updatePointValue(new PointValueTime((double) ((DoubleMonitor) m).getValue(), Common.timer.currentTimeMillis()));
else if (m instanceof AtomicIntegerMonitor)
dataPoint.updatePointValue(new PointValueTime((double) ((AtomicIntegerMonitor) m).getValue(), Common.timer.currentTimeMillis()));
}
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-modules-public by infiniteautomation.
the class InternalDataSourceRT method beginPolling.
@Override
public void beginPolling() {
// Ensure have all our points loaded
this.updateChangedPoints(Common.timer.currentTimeMillis());
// Refresh our Monitored Values
for (DataPointRT dataPoint : dataPoints) {
InternalPointLocatorRT locator = dataPoint.getPointLocator();
ValueMonitor<?> m = Common.MONITORED_VALUES.getValueMonitor(locator.getPointLocatorVO().getMonitorId());
if (m != null)
m.reset();
}
super.beginPolling();
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT 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();
}
}
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT 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);
}
}
use of com.serotonin.m2m2.rt.dataImage.DataPointRT in project ma-core-public by infiniteautomation.
the class EventHandlersDwr method validateScript.
@DwrPermission(user = true)
public ProcessResult validateScript(String script, Integer targetPointId, int type, List<IntStringPair> additionalContext, ScriptPermissions scriptPermissions) {
ProcessResult response = new ProcessResult();
TranslatableMessage message;
Map<String, IDataPointValueSource> context = new HashMap<String, IDataPointValueSource>();
int targetDataType;
if (type == SetPointEventHandlerDefinition.ACTIVE_SCRIPT_TYPE || type == SetPointEventHandlerDefinition.INACTIVE_SCRIPT_TYPE) {
DataPointRT target = targetPointId == null ? null : Common.runtimeManager.getDataPoint(targetPointId.intValue());
if (target == null) {
DataPointVO targetVo = targetPointId == null ? null : DataPointDao.instance.getDataPoint(targetPointId.intValue(), false);
if (targetVo == null) {
if (// These are passed in the validateScript of eventHandlers.jsp
type == SetPointEventHandlerDefinition.ACTIVE_SCRIPT_TYPE)
response.addMessage("activeScript", new TranslatableMessage("eventHandlers.noTargetPoint"));
else if (type == SetPointEventHandlerDefinition.INACTIVE_SCRIPT_TYPE)
response.addMessage("inactiveScript", new TranslatableMessage("eventHandlers.noTargetPoint"));
return response;
}
if (targetVo.getDefaultCacheSize() == 0)
targetVo.setDefaultCacheSize(1);
target = new DataPointRT(targetVo, targetVo.getPointLocator().createRuntime(), DataSourceDao.instance.getDataSource(targetVo.getDataSourceId()), null);
target.resetValues();
context.put(SetPointEventHandlerVO.TARGET_CONTEXT_KEY, target);
}
targetDataType = target.getDataTypeId();
} else {
targetDataType = DataTypes.ALPHANUMERIC;
}
for (IntStringPair cxt : additionalContext) {
DataPointRT dprt = Common.runtimeManager.getDataPoint(cxt.getKey());
if (dprt == null) {
DataPointVO dpvo = DataPointDao.instance.getDataPoint(cxt.getKey(), false);
if (dpvo == null) {
if (type == SetPointEventHandlerDefinition.ACTIVE_SCRIPT_TYPE)
response.addMessage("activeScript", new TranslatableMessage("event.script.contextPointMissing", cxt.getValue(), cxt.getKey()));
else if (type == SetPointEventHandlerDefinition.INACTIVE_SCRIPT_TYPE)
response.addMessage("inactiveScript", new TranslatableMessage("event.script.contextPointMissing", cxt.getValue(), cxt.getKey()));
else if (type == EmailEventHandlerDefinition.EMAIL_SCRIPT_TYPE)
response.addMessage("emailScript", new TranslatableMessage("event.script.contextPointMissing", cxt.getValue(), cxt.getKey()));
return response;
}
if (dpvo.getDefaultCacheSize() == 0)
dpvo.setDefaultCacheSize(1);
dprt = new DataPointRT(dpvo, dpvo.getPointLocator().createRuntime(), DataSourceDao.instance.getDataSource(dpvo.getDataSourceId()), null);
dprt.resetValues();
}
context.put(cxt.getValue(), dprt);
}
Map<String, Object> otherContext = new HashMap<String, Object>();
otherContext.put(SetPointEventHandlerVO.EVENT_CONTEXT_KEY, getTestEvent());
if (type == EmailEventHandlerDefinition.EMAIL_SCRIPT_TYPE)
otherContext.put("model", new HashMap<String, Object>());
final StringWriter scriptOut = new StringWriter();
final PrintWriter scriptWriter = new PrintWriter(scriptOut);
final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/YYY HH:mm:ss");
ScriptPointValueSetter loggingSetter = new ScriptPointValueSetter(scriptPermissions) {
@Override
public void set(IDataPointValueSource point, Object value, long timestamp, String annotation) {
DataPointRT dprt = (DataPointRT) point;
if (!dprt.getVO().getPointLocator().isSettable()) {
scriptOut.append("Point " + dprt.getVO().getExtendedName() + " not settable.");
return;
}
if (!Permissions.hasPermission(dprt.getVO().getSetPermission(), permissions.getDataPointSetPermissions())) {
scriptOut.write(new TranslatableMessage("pointLinks.setTest.permissionDenied", dprt.getVO().getXid()).translate(Common.getTranslations()));
return;
}
scriptOut.append("Setting point " + dprt.getVO().getName() + " to " + value + " @" + sdf.format(new Date(timestamp)) + "\r\n");
}
@Override
protected void setImpl(IDataPointValueSource point, Object value, long timestamp, String annotation) {
// not really setting
}
};
try {
CompiledScript compiledScript = CompiledScriptExecutor.compile(script);
PointValueTime pvt = CompiledScriptExecutor.execute(compiledScript, context, otherContext, System.currentTimeMillis(), targetDataType, System.currentTimeMillis(), scriptPermissions, scriptWriter, new ScriptLog(SetPointHandlerRT.NULL_WRITER, LogLevel.FATAL), loggingSetter, null, true);
if (pvt.getValue() == null)
message = new TranslatableMessage("eventHandlers.script.nullResult");
else if (CompiledScriptExecutor.UNCHANGED == pvt.getValue())
message = new TranslatableMessage("eventHandlers.script.successUnchanged");
else
message = new TranslatableMessage("eventHandlers.script.success", pvt.getValue());
// Add the script logging output
response.addData("out", scriptOut.toString().replaceAll("\n", "<br/>"));
} catch (ScriptPermissionsException e) {
message = e.getTranslatableMessage();
} catch (ScriptException e) {
message = new TranslatableMessage("eventHandlers.script.failure", e.getMessage());
} catch (ResultTypeException e) {
message = e.getTranslatableMessage();
}
if (type == SetPointEventHandlerDefinition.ACTIVE_SCRIPT_TYPE)
response.addMessage("activeScript", message);
else if (type == SetPointEventHandlerDefinition.INACTIVE_SCRIPT_TYPE)
response.addMessage("inactiveScript", message);
else if (type == EmailEventHandlerDefinition.EMAIL_SCRIPT_TYPE)
response.addMessage("emailScript", message);
return response;
}
Aggregations