use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.
the class PublisherRT method initializePoints.
/**
* The {@link PublishedPointGroupInitializer} calls
* {@link RuntimeManager#startPublishedPoint(PublishedPointVO) startPublishedPoint()}
* which adds the points to the cache in the RTM and initializes them.
*/
private void initializePoints() {
ExecutorService executorService = Common.getBean(ExecutorService.class);
// Add the enabled points to the data source.
List<PublishedPointVO> points = publishedPointDao.getEnabledPublishedPoints(getId());
// Startup multi threaded
int pointsPerThread = Common.envProps.getInt("runtime.publishedPoint.startupThreads.pointsPerThread", 1000);
int startupThreads = Common.envProps.getInt("runtime.publishedPoint.startupThreads", Runtime.getRuntime().availableProcessors());
PublishedPointGroupInitializer pointInitializer = new PublishedPointGroupInitializer(executorService, startupThreads);
pointInitializer.initialize(points, pointsPerThread);
}
use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.
the class PublisherImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
PublisherVO vo = null;
if (StringUtils.isBlank(xid)) {
xid = service.generateUniqueXid();
} else {
try {
vo = service.get(xid);
} catch (NotFoundException e) {
}
}
if (vo == null) {
String typeStr = json.getString("type");
if (StringUtils.isBlank(typeStr))
addFailureMessage("emport.publisher.missingType", xid, ModuleRegistry.getPublisherDefinitionTypes());
else {
PublisherDefinition<?> def = ModuleRegistry.getPublisherDefinition(typeStr);
if (def == null)
addFailureMessage("emport.publisher.invalidType", xid, typeStr, ModuleRegistry.getPublisherDefinitionTypes());
else {
vo = def.baseCreatePublisherVO();
vo.setXid(xid);
}
}
}
if (vo != null) {
try {
// The VO was found or successfully created. Finish reading it in.
ctx.getReader().readInto(vo, json);
boolean isnew = vo.isNew();
if (Common.runtimeManager.getLifecycleState() == ILifecycleState.RUNNING) {
if (isnew) {
service.insert(vo);
} else {
service.update(vo.getId(), vo);
}
addSuccessMessage(isnew, "emport.publisher.prefix", xid);
// Handle embedded points (pre Mango 4.3 this was the case)
JsonArray arr = json.getJsonArray("points");
if (arr != null) {
for (JsonValue jv : arr) {
String dataPointXid = jv.getJsonValue("dataPointId").toString();
try {
DataPointVO dataPointVO = dataPointService.get(dataPointXid);
PublishedPointVO point = vo.getDefinition().createPublishedPointVO(vo, dataPointVO);
point.setName(dataPointVO.getName());
ctx.getReader().readInto(point, jv.toJsonObject());
point.setXid(publishedPointService.generateUniqueXid());
publishedPointService.insert(point);
addSuccessMessage(isnew, "emport.publishedPoint.prefix", point.getXid());
} catch (NotFoundException e) {
addFailureMessage("emport.publisher.prefix", xid, new TranslatableMessage("emport.error.missingPoint", dataPointXid));
} catch (ValidationException e) {
for (ProcessMessage m : e.getValidationResult().getMessages()) {
addFailureMessage(new ProcessMessage("emport.publisher.prefix", new TranslatableMessage("literal", xid), m));
}
}
}
}
} else {
addFailureMessage("emport.publisher.runtimeManagerNotRunning", xid);
}
} catch (ValidationException e) {
setValidationMessages(e.getValidationResult(), "emport.publisher.prefix", xid);
} catch (TranslatableJsonException e) {
addFailureMessage("emport.publisher.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.publisher.prefix", xid, getJsonExceptionMessage(e));
}
}
}
use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.
the class MockRuntimeManager method stopPublishedPoint.
@Override
public void stopPublishedPoint(int id) {
if (useDatabase) {
PublishedPointVO vo = PublishedPointDao.getInstance().get(id);
vo.setEnabled(false);
PublishedPointDao.getInstance().saveEnabledColumn(vo);
}
}
use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.
the class PublishedPointDao method saveEnabledColumn.
/**
* Update the enabled column
*
* @param pp point for which to update the enabled column
*/
public void saveEnabledColumn(PublishedPointVO pp) {
PublishedPointVO existing = get(pp.getId());
saveEnabledColumn(existing, pp.isEnabled());
}
use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by MangoAutomation.
the class PublisherImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
PublisherVO vo = null;
if (StringUtils.isBlank(xid)) {
xid = service.generateUniqueXid();
} else {
try {
vo = service.get(xid);
} catch (NotFoundException e) {
}
}
if (vo == null) {
String typeStr = json.getString("type");
if (StringUtils.isBlank(typeStr))
addFailureMessage("emport.publisher.missingType", xid, ModuleRegistry.getPublisherDefinitionTypes());
else {
PublisherDefinition<?> def = ModuleRegistry.getPublisherDefinition(typeStr);
if (def == null)
addFailureMessage("emport.publisher.invalidType", xid, typeStr, ModuleRegistry.getPublisherDefinitionTypes());
else {
vo = def.baseCreatePublisherVO();
vo.setXid(xid);
}
}
}
if (vo != null) {
try {
// The VO was found or successfully created. Finish reading it in.
ctx.getReader().readInto(vo, json);
boolean isnew = vo.isNew();
if (Common.runtimeManager.getLifecycleState() == ILifecycleState.RUNNING) {
if (isnew) {
service.insert(vo);
} else {
service.update(vo.getId(), vo);
}
addSuccessMessage(isnew, "emport.publisher.prefix", xid);
// Handle embedded points (pre Mango 4.3 this was the case)
JsonArray arr = json.getJsonArray("points");
if (arr != null) {
for (JsonValue jv : arr) {
String dataPointXid = jv.getJsonValue("dataPointId").toString();
try {
DataPointVO dataPointVO = dataPointService.get(dataPointXid);
PublishedPointVO point = vo.getDefinition().createPublishedPointVO(vo, dataPointVO);
point.setName(dataPointVO.getName());
ctx.getReader().readInto(point, jv.toJsonObject());
point.setXid(publishedPointService.generateUniqueXid());
publishedPointService.insert(point);
addSuccessMessage(isnew, "emport.publishedPoint.prefix", point.getXid());
} catch (NotFoundException e) {
addFailureMessage("emport.publisher.prefix", xid, new TranslatableMessage("emport.error.missingPoint", dataPointXid));
} catch (ValidationException e) {
for (ProcessMessage m : e.getValidationResult().getMessages()) {
addFailureMessage(new ProcessMessage("emport.publisher.prefix", new TranslatableMessage("literal", xid), m));
}
}
}
}
} else {
addFailureMessage("emport.publisher.runtimeManagerNotRunning", xid);
}
} catch (ValidationException e) {
setValidationMessages(e.getValidationResult(), "emport.publisher.prefix", xid);
} catch (TranslatableJsonException e) {
addFailureMessage("emport.publisher.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.publisher.prefix", xid, getJsonExceptionMessage(e));
}
}
}
Aggregations