E
- Template class's type of the result.@PublicAPI public abstract class Script<E> extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
static String |
ARGUMENTS_NAME
Variable name for script arguments
|
static int |
DEFAULT_OUTPUT_MAX_SIZE |
protected String |
id
Id of this script
|
static org.apache.log4j.Logger |
logger
Loggers
|
static String |
MD5 |
protected Serializable[] |
parameters
The parameters of the script
|
protected String |
script
The script to evaluate
|
protected String |
scriptEngineLookupName
Name of the script engine or file path to script file (extension will be used to lookup)
|
protected URL |
url
url used to define this script, if aaplicable
|
Constructor and Description |
---|
Script()
ProActive needed constructor
|
Script(File file)
Create a script from a file.
|
Script(File file,
Serializable[] parameters)
Create a script from a file.
|
Script(Script<?> script2)
Create a script from another script object
|
Script(Script<?> script2,
String scriptName)
Create a script from another script object
|
Script(String script,
String engineName)
Directly create a script with a string.
|
Script(String script,
String engineName,
Serializable[] parameters)
Directly create a script with a string.
|
Script(String script,
String engineName,
Serializable[] parameters,
String scriptName)
Directly create a script with a string.
|
Script(String script,
String engineName,
String scriptName)
Directly create a script with a string.
|
Script(URL url,
boolean fetchImmediately)
Create a script from an URL.
|
Script(URL url,
Serializable[] parameters,
boolean fetchImmediately)
Create a script from an URL.
|
Script(URL url,
String engineName,
boolean fetchImmediately)
Create a script from an URL.
|
Script(URL url,
String engineName,
Serializable[] parameters,
boolean fetchImmediately)
Create a script from an URL.
|
Modifier and Type | Method and Description |
---|---|
protected ScriptEngine |
createScriptEngine()
The Script Engine used to evaluate the script.
|
static String |
digest(String script)
Get MD5 hash value of the script without parameters
|
String |
display() |
boolean |
equals(Object obj) |
ScriptResult<E> |
execute()
Execute the script and return the ScriptResult corresponding.
|
ScriptResult<E> |
execute(Map<String,Object> aBindings,
PrintStream outputSink,
PrintStream errorSink)
Execute the script and return the ScriptResult corresponding.
|
String |
fetchScript()
If the script is defined by an url, in fetchImmediately=false mode, retrieve and return the script content from the url.
|
String |
fetchScriptWithExceptionHandling()
If the script is defined by an url, in fetchImmediately=false mode, retrieve and return the script content from the url.
|
void |
fetchUrlIfNeeded() |
protected abstract String |
getDefaultScriptName() |
String |
getEngineName() |
String |
getId()
String identifying the script.
|
String |
getOwner() |
Serializable[] |
getParameters()
Get the parameters.
|
protected Reader |
getReader()
The reader used to read the script.
|
protected abstract ScriptResult<E> |
getResult(Object evalResult,
Bindings bindings)
Return the variable awaited from the script execution
|
String |
getScript()
Get the script.
|
String |
getScriptName()
Get the script name.
|
URL |
getScriptUrl()
Get the script url, if applicable
|
String |
getSessionid() |
int |
hashCode() |
protected static boolean |
isLazyFetch() |
void |
overrideDefaultScriptName(String defaultScriptName) |
protected void |
prepareBindings(Bindings bindings)
Set parameters in bindings if any
|
protected abstract void |
prepareSpecialBindings(Bindings bindings)
Specify the variable awaited from the script execution
|
static String |
readFile(File file)
Create string script from file
|
void |
setOwner(String owner) |
void |
setScript(String script)
Set the script content, ie the executed code
|
void |
setSessionid(String sessionid) |
String |
toString() |
public static final int DEFAULT_OUTPUT_MAX_SIZE
public static final org.apache.log4j.Logger logger
public static final String ARGUMENTS_NAME
public static final String MD5
protected String scriptEngineLookupName
protected String script
protected URL url
protected String id
protected Serializable[] parameters
public Script()
public Script(String script, String engineName, Serializable[] parameters)
script
- String representing the script's source codeengineName
- String representing the execution engineparameters
- script's execution arguments.public Script(String script, String engineName, Serializable[] parameters, String scriptName)
script
- String representing the script's source codeengineName
- String representing the execution engineparameters
- script's execution arguments.scriptName
- name of the scriptpublic Script(String script, String engineName)
script
- String representing the script's source codeengineName
- String representing the execution enginepublic Script(String script, String engineName, String scriptName)
script
- String representing the script's source codeengineName
- String representing the execution enginescriptName
- name of the scriptpublic Script(File file, Serializable[] parameters) throws InvalidScriptException
file
- a file containing the script's source code.parameters
- script's execution arguments.InvalidScriptException
- if the creation fails.public Script(File file) throws InvalidScriptException
file
- a file containing a script's source code.InvalidScriptException
- if Constructor fails.public Script(URL url, Serializable[] parameters, boolean fetchImmediately) throws InvalidScriptException
url
- representing a script source code.parameters
- execution arguments.fetchImmediately
- true if the script at the given url must be fetched when the job is parsed by the server, false if the script must be fetch only at execution time.InvalidScriptException
- if the creation fails.public Script(URL url, String engineName, Serializable[] parameters, boolean fetchImmediately) throws InvalidScriptException
url
- representing a script source code.engineName
- String representing the execution engineparameters
- execution arguments.fetchImmediately
- true if the script at the given url must be fetched when the job is parsed by the server, false if the script must be fetch only at execution time.InvalidScriptException
- if the creation fails.public Script(URL url, boolean fetchImmediately) throws InvalidScriptException
url
- representing a script source code.fetchImmediately
- true if the script at the given url must be fetched when the job is parsed by the server, false if the script must be fetch only at execution time.InvalidScriptException
- if the creation fails.public Script(URL url, String engineName, boolean fetchImmediately) throws InvalidScriptException
url
- representing a script source code.engineName
- String representing the execution enginefetchImmediately
- true if the script at the given url must be fetched when the job is parsed by the server, false if the script must be fetch only at execution time.InvalidScriptException
- if the creation fails.public Script(Script<?> script2)
script2
- script object sourceprotected abstract String getDefaultScriptName()
public String getSessionid()
public void setSessionid(String sessionid)
public String getOwner()
public void setOwner(String owner)
protected static boolean isLazyFetch()
public String getScript()
public String fetchScript()
public String fetchScriptWithExceptionHandling() throws IOException
IOException
- when the script cannot be accessedpublic String getScriptName()
public URL getScriptUrl()
public void setScript(String script)
script
- the new script contentpublic Serializable[] getParameters()
public ScriptResult<E> execute()
System.out
for output.public ScriptResult<E> execute(Map<String,Object> aBindings, PrintStream outputSink, PrintStream errorSink)
aBindings
- the additional user bindings to add if needed. Can be null or empty.outputSink
- where the script output is printed to.errorSink
- where the script error stream is printed to.public void fetchUrlIfNeeded() throws IOException
IOException
public String getId()
protected Reader getReader()
protected ScriptEngine createScriptEngine()
protected abstract void prepareSpecialBindings(Bindings bindings)
bindings
- protected abstract ScriptResult<E> getResult(Object evalResult, Bindings bindings)
protected final void prepareBindings(Bindings bindings)
public static String readFile(File file) throws IOException
IOException
public String getEngineName()
public static String digest(String script)
public String display()
public void overrideDefaultScriptName(String defaultScriptName)