Package org.jppf.node.protocol
Class ScriptedTask<T>
java.lang.Object
org.jppf.node.protocol.AbstractTask<T>
org.jppf.node.protocol.ScriptedTask<T>
- Type Parameters:
T- the type of result returned by this task.
- All Implemented Interfaces:
Serializable,Runnable,Interruptibility,PositionalElement<Task<T>>,Task<T>
A task implementation which executes a script in a specified JSR 223 (
javax.script APIs) script language.
In addition to the user-specified bindings, this task always provides to the script engine a reference to itself with the name 'jppfTask'.
A reusableId can be specified via the constructors, indicating that, if the script engine has that capability, compiled scripts will be stored and reused, to avoid compiling the same scripts repeatedly.
- Author:
- Laurent Cohen
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ScriptDefinitionSpecfications for the script to execute. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor provided as a convenience for subclassing.Initialize this task with the specified script language, script provided as a file, and a set of variable bindings to be used in the scripts.Initialize this task with the specified script language, script provided from aReader, and a set of variable bindings to be used in the scripts.Initialize this task with the specified script language, script provided as a string, and a set of variable bindings to be used in the scripts. -
Method Summary
Modifier and TypeMethodDescriptionaddBinding(String name, Object value) Add the specified variable to the user-defined bindings.Get the user-defined variable bindings.Get the JSR 223 script language to use.Get the unique identifier for the script.Get the script to execute from this task.removeBinding(String name) Remove the specified variable from the user-defined bindings.voidrun()Methods inherited from class org.jppf.node.protocol.AbstractTask
compute, fireNotification, getDataProvider, getId, getJob, getMaxResubmits, getNode, getPosition, getResult, getTaskClassLoader, getTaskObject, getThrowable, getTimeoutSchedule, isInNode, isInterruptible, isResubmit, onCancel, onTimeout, setDataProvider, setExecutionDispatcher, setId, setInNode, setJob, setMaxResubmits, setNode, setPosition, setResubmit, setResult, setThrowable, setTimeoutSchedule
-
Field Details
-
scriptSpec
Specfications for the script to execute.
-
-
Constructor Details
-
ScriptedTask
protected ScriptedTask()Default constructor provided as a convenience for subclassing. -
ScriptedTask
public ScriptedTask(String language, String script, String reusableId, Map<String, Object> bindings) throws IllegalArgumentExceptionInitialize this task with the specified script language, script provided as a string, and a set of variable bindings to be used in the scripts.- Parameters:
language- the JSR 223 script language to use.script- the script to execute from this task.reusableId- a unique identifier for the script, which allows reusing a compiled version if one has already been produced.bindings- a set of variables that will be available to the script.- Throws:
IllegalArgumentException- iflanguageorscriptisnull.
-
ScriptedTask
public ScriptedTask(String language, Reader scriptReader, String reusableId, Map<String, Object> bindings) throws IllegalArgumentException, IOExceptionInitialize this task with the specified script language, script provided from aReader, and a set of variable bindings to be used in the scripts.- Parameters:
language- the JSR 223 script language to use.scriptReader- a reader form which to read the script source.reusableId- a unique identifier for the script, which allows reusing a compiled version if one has already been produced.bindings- a set of variables that will be available to the script.- Throws:
IllegalArgumentException- iflanguageorscriptisnull.IOException- if an I/O error occurs while reading the script source.
-
ScriptedTask
public ScriptedTask(String language, File scriptFile, String reusableId, Map<String, Object> bindings) throws IllegalArgumentException, IOExceptionInitialize this task with the specified script language, script provided as a file, and a set of variable bindings to be used in the scripts.- Parameters:
language- the JSR 223 script language to use.scriptFile- a file from which to read the script source.reusableId- a unique identifier for the script, which allows reusing a compiled version if one has already been produced.bindings- a set of variables that will be available to the script.- Throws:
IllegalArgumentException- iflanguageorscriptisnull.IOException- if an I/O error occurs while reading the script source.
-
-
Method Details
-
run
public void run()- Specified by:
runin interfaceRunnable- Overrides:
runin classAbstractTask<T>
-
getLanguage
Get the JSR 223 script language to use.- Returns:
- the script language a s a script.
-
getScript
Get the script to execute from this task.- Returns:
- the script source as a string.
-
getReusableId
Get the unique identifier for the script.- Returns:
- the identifier as a string.
-
getBindings
Get the user-defined variable bindings.- Returns:
- a map of variable names to their value.
-
addBinding
Add the specified variable to the user-defined bindings.- Parameters:
name- the name of the variable binding to add.value- the value of the variable.- Returns:
- this task, for method chaining.
-
removeBinding
Remove the specified variable from the user-defined bindings.- Parameters:
name- the name of the variable binding to remove.- Returns:
- the value of the variable, or
nullif the variable was not bound.
-