Class Run<S extends org.eclipse.emf.ecore.EObject>
java.lang.Object
com.amalgamasimulation.studies.core.Run<S>
- Type Parameters:
S- Type representing a root type of EMF scenario. Typically, a "Scenario" instance of a data model.
Single run of the simulation model. The run is parameterized by a
EObject scenario. Result of the run is represented with a single
SimulationRunResult instance.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Runnableprotected SimulationRunResultprotected Sprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract doubleReturns the current simulation completion fraction as a number between 0.0 and 1.0;intCan be called from any external thread, including RCP UI threadintCan be called from any external thread, including RCP UI threadid()booleanabstract Optional<SimulationRunResult> result()Returns the run result, if any, or an empty Optional.abstract voidrun()Starts the run and blocks until the run is completed.protected voidCalls the completionActionHandler and then sets completionActionHandler to null.voidsetCompletionActionHandler(Runnable completionActionHandler) protected voidsetStatus(Run.Status newStatus) voidsetStopMonitor(Supplier<Boolean> stopMonitor) Sets the stopping monitor to the run.status()Returns the current run status.voidstop()Gracefully stops the run.
-
Field Details
-
scenario
-
seed
protected int seed -
result
-
completionActionHandler
-
-
Constructor Details
-
Run
-
Run
Creates a new instance of a run and assigns a unique id to it. Upon creation, the run's status isRun.Status.NOT_STARTED.- Parameters:
scenario- EMF scenario (instance inherited fromEObjectthat parameterizes the simulation model.seed- random number seed used to initialize random number sequences of the simulation model.
-
-
Method Details
-
isStopRequested
public boolean isStopRequested() -
setStopMonitor
Sets the stopping monitor to the run. Stopping monitor is a supplier of a boolean value that answers the question "must the run be stopped?". Iftrueis returned, then stoppage is initiated. Iffalseis returned, the run continues normally. More specifically:If the run is currently
Run.Status.IN_PROGRESSand stopMonitor returnstrue, that means "yes, stop the run", and the run must attempt to complete the execution as soon as possible.If the run is
Run.Status.NOT_STARTED, the stop monitor will be asked whenrun()method is called, and the run will not start iftrueis returned. In this case, the run will remain inRun.Status.NOT_STARTEDstatus.If the stop monitor is not set, the run cannot be canceled externally.
- Parameters:
stopMonitor- supplier of a boolean value that answers the question "must the run be cancelled?"
-
setCompletionActionHandler
-
runCompletionActionHandlerOnce
protected void runCompletionActionHandlerOnce()Calls the completionActionHandler and then sets completionActionHandler to null. This method is idempotent. -
id
-
errorsCount
public int errorsCount()Can be called from any external thread, including RCP UI thread- Returns:
-
elapsedTimeMillis
public int elapsedTimeMillis()Can be called from any external thread, including RCP UI thread- Returns:
-
setStatus
-
stop
public void stop()Gracefully stops the run. The method returns immediately, it is non-blocking.Can be called from any external thread, including RCP UI thread
-
status
Returns the current run status.Can be called from any external thread, including RCP UI thread
- Returns:
- current status
-
run
public abstract void run()Starts the run and blocks until the run is completed. -
result
Returns the run result, if any, or an empty Optional.Can be called from any external thread, including RCP UI thread
- Returns:
- run result
-
completedFraction
public abstract double completedFraction()Returns the current simulation completion fraction as a number between 0.0 and 1.0;Can be called from any external thread, including RCP UI thread
- Returns:
- simulation completion fraction
-