Class RubyScript
java.lang.Object
org.tentackle.script.AbstractScript
org.tentackle.script.ruby.RubyScript
- All Implemented Interfaces:
Script
A Ruby script.
The code is compiled lazily on first use into a CompiledRubyScript, shared by all scripts with the
same code if cached. All scripts are executed by the single ScriptingContainer of the
RubyLanguage, which is not thread-safe. Hence, if the script is thread-safe, execution is synchronized
on the container. The variables are reset to nil after each execution.
- Author:
- harald
-
Constructor Summary
ConstructorsConstructorDescriptionRubyScript(RubyLanguage language, org.jruby.embed.ScriptingContainer container, String code, boolean cached, boolean threadSafe) Creates a Ruby script. -
Method Summary
Modifier and TypeMethodDescriptionprotected CompiledRubyScriptcompileScript(String code) Compiles script code.<T> Texecute(Set<ScriptVariable> variables) protected <T> TexecuteImpl(CompiledRubyScript script, Collection<ScriptVariable> variables) Executes the compiled script.
The variables are bound to the container as instance variables and reset tonilafter execution, so that subsequent scripts don't see their values and the objects can be garbage collected (as soon as the next script injects thenil).protected CompiledRubyScriptGets the compiled script.
Will be compiled if not done yet.voidvalidate()Methods inherited from class AbstractScript
execute, getCode, getLanguage, isCached, isThreadSafe, toString
-
Constructor Details
-
RubyScript
public RubyScript(RubyLanguage language, org.jruby.embed.ScriptingContainer container, String code, boolean cached, boolean threadSafe) Creates a Ruby script.- Parameters:
language- the languagecontainer- the scripting containercode- the scripting codecached- true if cachedthreadSafe- true if thread-safety required
-
-
Method Details
-
validate
public void validate() -
execute
-
getCompiledScript
Gets the compiled script.
Will be compiled if not done yet.- Returns:
- the compiled script
-
compileScript
Compiles script code.- Parameters:
code- the scripting source code- Returns:
- the compiled script
- Throws:
ScriptRuntimeException- if compilation failed
-
executeImpl
Executes the compiled script.
The variables are bound to the container as instance variables and reset tonilafter execution, so that subsequent scripts don't see their values and the objects can be garbage collected (as soon as the next script injects thenil).- Type Parameters:
T- the result type- Parameters:
script- the compiled scriptvariables- the variables, null if none- Returns:
- the result converted to Java, null if none
-