Skip to content

Refactoring data connections and container. #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7bf982c
Refactoring data connections and container.
staudtMarius Apr 7, 2025
0f633bd
Addressing `sonarqube` issues.
staudtMarius Apr 7, 2025
30cf61e
Adding `CHANGELOG` entries.
staudtMarius Apr 8, 2025
9a1af78
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius Apr 8, 2025
498c152
Some small improvements.
staudtMarius Apr 10, 2025
eb44d2a
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius Apr 10, 2025
becdadb
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius May 6, 2025
102d75c
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius May 7, 2025
b19ccf6
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius May 8, 2025
cd10282
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius May 9, 2025
f2b13e8
Adapt `CHANGELOG` to latest release.
staudtMarius May 9, 2025
94662cf
Small changes to `ExtEmDataConnection`.
staudtMarius May 12, 2025
87ecbc3
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius May 22, 2025
b55e113
Refactoring `EmSetPoint`.
staudtMarius May 22, 2025
b1b81c7
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius Jun 4, 2025
1905c94
Including reviewer's comments.
staudtMarius Jun 10, 2025
daaa94c
Fix failing tests.
staudtMarius Jun 10, 2025
b77e500
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius Jun 10, 2025
967a569
Including reviewer's comments.
staudtMarius Jun 10, 2025
17b2e2f
Increasing test coverage.
staudtMarius Jun 20, 2025
978ca23
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius Jun 20, 2025
7acd136
Including reviewer's comments.
staudtMarius Jun 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Removed Jenkinsfile [#290](https://github.com/ie3-institute/simonaAPI/issues/290)
- Adapted dependabot workflow and added CODEOWNERS [#294](https://github.com/ie3-institute/simonaAPI/issues/294)
- Refactoring external data connection [#267](https://github.com/ie3-institute/simonaAPI/issues/267)
- Refactoring data containers [#268](https://github.com/ie3-institute/simonaAPI/issues/268)

## [0.9.0] - 2025-05-09

Expand Down
39 changes: 39 additions & 0 deletions docs/readthedocs/connections/connections.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
# Data connections

This API defines some data connections in order to exchange data between SIMONA and an external simulation.

1. Input data connections
2. Output data connections
3. Bidirectional data connections

## Input data connections

These data connections are used to provide SIMONA with external data. Each input data connection contains two references
for SIMONA actors. The first reference specifies the SIMONA service that will receive the external data. The second
reference is for the external simulation adapter. This adapter receives a message to schedule the data service in SIMONA.

The process of sending data to the service and requesting scheduling is handled by the `sendExtMsg` method.
To send a message, simply call the method with the message as input.

Currently, the following input data connections are provided:
- ExtPrimaryDataConnection


## Output data connections

These data connections are used to provide SIMONA response messages to the external simulation. Each output data connection
has a queue for messages sent by SIMONA. The result data connection itself cannot send messages to SIMONA.

Currently, the following input data connections are provided:
- ExtResultListener


## Bidirectional data connections

The bidirectional data connection combines the functionality of both input and output data connections. These data connections
can be used to send data to SIMONA and receive responses. One additional feature is that bidirectional data connections
can be used to request responses, e.g. SIMONA results.

Currently, the following input data connections are provided:
- ExtEmDataConnection
- ExtEvDataConnection
- ExtResultDataConnection
17 changes: 17 additions & 0 deletions docs/readthedocs/simulations/externalsimulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,20 @@ method should provide a new tick as long as there are future activities.

The method `getDataConnections` returns all [data connections](/connections/connections) that are used to connect the
external simulation to SIMONA.


## Communication between SIMONA and an external simulation

Depending on the connections used by the external simulation, the following communication structures are used:

- Input connections: external simulation -> simonaAPI -> SIMONA
- Output connections: SIMONA -> simonaAPI -> external simulation

Bidirectional connections can use both structures.


## Co-simulations

This API provides an extension to the class `edu.ie3.simona.api.simulation.ExtSimulation` in the form of
`edu.ie3.simona.api.simulation.ExtCoSimulation`. This class contains some methods to simplify the definition of external
co-simulations.

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/java/edu/ie3/simona/api/data/ExtDataContainer.java

This file was deleted.

117 changes: 117 additions & 0 deletions src/main/java/edu/ie3/simona/api/data/ExtDataContainerQueue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* © 2024. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/

package edu.ie3.simona.api.data;

import edu.ie3.simona.api.data.container.ExtDataContainer;
import java.util.Optional;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

/** Data queue to allow data flow between SimonaAPI and an external simulation */
public final class ExtDataContainerQueue<V extends ExtDataContainer> {
private final LinkedBlockingDeque<V> receiverTriggerDeque = new LinkedBlockingDeque<>();

/** Returns the number of elements in this queue. */
public int size() {
return receiverTriggerDeque.size();
}

/**
* Method for adding an {@link ExtDataContainer} to the queue.
*
* @param data to be added
* @throws InterruptedException if the thread running this has been interrupted during the
* blocking operation
*/
public void queueData(V data) throws InterruptedException {
receiverTriggerDeque.putLast(data);
}

/**
* Method to retrieve and remove an {@link ExtDataContainer} from the queue. This method waits
* (blocks) until data is added to the queue.
*
* @return a data container
* @throws InterruptedException if the thread running this has been interrupted during the
* blocking operation
*/
public V takeContainer() throws InterruptedException {
return receiverTriggerDeque.takeFirst();
}

/**
* Method to retrieve and remove an {@link ExtDataContainer} from the queue. This method waits
* (blocks) until either data is added to the queue or the specified wait time is reached.
*
* @param timeout maximal time to wait for data
* @param unit unit of the timeout
* @return an option for a data container
* @throws InterruptedException if the thread running this has been interrupted during the
* blocking operation
*/
public Optional<V> pollContainer(long timeout, TimeUnit unit) throws InterruptedException {
return Optional.ofNullable(receiverTriggerDeque.pollFirst(timeout, unit));
}

/**
* Method to retrieve only a part of a container from the queue. This method waits (blocks) until
* data is added to the queue.
*
* @param extractor function to extract a part of the container
* @return the extracted part
* @param <R> type of returned value
* @throws InterruptedException if the thread running this has been interrupted during the
* blocking operation
*/
public <R> R takeData(Function<V, R> extractor) throws InterruptedException {
// removes the first container from the queue
V data = receiverTriggerDeque.takeFirst();
R result = extractor.apply(data);

// if the container is not empty, it should remain in the queue.
// else the container needs to be removed
if (!data.isEmpty()) {
receiverTriggerDeque.putFirst(data);
}

return result;
}

/**
* Method to retrieve only a part of a container from the queue. This method waits (blocks) until
* either data is added to the queue or the specified wait time is reached.
*
* @param extractor function to extract a part of the container
* @param timeout maximal time to wait for data
* @param unit unit of the timeout
* @return an option for the extracted part
* @param <R> type of returned value
* @throws InterruptedException if the thread running this has been interrupted during the
* blocking operation
*/
public <R> Optional<R> pollData(Function<V, R> extractor, long timeout, TimeUnit unit)
throws InterruptedException {
// removes the first container from the queue
Optional<V> containerOption = pollContainer(timeout, unit);

if (containerOption.isPresent()) {
V data = containerOption.get();
R result = extractor.apply(data);

// if the container is not empty, it should remain in the queue.
// else the container needs to be removed
if (!data.isEmpty()) {
receiverTriggerDeque.putFirst(data);
}

return Optional.of(result);
}

return Optional.empty();
}
}
29 changes: 0 additions & 29 deletions src/main/java/edu/ie3/simona/api/data/ExtInputDataConnection.java

This file was deleted.

69 changes: 0 additions & 69 deletions src/main/java/edu/ie3/simona/api/data/ExtInputDataContainer.java

This file was deleted.

31 changes: 0 additions & 31 deletions src/main/java/edu/ie3/simona/api/data/ExtOutputDataConnection.java

This file was deleted.

Loading