Skip to content

Commit 10d7a4c

Browse files
committed
Adding max delay parameter to em communication.
1 parent 3a7b213 commit 10d7a4c

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

src/main/java/edu/ie3/simona/api/data/connection/ExtEmDataConnection.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import edu.ie3.simona.api.data.model.em.FlexOptions;
1313
import edu.ie3.simona.api.ontology.em.*;
1414
import java.util.*;
15+
import javax.measure.quantity.Time;
1516
import org.slf4j.Logger;
17+
import tech.units.indriya.ComparableQuantity;
1618

1719
/** Enables data connection of em data between SIMONA and SimonaAPI */
1820
public final class ExtEmDataConnection
@@ -23,18 +25,35 @@ public final class ExtEmDataConnection
2325
/** Assets that are controlled by external simulation */
2426
private final List<UUID> controlled;
2527

28+
private final Optional<ComparableQuantity<Time>> maxDelay;
29+
2630
public ExtEmDataConnection(List<UUID> controlled, EmMode mode) {
2731
super();
2832

2933
this.mode = mode;
3034
this.controlled = controlled;
35+
this.maxDelay = Optional.empty();
36+
}
37+
38+
public ExtEmDataConnection(
39+
List<UUID> controlled, EmMode mode, Optional<ComparableQuantity<Time>> maxDelay) {
40+
super();
41+
42+
this.mode = mode;
43+
this.controlled = controlled;
44+
this.maxDelay = maxDelay;
3145
}
3246

3347
/** Returns a list of the uuids of the em agents that expect external set points */
3448
public List<UUID> getControlledEms() {
3549
return new ArrayList<>(controlled);
3650
}
3751

52+
/** Returns the maximal delay, that is allowed for a message when using the em communication. */
53+
public Optional<ComparableQuantity<Time>> getMaxDelay() {
54+
return maxDelay;
55+
}
56+
3857
/**
3958
* Sends the em flex requests to SIMONA.
4059
*

src/main/java/edu/ie3/simona/api/simulation/ExtCoSimulation.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import edu.ie3.simona.api.exceptions.ExtDataConnectionException;
2121
import edu.ie3.simona.api.mapping.DataType;
2222
import java.util.*;
23+
import javax.measure.quantity.Time;
2324
import org.slf4j.Logger;
25+
import tech.units.indriya.ComparableQuantity;
2426

2527
/**
2628
* Abstract class for an external co-simulation with bidirectional communication with SIMONA.
@@ -72,11 +74,19 @@ public static ExtPrimaryDataConnection buildPrimaryConnection(
7274
* Builds an {@link ExtEmDataConnection}.
7375
*
7476
* @param controlled uuids for controlled em agents.
77+
* @param maxDelay the maximal delay used in em communication mode
7578
* @param log logger
7679
* @return an ext em data connection
7780
*/
7881
public static ExtEmDataConnection buildEmConnection(
79-
List<UUID> controlled, ExtEmDataConnection.EmMode mode, Logger log) {
82+
List<UUID> controlled,
83+
ExtEmDataConnection.EmMode mode,
84+
Optional<ComparableQuantity<Time>> maxDelay,
85+
Logger log) {
86+
if (maxDelay.isEmpty() && mode == ExtEmDataConnection.EmMode.EM_COMMUNICATION) {
87+
log.info("Using em communication without a maximum delay.");
88+
}
89+
8090
if (controlled.isEmpty()) {
8191
log.warn("Em data connection with 0 controlled entities created. This might lead to errors!");
8292
throw new ExtDataConnectionException(ExtEmDataConnection.class);
@@ -86,7 +96,7 @@ public static ExtEmDataConnection buildEmConnection(
8696
mode,
8797
controlled.size());
8898

89-
return new ExtEmDataConnection(controlled, mode);
99+
return new ExtEmDataConnection(controlled, mode, maxDelay);
90100
}
91101
}
92102

src/test/groovy/edu/ie3/simona/api/simulation/ExtCoSimulationTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ class ExtCoSimulationTest extends Specification {
5050
def controlled = [uuid1, uuid2]
5151

5252
when:
53-
def actual = ExtCoSimulation.buildEmConnection(controlled, EmMode.BASE, log)
53+
def actual = ExtCoSimulation.buildEmConnection(controlled, EmMode.BASE, Optional.empty(), log)
5454

5555
then:
5656
actual.getControlledEms() == [uuid1, uuid2]
5757
}
5858

5959
def "An ExtCoSimulation throws an ExtDataConnectionException while trying to build an empty em data connection"() {
6060
when:
61-
ExtCoSimulation.buildEmConnection([], EmMode.BASE, log)
61+
ExtCoSimulation.buildEmConnection([], EmMode.BASE, Optional.empty(), log)
6262

6363
then:
6464
ExtDataConnectionException ex = thrown(ExtDataConnectionException)

0 commit comments

Comments
 (0)