Class ScriptingEnvironment
java.lang.Object
org.camunda.bpm.engine.impl.scripting.env.ScriptingEnvironment
The scripting environment contains scripts that provide an environment to a user provided script. The environment may contain additional libraries or imports.
The environment performs lazy initialization of scripts: the first time a script of a given
script language is executed, the environment will use the ScriptEnvResolvers
for resolving the environment scripts for that language. The scripts (if any) are then pre-compiled
and cached for reuse.
- Author:
- Daniel Meyer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map<String,List<ExecutableScript>> the cached environment scripts per script languageprotected List<ScriptEnvResolver>the resolversprotected ScriptFactorythe script factory used for compiling env scriptsprotected ScriptingEnginesthe scripting engines -
Constructor Summary
ConstructorsConstructorDescriptionScriptingEnvironment(ScriptFactory scriptFactory, List<ScriptEnvResolver> scriptEnvResolvers, ScriptingEngines scriptingEngines) -
Method Summary
Modifier and TypeMethodDescriptionprotected BindingscreateBindings(ExecutableScript script, ScriptEngine scriptEngine, VariableScope scope) Creates the bindingsscriptis evaluated against.execute(ExecutableScript script, VariableScope scope) execute a given script in the environmentexecute(ExecutableScript script, VariableScope scope, Bindings bindings, ScriptEngine scriptEngine) protected Map<String,List<ExecutableScript>> protected List<ExecutableScript>getEnvScripts(String scriptLanguage) Returns the env scripts for the given language.protected List<ExecutableScript>getEnvScripts(ExecutableScript script, ScriptEngine scriptEngine) protected Map<String,List<ExecutableScript>> protected List<ExecutableScript>initEnvForLanguage(String language) Initializes the env scripts for a given language.protected booleanisEngineRetained(ScriptEngine scriptEngine, ExecutableScript script) protected booleanisEngineRetainedBy(ScriptEngine scriptEngine, ExecutableScript script) protected booleanisEngineRetainedFailSafe(ScriptEngine scriptEngine, ExecutableScript script) WrapsisEngineRetained(javax.script.ScriptEngine, org.camunda.bpm.engine.impl.scripting.ExecutableScript)so a failure while determining retention (e.g.
-
Field Details
-
env
the cached environment scripts per script language -
envResolvers
the resolvers -
scriptFactory
the script factory used for compiling env scripts -
scriptingEngines
the scripting engines
-
-
Constructor Details
-
ScriptingEnvironment
public ScriptingEnvironment(ScriptFactory scriptFactory, List<ScriptEnvResolver> scriptEnvResolvers, ScriptingEngines scriptingEngines)
-
-
Method Details
-
execute
execute a given script in the environment- Parameters:
script- theExecutableScriptto executescope- the scope in which to execute the script- Returns:
- the result of the script evaluation
-
createBindings
protected Bindings createBindings(ExecutableScript script, ScriptEngine scriptEngine, VariableScope scope) Creates the bindingsscriptis evaluated against. For GraalJS this reads the process variables and starts the polyglotContext, which GraalJS used to do while evaluating the script - whereExecutableScriptturns every failure into aScriptEvaluationException(and lets aBpmnErrorpass). A failure here is reported the same way. -
isEngineRetainedFailSafe
WrapsisEngineRetained(javax.script.ScriptEngine, org.camunda.bpm.engine.impl.scripting.ExecutableScript)so a failure while determining retention (e.g. env script resolution hitting an unavailable process application - seegetPaEnvScripts(org.camunda.bpm.application.ProcessApplicationReference)) can never propagate out of thefinallyblock inexecute(ExecutableScript, VariableScope), where it would mask the try block's real result/exception and skip disposal entirely. On failure, conservatively treats the engine as retained: leaving oneScriptEngineopen a little longer is preferable to risking closing one a cachedCompiledScriptstill depends on - see issue #3174. -
isEngineRetained
-
isEngineRetainedBy
-
execute
public Object execute(ExecutableScript script, VariableScope scope, Bindings bindings, ScriptEngine scriptEngine) -
getEnv
-
getPaEnvScripts
-
getEnvScripts
-
getEnvScripts
Returns the env scripts for the given language. Performs lazy initialization of the env scripts.- Parameters:
scriptLanguage- the language- Returns:
- a list of executable environment scripts. Never null.
-
initEnvForLanguage
Initializes the env scripts for a given language.- Parameters:
language- the language- Returns:
- the list of env scripts. Never null.
-