-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1507 from NASA-AMMOS/feat/stream-sim-results
Stream Simulation Resources
- Loading branch information
Showing
47 changed files
with
1,696 additions
and
1,205 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
52 changes: 52 additions & 0 deletions
52
merlin-driver/src/main/java/gov/nasa/jpl/aerie/merlin/driver/CachedSimulationEngine.java
This file contains 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,52 @@ | ||
package gov.nasa.jpl.aerie.merlin.driver; | ||
|
||
import gov.nasa.jpl.aerie.merlin.driver.engine.SimulationEngine; | ||
import gov.nasa.jpl.aerie.merlin.driver.engine.SpanException; | ||
import gov.nasa.jpl.aerie.merlin.driver.resources.InMemorySimulationResourceManager; | ||
import gov.nasa.jpl.aerie.merlin.protocol.driver.Topic; | ||
import gov.nasa.jpl.aerie.merlin.protocol.types.Duration; | ||
|
||
import java.time.Instant; | ||
import java.util.Map; | ||
|
||
public record CachedSimulationEngine( | ||
Duration endsAt, | ||
Map<ActivityDirectiveId, ActivityDirective> activityDirectives, | ||
SimulationEngine simulationEngine, | ||
Topic<ActivityDirectiveId> activityTopic, | ||
MissionModel<?> missionModel, | ||
InMemorySimulationResourceManager resourceManager | ||
) { | ||
public void freeze() { | ||
simulationEngine.close(); | ||
} | ||
|
||
public static CachedSimulationEngine empty(final MissionModel<?> missionModel, final Instant simulationStartTime) { | ||
final SimulationEngine engine = new SimulationEngine(missionModel.getInitialCells()); | ||
|
||
// Specify a topic on which tasks can log the activity they're associated with. | ||
final var activityTopic = new Topic<ActivityDirectiveId>(); | ||
try { | ||
engine.init(missionModel.getResources(), missionModel.getDaemon()); | ||
|
||
return new CachedSimulationEngine( | ||
Duration.MIN_VALUE, | ||
Map.of(), | ||
engine, | ||
new Topic<>(), | ||
missionModel, | ||
new InMemorySimulationResourceManager() | ||
); | ||
} catch (SpanException ex) { | ||
// Swallowing the spanException as the internal `spanId` is not user meaningful info. | ||
final var topics = missionModel.getTopics(); | ||
final var directiveId = engine.getDirectiveIdFromSpan(activityTopic, topics, ex.spanId); | ||
if (directiveId.isPresent()) { | ||
throw new SimulationException(Duration.ZERO, simulationStartTime, directiveId.get(), ex.cause); | ||
} | ||
throw new SimulationException(Duration.ZERO, simulationStartTime, ex.cause); | ||
} catch (Throwable ex) { | ||
throw new SimulationException(Duration.ZERO, simulationStartTime, ex); | ||
} | ||
} | ||
} |
Oops, something went wrong.