Technical Blog Post
Abstract
Maximo Scripting: Script compilation and caching
Body
Script code is written into the Source Code field of the Automation Script application. Alternately, script code can be imported as the Automation Script wizards are used to create new launch point and script. Once the Automation Script wizards are completed or, the Save Script button of the Automation Scripts application is clicked the contents of the field are compiled, cached into memory and, finally, saved to the Maximo database.
Script compilation
At run time, when a script is to be executed, an entity called the interpreter is given the script code. The interpreter loads, evaluates and then executes the script code. If this sequence of tasks is performed every time a script is to be executed, script execution will be very inefficient and business application responsiveness adversely impacted. Instead of adopting this approach, Maximo scripting framework compiles and caches the script. Script compilation results in the script being read, evaluated and compiled into intermediate byte code just once. Once this intermediate byte code is cached, significant time savings result as script execution no longer needs to load and evaluate the script code.
Intermediate byte code
The ability to compile a script depends upon support available in the underlying scripting engine. Maximo ships with the Mozilla Rhino and Jython scripting engines both of which support the compilation of a script into Java byte code. Other scripting engines may not offer the same support.
Script cache
Maximo implements a script cache that loads the Java byte code representation of a script into memory. This cache enables script execution to be more efficient. The script cache is refreshed under these conditions:
- New launch point and script created using Automation Scripts application wizards
- Existing script modified and saved from Automation Scripts application
- Application server start up of Maximo
The script cache adheres to Maximo’s standard caching mechanism and thus, script changes are automatically propagated to all Java Virtual Machine (JVM) instances in a clustered environment.
Script execution
At run time, script execution is triggered by Maximo’s scripting framework using the appropriate script language interpreter. If an error is encountered, statements and traces pertaining to the error are written to the application server console and/or the product log file, if the latter has been configured. Script execution stops upon encountering the first error.
Maximo will always output the script execution time in milliseconds to the application server console and/or the product log file.
UID
ibm11134375