Interface ScriptFactory
- All Known Implementing Classes:
DefaultScriptFactory, JSR223ScriptFactory
The scripting languages are provided by modules such as tentackle-script-groovy and are
referenced by their abbreviations. There is no default language unless set via
setDefaultLanguage(String) (the application sets it from its scripting property,
or if there is exactly one language available).
Replaceable via @Service.
The default implementation is DefaultScriptFactory.
- Author:
- harald
-
Method Summary
Modifier and TypeMethodDescriptioncreateScript(String abbreviation, String code, boolean cached, boolean threadSafe, Function<String, ScriptConverter> converterProvider) Creates a script object.Gets the default language.static ScriptFactoryGets the singleton.getLanguage(String abbreviation) Gets the scripting language.
The abbreviation is case-insensitive.Gets all scripting languages.booleanisLanguageAvailable(String abbreviation) Check if a scripting language is available.voidsetDefaultLanguage(String abbreviation) Sets the default language.voidsetDefaultLanguage(ScriptingLanguage language) Sets the default language.
-
Method Details
-
getInstance
-
setDefaultLanguage
Sets the default language.- Parameters:
abbreviation- the abbreviation for the default language- Throws:
ScriptRuntimeException- if no such language
-
setDefaultLanguage
Sets the default language.- Parameters:
language- the language
-
getDefaultLanguage
ScriptingLanguage getDefaultLanguage()Gets the default language.- Returns:
- the default language, null if none
-
getLanguage
Gets the scripting language.
The abbreviation is case-insensitive.- Parameters:
abbreviation- one of the abbreviations for that language, null or empty string if default language- Returns:
- the language, never null
- Throws:
ScriptRuntimeException- if no such language or no default language
-
isLanguageAvailable
Check if a scripting language is available.- Parameters:
abbreviation- one of the abbreviations for that language, null or empty string if default language- Returns:
- true if the scripting language is available
-
getLanguages
-
createScript
Script createScript(String abbreviation, String code, boolean cached, boolean threadSafe, Function<String, ScriptConverter> converterProvider) Creates a script object.Scripts will be cached to optimize memory consumption and performance, if
cached=true. The same source code will refer to the same compiled evaluation unit. The implementation may still return a newScriptinstance if caching not supported by the language or the caching refers to class instances instead of objects. Caching should not be used for scripts that are executed only once.If there are chances that scripts are invoked from different threads at a time, all scripts must be executed in a thread-safe manner. Although some languages are thread-safe by design, others may need some extra synchronization. If in doubt, set
threadSafetotrue.An optional function provides a
ScriptConverterfor the given scripting language to translate the code before being compiled.Notice that the script will be compiled when first used. To compile it without execution, invoke
Script.validate().- Parameters:
abbreviation- the scripting language abbreviation, null or empty for default languagecode- the scripting codecached- the same code should refer to the same compiled script objectthreadSafe- true if script may be used by more than one thread in parallelconverterProvider- the optional script converter provider- Returns:
- the script, never null
- Throws:
ScriptRuntimeException- if creating the script failed, for example due to an unknown language
-