-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
7bf982c
Refactoring data connections and container.
staudtMarius 0f633bd
Addressing `sonarqube` issues.
staudtMarius 30cf61e
Adding `CHANGELOG` entries.
staudtMarius 9a1af78
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius 498c152
Some small improvements.
staudtMarius eb44d2a
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius becdadb
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius 102d75c
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius b19ccf6
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius cd10282
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius f2b13e8
Adapt `CHANGELOG` to latest release.
staudtMarius 94662cf
Small changes to `ExtEmDataConnection`.
staudtMarius 87ecbc3
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius b55e113
Refactoring `EmSetPoint`.
staudtMarius b1b81c7
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius 1905c94
Including reviewer's comments.
staudtMarius daaa94c
Fix failing tests.
staudtMarius b77e500
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius 967a569
Including reviewer's comments.
staudtMarius 17b2e2f
Increasing test coverage.
staudtMarius 978ca23
Merge branch 'dev' into ms/#267-refactoring-data-connections
staudtMarius 7acd136
Including reviewer's comments.
staudtMarius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,41 @@ | ||
# Data connections | ||
|
||
In order to exchange data between SIMONA and an external simulation, this API defines some data connections. | ||
|
||
The data connections provided by the API can be divided into three kinds of data connections: | ||
staudtMarius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 is for the actual service within SIMONA that will receive the external data. The second | ||
staudtMarius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
reference is for the external simulation adapter. The adapter will receive a message to schedule the data service in SIMONA. | ||
staudtMarius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The process of sending data to the service and asking for scheduling of the service is taken care of by the method `sendExtMsg`. | ||
staudtMarius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
In order to send a message, simply call the method with the message as input. | ||
staudtMarius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 send by SIMONA. The result data connection itself cannot send messages to SIMONA. | ||
staudtMarius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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. Also, one additional feature is, that a bidirectional data connections | ||
can request responses, e.g. SIMONA results. | ||
staudtMarius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Currently, the following input data connections are provided: | ||
- ExtEmDataConnection | ||
- ExtEvDataConnection | ||
- ExtResultDataConnection |
22 changes: 0 additions & 22 deletions
22
src/main/java/edu/ie3/simona/api/data/DataQueueExtSimulationExtSimulator.java
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
src/main/java/edu/ie3/simona/api/data/ExtDataContainer.java
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
src/main/java/edu/ie3/simona/api/data/ExtDataContainerQueue.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* © 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.concurrent.LinkedBlockingDeque; | ||
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<>(); | ||
|
||
/** | ||
* 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 take 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 take 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; | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
src/main/java/edu/ie3/simona/api/data/ExtInputDataConnection.java
This file was deleted.
Oops, something went wrong.
69 changes: 0 additions & 69 deletions
69
src/main/java/edu/ie3/simona/api/data/ExtInputDataContainer.java
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/main/java/edu/ie3/simona/api/data/ExtOutputDataConnection.java
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
src/main/java/edu/ie3/simona/api/data/connection/BiDirectional.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* © 2025. 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.connection; | ||
|
||
import edu.ie3.simona.api.data.ontology.DataMessageFromExt; | ||
import edu.ie3.simona.api.data.ontology.DataResponseMessageToExt; | ||
import edu.ie3.simona.api.exceptions.WrongResponseTypeException; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
|
||
/** | ||
* Enables bidirectional communication when extended by an external data connection. | ||
* | ||
* @param <M> type of message to SIMONA | ||
* @param <R> type of response messages to ext | ||
*/ | ||
public abstract non-sealed class BiDirectional< | ||
M extends DataMessageFromExt, R extends DataResponseMessageToExt> | ||
extends ExtInputDataConnection<M> implements ExtOutputDataConnection<R> { | ||
|
||
/** Data message queue containing messages from SIMONA */ | ||
public final LinkedBlockingQueue<R> receiveTriggerQueue = new LinkedBlockingQueue<>(); | ||
|
||
protected BiDirectional() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public final void queueExtResponseMsg(R msg) throws InterruptedException { | ||
receiveTriggerQueue.put(msg); | ||
} | ||
|
||
@Override | ||
public final R receiveAny() throws InterruptedException { | ||
return receiveTriggerQueue.take(); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public final <T extends R> T receiveWithType(Class<T> expectedMessageClass) | ||
throws InterruptedException { | ||
// blocks until actor puts something here | ||
R msg = receiveTriggerQueue.take(); | ||
|
||
if (msg.getClass().equals(expectedMessageClass)) { | ||
return (T) msg; | ||
} else | ||
throw new WrongResponseTypeException( | ||
"Received unexpected message '" | ||
+ msg | ||
+ "', expected type '" | ||
+ expectedMessageClass | ||
+ "'"); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.