public interface IScriptEngine
Thread
and
therefore run separately from other code. An engine shall be started by calling schedule()
.Modifier and Type | Field and Description |
---|---|
static boolean |
TRACE_SCRIPT_ENGINE
Trace enablement for script engines.
|
Modifier and Type | Method and Description |
---|---|
void |
addExecutionListener(IExecutionListener listener) |
void |
addSecurityCheck(ISecurityCheck.ActionType type,
ISecurityCheck check)
Add a dedicated security check for a certain script action.
|
ScriptResult |
executeAsync(Object content)
Execute script code asynchronously.
|
ScriptResult |
executeSync(Object content)
Execute script code synchronously.
|
EngineDescription |
getDescription()
Get engine description for current engine.
|
PrintStream |
getErrorStream() |
Object |
getExecutedFile()
Get the currently executed file instance.
|
InputStream |
getInputStream() |
String |
getName()
Get the engine name.
|
PrintStream |
getOutputStream() |
String |
getSaveVariableName(String name)
Return a save name to be used for a variable.
|
boolean |
getTerminateOnIdle()
Get termination condition when engine is idle.
|
Object |
getVariable(String name)
Get a script variable.
|
Map<String,Object> |
getVariables()
Get all variables from the scope.
|
boolean |
hasVariable(String name)
Check if a variable exists within the scope of the engine.
|
Object |
inject(Object content)
Inject script code and execute synchronously.
|
Object |
injectUI(Object content)
Inject script code and execute synchronously within the UI thread.
|
boolean |
isFinished()
Verify that engine was started and terminated.
|
boolean |
isIdle()
Returns the execution state of the engine.
|
void |
join(long timeout)
Join engine execution thread.
|
void |
registerJar(URL url)
Register a jar file and add it to the classpath.
|
void |
removeExecutionListener(IExecutionListener listener) |
void |
removeSecurityCheck(ISecurityCheck check)
Remove registered security check for all actions.
|
Object |
removeVariable(String name)
Remove a variable from the scope.
|
void |
schedule()
Schedule script execution.
|
void |
setCloseStreamsOnTerminate(boolean closeStreams)
Set marker to automatically close I/O streams when engine is terminated.
|
void |
setEngineDescription(EngineDescription description)
Set engine description for current engine.
|
void |
setErrorStream(OutputStream errorStream)
Set the default error stream for the interpreter.
|
void |
setInputStream(InputStream inputStream)
Set the default input stream for the interpreter.
|
void |
setOutputStream(OutputStream outputStream)
Set the default output stream for the interpreter.
|
void |
setTerminateOnIdle(boolean terminate)
Set a marker that the interpreter should terminate instead entering IDLE mode.
|
void |
setVariable(String name,
Object content)
Set a variable in the script engine.
|
void |
terminate()
Terminate this interpreter.
|
void |
terminateCurrent()
Stops the currently executed piece of code.
|
static final boolean TRACE_SCRIPT_ENGINE
ScriptResult executeAsync(Object content)
Reader
object, or a File
special treatment is done, otherwise the toString() method is used to extract script code.content
- content to be executed.ScriptResult executeSync(Object content) throws InterruptedException
Reader
object, or a File
special treatment is done, otherwise the toString() method is used to extract script code.
In case the engine was not started yet, it will be automatically started by this call. This is a blocking call.content
- content to be executed.InterruptedException
- when execution is interruptedObject inject(Object content)
content
- content to be executed.Object injectUI(Object content)
content
- content to be executed.Object getExecutedFile()
void setOutputStream(OutputStream outputStream)
outputStream
- default output streamvoid setErrorStream(OutputStream errorStream)
errorStream
- default error streamvoid setInputStream(InputStream inputStream)
inputStream
- default input streamPrintStream getOutputStream()
PrintStream getErrorStream()
InputStream getInputStream()
void setCloseStreamsOnTerminate(boolean closeStreams)
closeStreams
- true
to close streamsvoid setTerminateOnIdle(boolean terminate)
terminate
- true
to request terminationboolean getTerminateOnIdle()
true
when engine is terminated when idlevoid schedule()
void terminate()
void terminateCurrent()
void addExecutionListener(IExecutionListener listener)
void removeExecutionListener(IExecutionListener listener)
boolean isIdle()
false
. If the engine is
waiting for further scripts to execute this will return true
.String getName()
void setVariable(String name, Object content)
name
- variable namecontent
- variable contentObject getVariable(String name)
name
- variable namenull
boolean hasVariable(String name)
null
, getVariable(String)
might not be
sufficient to query.name
- variable nametrue
when variable existsString getSaveVariableName(String name)
name
- variable name candidateEngineDescription getDescription()
void setEngineDescription(EngineDescription description)
description
- engine descriptionObject removeVariable(String name)
name
- variable to be removed.Map<String,Object> getVariables()
void registerJar(URL url)
url
- url to load jar file fromvoid join(long timeout) throws InterruptedException
timeout
- command timeout in millisecondsInterruptedException
- when join command got interruptedboolean isFinished()
true
when engine ran and terminatedvoid addSecurityCheck(ISecurityCheck.ActionType type, ISecurityCheck check)
type
- action type to add check forcheck
- check to registervoid removeSecurityCheck(ISecurityCheck check)
check
- check to be removed