Search in sources :

Example 1 with EventDetectorsService

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;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) CompletableFuture(java.util.concurrent.CompletableFuture) Scope(org.openjdk.jmh.annotations.Scope) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ArrayList(java.util.ArrayList) EventDetectorsService(com.infiniteautomation.mango.spring.service.EventDetectorsService) DataType(com.serotonin.m2m2.DataType) SQLException(java.sql.SQLException) Map(java.util.Map) MangoTestBase(com.serotonin.m2m2.MangoTestBase) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) TearDown(org.openjdk.jmh.annotations.TearDown) AbstractEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) Setup(org.openjdk.jmh.annotations.Setup) Common(com.serotonin.m2m2.Common) EventDetectorDefinition(com.serotonin.m2m2.module.EventDetectorDefinition) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) IOException(java.io.IOException) UUID(java.util.UUID) State(org.openjdk.jmh.annotations.State) Collectors(java.util.stream.Collectors) ModuleRegistry(com.serotonin.m2m2.module.ModuleRegistry) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) MockMangoLifecycle(com.serotonin.m2m2.MockMangoLifecycle) Level(org.openjdk.jmh.annotations.Level) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) EventDetectorsService(com.infiniteautomation.mango.spring.service.EventDetectorsService)

Example 2 with EventDetectorsService

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;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) CompletableFuture(java.util.concurrent.CompletableFuture) Scope(org.openjdk.jmh.annotations.Scope) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ArrayList(java.util.ArrayList) EventDetectorsService(com.infiniteautomation.mango.spring.service.EventDetectorsService) DataType(com.serotonin.m2m2.DataType) SQLException(java.sql.SQLException) Map(java.util.Map) MangoTestBase(com.serotonin.m2m2.MangoTestBase) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) TearDown(org.openjdk.jmh.annotations.TearDown) AbstractEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO) Setup(org.openjdk.jmh.annotations.Setup) Common(com.serotonin.m2m2.Common) EventDetectorDefinition(com.serotonin.m2m2.module.EventDetectorDefinition) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) IOException(java.io.IOException) UUID(java.util.UUID) State(org.openjdk.jmh.annotations.State) Collectors(java.util.stream.Collectors) ModuleRegistry(com.serotonin.m2m2.module.ModuleRegistry) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) MockMangoLifecycle(com.serotonin.m2m2.MockMangoLifecycle) Level(org.openjdk.jmh.annotations.Level) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) IDataPoint(com.serotonin.m2m2.vo.IDataPoint) EventDetectorsService(com.infiniteautomation.mango.spring.service.EventDetectorsService)

Aggregations

DataPointService (com.infiniteautomation.mango.spring.service.DataPointService)2 EventDetectorsService (com.infiniteautomation.mango.spring.service.EventDetectorsService)2 Common (com.serotonin.m2m2.Common)2 DataType (com.serotonin.m2m2.DataType)2 MangoTestBase (com.serotonin.m2m2.MangoTestBase)2 MockMangoLifecycle (com.serotonin.m2m2.MockMangoLifecycle)2 EventDetectorDefinition (com.serotonin.m2m2.module.EventDetectorDefinition)2 ModuleRegistry (com.serotonin.m2m2.module.ModuleRegistry)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 IDataPoint (com.serotonin.m2m2.vo.IDataPoint)2 MockPointLocatorVO (com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)2 MockDataSourceVO (com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO)2 AbstractEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2