use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.
the class RuntimeManagerImpl method startPublisher.
@Override
public void startPublisher(PublisherVO vo) {
// Ensure that the publisher is saved and enabled.
Assert.isTrue(vo.getId() > 0, "Publisher must be saved");
Assert.isTrue(vo.isEnabled(), "Publisher must be enabled");
ensureState(ILifecycleState.INITIALIZING, ILifecycleState.RUNNING);
PublisherRT<? extends PublisherVO, ? extends PublishedPointVO, ? extends SendThread> publisher = runningPublishers.computeIfAbsent(vo.getId(), k -> vo.createPublisherRT());
long startTime = System.nanoTime();
// Initialize the runtime of the publisher.
publisher.initialize(false);
long duration = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
stateMessage = new TranslatableMessage("runtimeManager.initialize.publisher", vo.getName(), duration);
LOG.info(String.format("%s took %dms to start", publisher.readableIdentifier(), duration));
}
use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.
the class PublishedPointGroupInitializer method processItem.
@Override
protected Void processItem(List<PublishedPointVO> subgroup, int itemId) throws Exception {
long startTs = 0L;
if (log.isInfoEnabled()) {
startTs = Common.timer.currentTimeMillis();
log.info("Initializing group {} of {} published points", itemId, subgroup.size());
}
// Now start them
int failedCount = 0;
for (PublishedPointVO point : subgroup) {
try {
Common.runtimeManager.startPublishedPoint(point);
} catch (Exception e) {
// Ensure only 1 can fail at a time
failedCount++;
log.error("Failed to start published point", e);
}
}
if (log.isInfoEnabled()) {
log.info("Group {} successfully initialized {} of {} published points in {} ms", itemId, subgroup.size() - failedCount, subgroup.size(), Common.timer.currentTimeMillis() - startTs);
}
return null;
}
use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.
the class PublisherRTQueueMonitorTest method testQueueMonitor.
@Test(timeout = 1 * 60 * 1000)
public void testQueueMonitor() {
// create DS and DP and enable them (need to be running)
MockDataSourceVO dataSource = this.createMockDataSource(true);
DataPointVO dataPoint = this.createMockDataPoint(dataSource, new MockPointLocatorVO(DataType.NUMERIC, true), true);
// create publisher with a published point (this is a listener) for the DP
TestPublisherVO publisherVO = (TestPublisherVO) createMockPublisher(true);
List<PublishedPointVO> points = createMockPublishedPoints(publisherVO, Collections.singletonList(dataPoint), true);
// get the running data point RT from the Common.runtimeManager
DataPointRT rt = Common.runtimeManager.getDataPoint(dataPoint.getId());
// MockBackgroundProcessing
// set PV(s) to the RT
// Note: the publish point will be notified by DataPointEventNotifyWorkItem
PointValueTime newValue = new PointValueTime(1.0, this.timer.currentTimeMillis());
rt.setPointValue(newValue, null);
try {
/* Waiting for the PublishQueue.add to happen...
* because I know that PublishQueue.lastSizeCheck is 0,
* the fist time the PublishQueue.sizeCheck() will happen
*/
publisherVO.getAddedFuture().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
fail(e.getMessage());
}
// confirm publish queue is of certain size
String monitor = QUEUE_SIZE_MONITOR_ID + publisherVO.getXid();
Assert.assertNotNull(Common.MONITORED_VALUES.getMonitor(monitor).getName());
Assert.assertEquals(1, Common.MONITORED_VALUES.getMonitor(monitor).getValue());
}
use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.
the class PublishedPointServiceTest method testSetPublishedPointState.
@Test
public void testSetPublishedPointState() {
// Start out with a running publisher and an enabled point
IDataPoint dp = createMockDataPoints(1).get(0);
MockPublisherVO publisher = createMockPublisher(true);
MockPublishedPointVO pp = publisher.getDefinition().createPublishedPointVO(publisher, dp);
pp.setName(dp.getName());
pp.setEnabled(true);
PublishedPointVO vo = service.insert(pp);
assertTrue(service.setPublishedPointState(vo.getXid(), false, false));
// Ensure it is not running
assertNull(getRuntimeManager().getPublishedPoint(vo.getId()));
assertTrue(service.setPublishedPointState(vo.getXid(), true, false));
// Ensure it is running
assertNotNull(getRuntimeManager().getPublishedPoint(vo.getId()));
}
use of com.serotonin.m2m2.vo.publish.PublishedPointVO in project ma-core-public by infiniteautomation.
the class PublishedPointServiceTest method testNonAdminUpdate.
@Test(expected = PermissionException.class)
public void testNonAdminUpdate() {
PublishedPointVO vo = insertNewVO(readUser);
PublishedPointVO fromDb = service.get(vo.getId());
assertVoEqual(vo, fromDb);
PublishedPointVO updated = updateVO(vo);
runAs.runAs(readUser, () -> {
service.update(vo.getId(), updated);
});
}
Aggregations