public interface IScriptEngine
Thread
and
therefore run separately from other code. An engine shall be started by calling schedule()
.Modifier and Type | Method and Description |
---|---|
void |
addExecutionListener(IExecutionListener listener) |
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 |
isIdle()
Returns the execution state of the engine.
|
void |
registerJar(URL url)
Register a jar file and add it to the classpath.
|
void |
removeExecutionListener(IExecutionListener listener) |
Object |
removeVariable(String name)
Remove a variable from the scope.
|
void |
reset()
Resets the script engine to a fresh state (removes all variables and code history).
|
void |
schedule()
Schedule script execution.
|
void |
setCloseStreamsOnTerminate(boolean closeStreams)
Set marker to automatically close I/O streams when engine is terminated.
|
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.
|
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.
The calling thread is stalled until the script code is processed.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)
void reset()
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()
Object removeVariable(String name)
name
- variable to be removed.Map<String,Object> getVariables()
void registerJar(URL url)
url
- url to load jar file from