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.
Direct Known Subclasses:
LocalRun, RemoteRun

public abstract class Run<S extends org.eclipse.emf.ecore.EObject> extends Object
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.
  • Field Details

    • scenario

      protected S extends org.eclipse.emf.ecore.EObject scenario
    • seed

      protected int seed
    • result

      protected SimulationRunResult result
    • completionActionHandler

      protected Runnable completionActionHandler
  • Constructor Details

    • Run

      protected Run(S scenario, int seed, ShortId id)
    • Run

      protected Run(S scenario, int seed)
      Creates a new instance of a run and assigns a unique id to it. Upon creation, the run's status is Run.Status.NOT_STARTED.
      Parameters:
      scenario - EMF scenario (instance inherited from EObject that 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

      public void setStopMonitor(Supplier<Boolean> stopMonitor)
      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?". If true is returned, then stoppage is initiated. If false is returned, the run continues normally. More specifically:

      If the run is currently Run.Status.IN_PROGRESS and stopMonitor returns true, 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 when run() method is called, and the run will not start if true is returned. In this case, the run will remain in Run.Status.NOT_STARTED status.

      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

      public void setCompletionActionHandler(Runnable completionActionHandler)
    • runCompletionActionHandlerOnce

      protected void runCompletionActionHandlerOnce()
      Calls the completionActionHandler and then sets completionActionHandler to null. This method is idempotent.
    • id

      public ShortId 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

      protected void setStatus(Run.Status newStatus)
    • 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

      public Run.Status 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

      public abstract Optional<SimulationRunResult> 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