Limitations
Topics covered in this chapter:
Primitive value types
Mosel can only directly understand a subset of the primitive Java data-types (boolean, int, double) and their direct Mosel equivalents (boolean, integer, real). When passing other primitive values, they must be wrapped in a jvmobject. For example, to pass a timestamp to the java.util.Date constructor as a long:
declarations ts, dt: jvmobject end-declarations ts.longvalue := 1648490312000.0 dt := jvmnewobj('java.util.Date',ts)
Similarly, to call a method that returns an unsupported primtive type, you can use jvmcallobj and then extract the primitive value from the jvmobject; for example, the method java.lang.System.currentTimeMillis() returns a long, and can be called as follows:
declarations ticks: jvmobject end-declarations ticks := jvmcallobj('java.lang.System.currentTimeMillis') writeln('currentTimeMillis: ', ticks.longvalue)
Limited complex return types
Mosel can only directly understand the primitive Java data-types and strings. Although your method can return any Java class into a 'jvmobject' variable, the main operations you can do with the object are turning it into the corresponding basic Mosel types or using it in calls to other Java methods.
If you need to return a large data-set then your options would be to format it in some standard format (e.g. CSV, XML, JSON), and return it as 'text' then use Mosel's standard modules to parse it, or to write it to a file that can be read later by the Mosel model.
Arguments passed by value
Method arguments are input-only—so when you make changes to an array from within a Java function, this does not affect the array in the Mosel model. Similarly when you pass a Mosel text object, it becomes a Java String and cannot be modified from Java.
Standard output streams
If you send output to the Java stream System.out within a Java method called through mosjvm, the output will be sent to the Mosel model's standard output stream. However, if the Java virtual machine generates output from a different thread, this will not be captured by any Mosel stream.
Similarly, output you send to System.err will go to the the Mosel model's error stream. If another thread generates output to System.err, it will be sent to the Mosel instance's error stream.
Working directories
The initial working directory of the Java virtual machine will be the working directory of the Mosel process; this may be different from the working directories of the Mosel models (controlled by the workdir parameter). When passing filenames between the Mosel and Java environments, it is recommended to always use absolute paths.
JVM shut down
In normal usage, once the Java virtual machine has started up, it will not be shut down until the Mosel process exits.
Incompatible with com.dashoptimization.XPRM
If you are calling Mosel using the Mosel Java Library classes in the com.dashoptimization package, you cannot use the mosjvm module.
Incompatible with other JVMs
The mosjvm module can only interact with a Java virtual machine that it itself has started. If there is already a Java virtual machine running in the Mosel process, attempting to use the mosjvm module will result in an error.
Supported Java versions
The mosjvm module is only supported with Java 8, 11 and 17. Only the Oracle, OpenJDK and Amazon Corretto distributions of Java are supported. The mosjvm module is not supported with other versions or distributions of Java.
Not supported on Solaris
The mosjvm module is not available in the Sun Solaris versions of Xpress.
System.exit may not be called
Calling System.exit from the JVM started by mosjvm will not work; an exception will be thrown.
© 2001-2024 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.