use of com.infiniteautomation.mango.spring.service.EventDetectorsService in project ma-core-public by MangoAutomation.
the class MockMango method createMockDataPointsWithDetectors.
/**
* Create data points and event detectors asynchronously, waiting until all are created
*/
public List<DataPointVO> createMockDataPointsWithDetectors(int dataPointCount, Map<String, String> tags, int detectorsPerPoint) throws ExecutionException, InterruptedException {
List<DataPointVO> points = createDataPoints(dataPointCount, tags);
EventDetectorDefinition<?> updateEventDetectorDefinition = ModuleRegistry.getEventDetectorDefinition("UPDATE");
List<CompletableFuture<AbstractEventDetectorVO>> detectors = new ArrayList<>();
EventDetectorsService eventDetectorsService = Common.getBean(EventDetectorsService.class);
for (IDataPoint point : points) {
for (int i = 0; i < detectorsPerPoint; i++) {
detectors.add(eventDetectorsService.insertAsync(updateEventDetectorDefinition.baseCreateEventDetectorVO(point.getId())).toCompletableFuture());
}
}
// Wait for all detectors to be created
CompletableFuture.allOf(detectors.toArray(new CompletableFuture[0])).thenApply(ignored -> detectors.stream().map(CompletableFuture::join).collect(Collectors.toList())).get();
return points;
}
use of com.infiniteautomation.mango.spring.service.EventDetectorsService in project ma-core-public by infiniteautomation.
the class MockMango method createMockDataPointsWithDetectors.
/**
* Create data points and event detectors asynchronously, waiting until all are created
*/
public List<DataPointVO> createMockDataPointsWithDetectors(int dataPointCount, Map<String, String> tags, int detectorsPerPoint) throws ExecutionException, InterruptedException {
List<DataPointVO> points = createDataPoints(dataPointCount, tags);
EventDetectorDefinition<?> updateEventDetectorDefinition = ModuleRegistry.getEventDetectorDefinition("UPDATE");
List<CompletableFuture<AbstractEventDetectorVO>> detectors = new ArrayList<>();
EventDetectorsService eventDetectorsService = Common.getBean(EventDetectorsService.class);
for (IDataPoint point : points) {
for (int i = 0; i < detectorsPerPoint; i++) {
detectors.add(eventDetectorsService.insertAsync(updateEventDetectorDefinition.baseCreateEventDetectorVO(point.getId())).toCompletableFuture());
}
}
// Wait for all detectors to be created
CompletableFuture.allOf(detectors.toArray(new CompletableFuture[0])).thenApply(ignored -> detectors.stream().map(CompletableFuture::join).collect(Collectors.toList())).get();
return points;
}
Aggregations