Class SimulationManager

java.lang.Object
com.nomagic.magicdraw.simulation.SimulationManager

@OpenApiAll public final class SimulationManager extends Object
API for running and stopping simulations and registering simulation listeners
  • Constructor Details

    • SimulationManager

      public SimulationManager()
  • Method Details

    • registerEngine

      public static void registerEngine(ExecutionEngineDescriptor engineDescriptor)
      Registers an engine descriptor to the simulation framework.
      Parameters:
      engineDescriptor - an engine descriptor.
    • execute

      public static SimulationResult execute(Element element, boolean start)
      Non-blocking method for executing the specific element.
      Parameters:
      element - the element that be executed
      start - if this flag is true, it will auto start the session. if the element is SimulationConfig, this flag will be ignored, it will use value inside SimulationConfig instead.
      Returns:
      the created SimulationResult. If this method is called in EDT, the returned SimulationResult will not be completed yet, it requires to release EDT for values completion.
    • executeWithConfig

      public static SimulationResult executeWithConfig(Element target, Element simulationConfig, boolean start)
      Executes the target element with a specific simulation config. Non-blocking method.
      Parameters:
      target - target element to execute, for example InstanceSpecification
      simulationConfig - config that is compatible with the target element
      start - if this flag is true, it will auto start the session.
      Returns:
      the created SimulationResult.
    • isSilentSimulation

      public static boolean isSilentSimulation(SimulationSession session)
      Check the simulation runt in silent mode or not.
      Parameters:
      session - the simulation session.
      Returns:
      true if simulation run in silent mode
    • terminateSession

      public static void terminateSession(@CheckForNull SimulationSession session)
      Terminate the running session.
      Parameters:
      session - the session being terminated
    • terminate

      public static void terminate(@CheckForNull SimulationResult result)
      Terminate the running session. If session is not found, interrupt all running tasks.
    • registerSimulationExecutionListener

      public static void registerSimulationExecutionListener(SimulationExecutionListener listener)
      Register the simulation execution listener.
      Parameters:
      listener - the registered simulation execution listener
    • registerSimulationExecutionListener

      public static void registerSimulationExecutionListener(SimulationExecutionListener listener, SimulationExecution execution)
      Register the simulation execution listener dynamically to the specified SimulationExecution.
      Parameters:
      listener - the registered simulation execution listener
      execution - the simulation execution
    • registerSimulationOptionsProvider

      public static void registerSimulationOptionsProvider(SimulationOptionsProvider optionsProvider)
      Register the simulation options provider.
      Parameters:
      optionsProvider - the registered simulation options provider
    • unregisterSimulationExecutionListener

      public static void unregisterSimulationExecutionListener(SimulationExecutionListener listener)
      Unregister the simulation execution listener.
      Parameters:
      listener - the unregistered simulation execution listener
    • unregisterSimulationExecutionListener

      public static void unregisterSimulationExecutionListener(SimulationExecutionListener listener, SimulationExecution execution)
      unregister the simulation execution listener dynamically from the specified SimulationExecution.
      Parameters:
      listener - the unregistered simulation execution listener
      execution - the simulation execution
    • unregisterSimulationOptionsProvider

      public static void unregisterSimulationOptionsProvider(SimulationOptionsProvider optionsProvider)
      Unregister the simulation options provider.
      Parameters:
      optionsProvider - the registered simulation options provider
    • logConsoleDebug

      public static void logConsoleDebug(BaseElement element, String message)
      Log the specified message to the simulation console with "DEBUG" log level.
      Parameters:
      element - an element of the running simulation
      message - the specified message
    • logConsoleInfo

      public static void logConsoleInfo(BaseElement element, String message)
      Log the specified message to the simulation console with "INFO" log level.
      Parameters:
      element - an element of the running simulation
      message - the specified message
    • logConsoleWarn

      public static void logConsoleWarn(BaseElement element, String message)
      Log the specified message to the simulation console with "WARN" log level.
      Parameters:
      element - an element of the running simulation
      message - the specified message
    • logConsoleError

      public static void logConsoleError(BaseElement element, String message)
      Log the specified message to the simulation console with "ERROR" log level.
      Parameters:
      element - an element of the running simulation
      message - the specified message
    • getRefSession

      @CheckForNull public static SimulationSession getRefSession(fUML.Semantics.Classes.Kernel.Object_ object)
      Get the referenced session of the specified object. If object is typed by Object_, the referenced session is a session that object was created.
      Parameters:
      object - a specified Object_
      Returns:
      the referenced SimulationSession
    • getSession

      @CheckForNull public static SimulationSession getSession(SimulationResult result)
      Retrieves simulation session from simulation result.
      Returns:
      session retrieved from simulation result
    • getRootContext

      @CheckForNull public static fUML.Semantics.Classes.Kernel.Object_ getRootContext(SimulationSession session)
      Get the root context of the running session.
      Parameters:
      session - the running session
      Returns:
      the root context
    • getContext

      @CheckForNull public static fUML.Semantics.Classes.Kernel.Object_ getContext(SimulationSession session)
      Get the context of the running session.
      Parameters:
      session - the running session
      Returns:
      the context of the running session
    • simulate

      public static Map<String,Object> simulate(BaseElement context, String configKeyword, @CheckForNull String targetKeyword, @CheckForNull String[] outputs, Object... inputs) throws com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException
      Executes the target element with a specific simulation config with custom initial values. Returns specified simulation parameters values, or all simulation values if it isn't specified.
      Parameters:
      context - search context where to look simulationConfigKeyword and targetKeyword
      configKeyword - config name or id that is compatible with the target element
      targetKeyword - the target element name or id to execute, for example InstanceSpecification
      outputs - array of parameters names which will be returned
      inputs - key value pair of parameters values which will be used in simulation
      Returns:
      the simulation parameters values
      Throws:
      com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException - if inputs value type mismatch, not all input values was replaced or inputs key value parameter is missing
    • simulate

      public static Map<String,Object> simulate(BaseElement context, String simulationConfigKeyword, Object... inputs) throws com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException
      Executes the simulation config with custom initial values. Returns specified simulation parameters values, or all simulation values if it isn't specified.
      Parameters:
      context - search context where to look simulationConfigKeyword
      simulationConfigKeyword - simulation config name or id
      inputs - key value pair of parameters values which will be used in simulation
      Returns:
      the simulation parameters values
      Throws:
      com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException - if inputs value type mismatch, not all input values was replaced or inputs key value parameter is missing
    • simulate

      public static Map<String,Object> simulate(BaseElement context, String simulationConfigKeyword, @CheckForNull String[] outputs, Object... inputs) throws com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException
      Executes the simulation config with custom initial values. Returns specified simulation parameters values, or all simulation values if it isn't specified.
      Parameters:
      context - search context where to look simulation config
      simulationConfigKeyword - simulation configuration name or id
      outputs - array of parameters names which will be returned
      inputs - key value pair of parameters values which will be used in simulation
      Returns:
      the simulation parameters values
      Throws:
      com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException - if inputs value type mismatch, not all input values was replaced or inputs key value parameter is missing
    • simulate

      public static Map<String,Object> simulate(Element simulationConfig, Element target, Object... inputs) throws com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException
      Executes the target element with a specific simulation config with initial custom values. Returns specified simulation parameters values, or all simulation values if it isn't specified.
      Parameters:
      simulationConfig - that is compatible with the target element
      target - the element to execute, for example InstanceSpecification
      inputs - key value pair of parameters values which will be used in simulation
      Returns:
      the simulation parameters values
      Throws:
      com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException - if inputs value type mismatch, not all input values was replaced or inputs key value parameter is missing
    • simulate

      public static Map<String,Object> simulate(Element simulationConfig, Object... inputs) throws com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException
      Executes the simulation config with custom initial values. Returns specified simulation parameters values, or all simulation values if it isn't specified.
      Parameters:
      simulationConfig - the element to execute
      inputs - key value pair of parameters values which will be used in simulation
      Returns:
      the simulation parameters values
      Throws:
      com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException - if inputs value type mismatch, not all input values was replaced or inputs key value parameter is missing
    • simulate

      public static Map<String,Object> simulate(Element element, String[] outputs, Object... inputs) throws com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException
      Executes the simulation config with initial custom values. This is a blocking method. Returns specified simulation parameters values, or all simulation values if it isn't specified.
      Parameters:
      element - the element to execute - either a SimulationConfig, or a Classifier/Behavior directly.
      outputs - names of parameter runtime values to be returned when simulation completes. When null is provided, all values will be returned.
      inputs - key-value map of values which will be used as initial values for the execution. When null is provided, execution will be initialized with values as described in the model.
      Returns:
      the simulation parameters values
      Throws:
      com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException - if inputs value type mismatch, not all input values was replaced or inputs key value parameter is missing
    • simulate

      public static Map<String,Object> simulate(Element element, @CheckForNull Collection<String> outputs, @CheckForNull Map<String,Object> inputs) throws com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException
      Executes the simulation config or an element with custom initial values. This is a blocking method. Returns specified simulation parameters values, or all simulation values if it isn't specified.
      Parameters:
      element - the element to execute - either a SimulationConfig, or a Classifier/Behavior directly.
      outputs - names of parameter runtime values to be returned when simulation completes. When null is provided, all values will be returned.
      inputs - key-value map of values which will be used as initial values for the execution. When null is provided, execution will be initialized with values as described in the model.
      Returns:
      the simulation parameters values
      Throws:
      com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException - if inputs value type mismatch, not all input values was replaced or inputs key value parameter is missing
    • simulate

      public static Map<String,Object> simulate(Element simulationConfig, @CheckForNull Element target, @CheckForNull String[] outputs, Object... inputs) throws com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException
      Executes the target element with a specific simulation config with custom initial values. This is a blocking method. Returns specified simulation parameters values, or all simulation values if it isn't specified.
      Parameters:
      simulationConfig - that is compatible with the target element
      target - the target element to execute, for example InstanceSpecification
      outputs - names of parameter runtime values to be returned when simulation completes. When null is provided, all values will be returned.
      inputs - key-value map of values which will be used as initial values for the execution. When null is provided, execution will be initialized with values as described in the model.
      Returns:
      the simulation parameters values
      Throws:
      com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException - if inputs value type mismatch, not all input values was replaced or inputs key value parameter is missing
    • simulate

      public static Map<String,Object> simulate(Element simulationConfig, @CheckForNull Element target, @CheckForNull Collection<String> outputs, @CheckForNull Map<String,Object> inputs) throws com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException
      Executes the target element with a specific simulation config with custom initial values. This is a blocking method. Returns specified simulation parameters values, or all simulation values if it isn't specified.
      Parameters:
      simulationConfig - that is compatible with the target element
      target - the target element to execute with the specified config, for example InstanceSpecification
      outputs - names of parameter runtime values to be returned when simulation completes. When null is provided, all values will be returned.
      inputs - key-value map of values which will be used as initial values for the execution. When null is provided, execution will be initialized with values as described in the model.
      Returns:
      the simulation parameters values
      Throws:
      com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException - if inputs value type mismatch, not all input values was replaced or inputs key value parameter is missing
    • simulateAsync

      public static SimulationResult simulateAsync(Element simulationConfig, @CheckForNull Element target, @CheckForNull String[] outputs, Object... inputs) throws com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException
      Asynchronously executes the target element with a specific simulation config with custom initial parameters values. Returns specified simulation parameters values, or all simulation values if it isn't specified.
      Parameters:
      simulationConfig - config that is compatible with the target element
      target - target element to execute, for example InstanceSpecification
      outputs - names of parameter runtime values to be returned when simulation completes. When null is provided, all values will be returned.
      inputs - key-value map of values which will be used as initial values for the execution. When null is provided, execution will be initialized with values as described in the model.
      Returns:
      the created SimulationResult
      Throws:
      com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException - if inputs value type mismatch, not all input values was replaced or inputs key value parameter is missing
    • simulateAsync

      public static SimulationResult simulateAsync(Element simulationConfig, @CheckForNull Element target, @CheckForNull Collection<String> outputs, Map<String,Object> inputs) throws com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException
      Asynchronously executes the target element with a specific simulation config with custom initial parameters values. Returns specified simulation parameters values, or all simulation values if it isn't specified.
      Parameters:
      simulationConfig - config that is compatible with the target element
      target - target element to execute, for example InstanceSpecification
      outputs - names of parameter runtime values to be returned when simulation completes. When null is provided, all values will be returned.
      inputs - key-value map of values which will be used as initial values for the execution. When null is provided, execution will be initialized with values as described in the model.
      Returns:
      the created SimulationResult
      Throws:
      com.nomagic.magicdraw.simulation.exceptions.SimulationInputValuesException - if inputs value type mismatch, not all input values was replaced or inputs key value parameter is missing