Package com.nomagic.magicdraw.simulation
Class SimulationManager
java.lang.Object
com.nomagic.magicdraw.simulation.SimulationManager
API for running and stopping simulations and registering simulation listeners
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic SimulationResult
Non-blocking method for executing the specific element.static SimulationResult
executeWithConfig
(Element target, Element simulationConfig, boolean start) Executes the target element with a specific simulation config.static fUML.Semantics.Classes.Kernel.Object_
getContext
(SimulationSession session) Get the context of the running session.static SimulationSession
getRefSession
(fUML.Semantics.Classes.Kernel.Object_ object) Get the referenced session of the specified object.static fUML.Semantics.Classes.Kernel.Object_
getRootContext
(SimulationSession session) Get the root context of the running session.static SimulationSession
getSession
(SimulationResult result) Retrieves simulation session from simulation result.static boolean
isSilentSimulation
(SimulationSession session) Check the simulation runt in silent mode or not.static void
logConsoleDebug
(BaseElement element, String message) Log the specified message to the simulation console with "DEBUG" log level.static void
logConsoleError
(BaseElement element, String message) Log the specified message to the simulation console with "ERROR" log level.static void
logConsoleInfo
(BaseElement element, String message) Log the specified message to the simulation console with "INFO" log level.static void
logConsoleWarn
(BaseElement element, String message) Log the specified message to the simulation console with "WARN" log level.static void
registerEngine
(ExecutionEngineDescriptor engineDescriptor) Registers an engine descriptor to the simulation framework.static void
Register the simulation execution listener.static void
registerSimulationExecutionListener
(SimulationExecutionListener listener, SimulationExecution execution) Register the simulation execution listener dynamically to the specified SimulationExecution.static void
registerSimulationOptionsProvider
(SimulationOptionsProvider optionsProvider) Register the simulation options provider.simulate
(BaseElement context, String simulationConfigKeyword, Object... inputs) Executes the simulation config with custom initial values.simulate
(BaseElement context, String simulationConfigKeyword, String[] outputs, Object... inputs) Executes the simulation config with custom initial values.simulate
(BaseElement context, String configKeyword, String targetKeyword, String[] outputs, Object... inputs) Executes the target element with a specific simulation config with custom initial values.Executes the target element with a specific simulation config with initial custom values.Executes the target element with a specific simulation config with custom initial values.simulate
(Element simulationConfig, Element target, Collection<String> outputs, Map<String, Object> inputs) Executes the target element with a specific simulation config with custom initial values.Executes the simulation config with custom initial values.Executes the simulation config with initial custom values.Executes the simulation config or an element with custom initial values.static SimulationResult
simulateAsync
(Element simulationConfig, Element target, String[] outputs, Object... inputs) Asynchronously executes the target element with a specific simulation config with custom initial parameters values.static SimulationResult
simulateAsync
(Element simulationConfig, Element target, Collection<String> outputs, Map<String, Object> inputs) Asynchronously executes the target element with a specific simulation config with custom initial parameters values.static void
terminate
(SimulationResult result) Terminate the running session.static void
terminateSession
(SimulationSession session) Terminate the running session.static void
Unregister the simulation execution listener.static void
unregisterSimulationExecutionListener
(SimulationExecutionListener listener, SimulationExecution execution) unregister the simulation execution listener dynamically from the specified SimulationExecution.static void
unregisterSimulationOptionsProvider
(SimulationOptionsProvider optionsProvider) Unregister the simulation options provider.
-
Constructor Details
-
SimulationManager
public SimulationManager()
-
-
Method Details
-
registerEngine
Registers an engine descriptor to the simulation framework.- Parameters:
engineDescriptor
- an engine descriptor.
-
execute
Non-blocking method for executing the specific element.- Parameters:
element
- the element that be executedstart
- 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 InstanceSpecificationsimulationConfig
- config that is compatible with the target elementstart
- if this flag is true, it will auto start the session.- Returns:
- the created SimulationResult.
-
isSilentSimulation
Check the simulation runt in silent mode or not.- Parameters:
session
- the simulation session.- Returns:
- true if simulation run in silent mode
-
terminateSession
Terminate the running session.- Parameters:
session
- the session being terminated
-
terminate
Terminate the running session. If session is not found, interrupt all running tasks. -
registerSimulationExecutionListener
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 listenerexecution
- the simulation execution
-
registerSimulationOptionsProvider
Register the simulation options provider.- Parameters:
optionsProvider
- the registered simulation options provider
-
unregisterSimulationExecutionListener
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 listenerexecution
- the simulation execution
-
unregisterSimulationOptionsProvider
Unregister the simulation options provider.- Parameters:
optionsProvider
- the registered simulation options provider
-
logConsoleDebug
Log the specified message to the simulation console with "DEBUG" log level.- Parameters:
element
- an element of the running simulationmessage
- the specified message
-
logConsoleInfo
Log the specified message to the simulation console with "INFO" log level.- Parameters:
element
- an element of the running simulationmessage
- the specified message
-
logConsoleWarn
Log the specified message to the simulation console with "WARN" log level.- Parameters:
element
- an element of the running simulationmessage
- the specified message
-
logConsoleError
Log the specified message to the simulation console with "ERROR" log level.- Parameters:
element
- an element of the running simulationmessage
- 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
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 targetKeywordconfigKeyword
- config name or id that is compatible with the target elementtargetKeyword
- the target element name or id to execute, for example InstanceSpecificationoutputs
- array of parameters names which will be returnedinputs
- 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 simulationConfigKeywordsimulationConfigKeyword
- simulation config name or idinputs
- 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 configsimulationConfigKeyword
- simulation configuration name or idoutputs
- array of parameters names which will be returnedinputs
- 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 elementtarget
- the element to execute, for example InstanceSpecificationinputs
- 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 executeinputs
- 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.SimulationInputValuesExceptionExecutes 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 elementtarget
- the target element to execute, for example InstanceSpecificationoutputs
- 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.SimulationInputValuesExceptionExecutes 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 elementtarget
- the target element to execute with the specified config, for example InstanceSpecificationoutputs
- 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 elementtarget
- target element to execute, for example InstanceSpecificationoutputs
- 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.SimulationInputValuesExceptionAsynchronously 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 elementtarget
- target element to execute, for example InstanceSpecificationoutputs
- 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
-