Package jline.solvers.wrappers.jmt
Class JmtBackend
java.lang.Object
jline.solvers.wrappers.jmt.JmtBackend
Backend dispatch for the JMT command line.
One analysis of jmt.commandline.Jmt is run on a model file and the result is
left where the JMT CLI itself would leave it, that is at
<model>-result.jsim for mode "sim" and <model>-result.jmva for mode
"mva". Every backend satisfies that contract, so the result parsers do not
know or care which one ran.
Backend selection, in order:
- options.restUrl non-empty: POST to a JMT REST server (the imperialqore/jmt-rest container). Nothing is executed locally.
- a local JVM plus common/JMT.jar: the default, unchanged.
- no local JVM, but Docker is usable: ask once per session whether to pull and use the JMT image, and dispatch through it.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String[]Docker images tried, in order, when none is named by the options.static final longGrace, in seconds, a JMT subprocess may overrun the remaining budget before it is killed. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanhasJava()Reports whether a JVM is on the path.static RuntimeExceptionkilledError(String mode) The error a budget kill raises: the subprocess wrote no result to return.static longHard bound on a JMT subprocess: the remaining budget plusHARD_GRACE_SECONDS, or 0 (no bound) when no budget is armed.static StringlocalCommand(String jmtPath, String mode, String modelPath, int seed) Builds the shell command that runs one JMT analysis locally.static longmaxTimeSeconds(String mode) The remaining armed wall-clock budget for a JSIM run, in whole seconds rounded UP (JMT parses an integer), or -1 when no budget is armed or the mode is JMVA, which has no such switch.static StringprivateTmpDirFlag(String modelPath) The -Djava.io.tmpdir switch that keeps one run's JMT scratch private.static StringresolveDockerImage(SolverOptions options) Resolves the JMT Docker image to dispatch through, with user consent.static StringresultPath(String modelPath, String mode) Returns the path JMT writes its result to for this model and mode.static booleanrunRemote(String mode, String modelPath, int seed, SolverOptions options) Runs one JMT analysis through the backend the options select, when that backend is not the local JVM.
-
Field Details
-
DEFAULT_IMAGES
Docker images tried, in order, when none is named by the options. -
HARD_GRACE_SECONDS
public static final long HARD_GRACE_SECONDSGrace, in seconds, a JMT subprocess may overrun the remaining budget before it is killed.- See Also:
-
-
Method Details
-
resultPath
Returns the path JMT writes its result to for this model and mode.- Parameters:
modelPath- path of the model file handed to JMTmode- "sim" or "mva"- Returns:
- the result path
-
hasJava
public static boolean hasJava()Reports whether a JVM is on the path. Probed once per session: the check costs a process launch, and a JVM does not appear or vanish mid-session.- Returns:
- true if "java -version" runs and exits zero
-
localCommand
Builds the shell command that runs one JMT analysis locally.- Parameters:
jmtPath- path of JMT.jarmode- "sim" or "mva"modelPath- path of the model fileseed- simulation seed, ignored by the JMVA engine- Returns:
- the command line, as passed to SysUtils.system
-
maxTimeSeconds
The remaining armed wall-clock budget for a JSIM run, in whole seconds rounded UP (JMT parses an integer), or -1 when no budget is armed or the mode is JMVA, which has no such switch. JSIM aborts every measure at that time and still writes its result file, so the run returns interim estimates. -
killSeconds
public static long killSeconds()Hard bound on a JMT subprocess: the remaining budget plusHARD_GRACE_SECONDS, or 0 (no bound) when no budget is armed. -
killedError
The error a budget kill raises: the subprocess wrote no result to return. -
privateTmpDirFlag
The -Djava.io.tmpdir switch that keeps one run's JMT scratch private. NOT A TIDINESS MEASURE: without it two JMT runs on one host corrupt each other. jmt.commandline.Jmt hands the engine a copy of the model under java.io.tmpdir, and XMLSimulationOutput.writeAllMeasures then writes the measures to <that dir>/res_sim_<the sim's name attribute>, copies that file to <model>-result.jsim and DELETES it. Every LINE-written model carries the same name attribute, "model.jsim" from getJSIMTempPath and its MATLAB/python/C++ twins, so with a shared /tmp every concurrent run fights over one path, /tmp/res_sim_model.jsim. Two outcomes: the other run deletes the file first and this one dies in jmt.commandline.Jmt.copyFile, or it copies the OTHER run's measures and reports another model's numbers as its own. The model already sits in a directory of its own, so pointing the JVM's temp dir at it makes every scratch file this run creates private to it.- Parameters:
modelPath- path of the model file JMT is to read- Returns:
- the quoted -Djava.io.tmpdir switch
-
runRemote
Runs one JMT analysis through the backend the options select, when that backend is not the local JVM.- Parameters:
mode- "sim" or "mva"modelPath- path of the model fileseed- simulation seed, ignored by the JMVA engineoptions- solver options, read for restUrl and container- Returns:
- true if a non-local backend ran the analysis and wrote its result file; false if the caller should run the local command
- Throws:
RuntimeException- if no backend can run JMT, or a remote one failed
-
resolveDockerImage
Resolves the JMT Docker image to dispatch through, with user consent. The decision is remembered for the session: a sweep over many models must not ask once per model.- Parameters:
options- solver options, read for the container override- Returns:
- the image name, or null when Docker is unusable, no image can be obtained, or the user declines
-