VnanoEngine Class Specification
(org.vcssl.nano.VnanoEngine)


Abstract

The class of the scripting engine of the Vnano (Vnano Engine).

List of Public Constructors/Fields/Methods

VnanoEngine()
Create a Vnano Engine with default settings.
Object executeScript(String script)
Executes an expression or script code specified as the argument.
void terminateScript()
Terminates the currently running script as soon as possible.
boolean isTerminatorEnabled()
Returns whether the "terminator" which is the feature to terminate scripts, is enabled.
void resetTerminator()
Resets the engine which had terminated by terminateScript() method, for processing new scripts.
void connectPlugin(String bindingName, Object plugin)
Connects various types of plug-ins which provides external functions/variables.
void disconnectAllPlugins()
Disconnects all plug-ins.
void includeLibraryScript(String libraryScriptName, String libraryScriptContent)
Add a library script which will be "include"-ed at the head of a executed script.
void unincludeAllLibraryScripts()
Uninclude all library scripts.
void setOptionMap(Map<String,Object> optionMap)
Sets options, by a Map (option map) storing names and values of options you want to set.
boolean hasOptionMap()
Returns whether getOptionMap() method can return a Map.
Map<String,Object> getOptionMap()
Gets the Map (option map) storing names and values of options.
void setPermissionMap(Map<String,String> permissionMap)
Sets permissions, by a Map (permission map) storing names and values of permission items you want to set.
boolean hasPermissionMap()
Returns whether getPermissionMap() method can return a Map.
Map<String,String> getPermissionMap()
Gets the Map (permission map) storing names and values of permission items.
boolean hasPerformanceMap()
Returns whether gePerformanceMap() method can return a Map.
Map<String,Object> getPerformanceMap()
Gets the Map (performance map) storing names and values of performance monitoring items.

Public Constructors

Name VnanoEngine
Signature VnanoEngine()
Description Create a Vnano Engine with default settings.
Parameters None
Return The created instance of the VnanoEngine class.

Public Fields

- None -

Public Methods

Name executeScript
Signature Object executeScript(String script) throws VnanoException
Description

Executes an expression or script code specified as the argument.

Please note that, you must not call this method of the same instance at the same time from multiple threads, for processing multiple scripts in parallel. For such parallel executions, create an independent instance of the engine for each thread and use them.

Parameters script: An expression or script code to be executed.
Return The evaluated value of the expression, or the last expression statement in script code. If there is no evaluated value, returns null.
Exception VnanoException: Thrown when any error has detected for the content or the processing of the script.
Name terminateScript
Signature void terminateScript()
Description

Requests this engine to terminate the currently running script as soon as possible.

To be precise, the VM in the scripting engine will be terminated after when the processing of a currently executed instruction has been completed, without processing remained instructions.

Also, if you used this method, call resetTerminator() method before the next execution of a new script, otherwise the next execution will end immediately without processing any instructions.

By the above behavior, even if a termination request by this method and an execution request by another thread are conflict, the execution will be terminated certainly (unless resetTerminator() will be called before when the execution will have been terminated).

Parameters None
Return None
Exception

VnanoFatalException (Unchecked Exception): Thrown if this method is called in a state in which isTerminatorEnabled() returns false.

Note that, if any exceptions occurred on the finalization processes of the connected plug-ins, it will be throws by the currently running executeScript(String script) method, not by this method. This method throws the exception only when it failed requesting the termination.

Name isTerminatorEnabled
Signature boolean isTerminatorEnabled()
Description

Returns whether the "terminator" which is the feature to terminate scripts, is enabled.

Internally, this method checks the value of "TERMINATOR_ENABLED" option (disabled by default) and returns it.

If this method returns true, terminateScript() method and resetTerminator() method are available.

Please note that, even when this method returns true, some errors may occur in the termination processes (for example, erros caused by failures of finalization processes of the connected plug-ins, and so on). For details, see the explanation about exceptions, in the description of terminateScript() method.

Parameters None
Return None
Exception None
Name resetTerminator
Signature void resetTerminator()
Description

Resets the engine which had terminated by terminateScript() method, for processing new scripts.

Please note that, if an execution of code is requested by another thread when this method is being processed, the execution request might be missed.

Parameters None
Return None
Exception VnanoFatalException (Unchecked Exception): Thrown if this method is called in a state in which isTerminatorEnabled() returns false.
Name connectPlugin
Signature void connectPlugin(String bindingName, Object plugin) throws VnanoException
Description

Connects various types of plug-ins which provides external functions/variables.

For the parameter "bindingName", specify the name in scripts of the variable/function/namespace provided by the connected plug-in. If the passed argument contains a white space or a character "(", the content after it will be ignored. By the above specification, for a function plug-in, you can specify a signature containing parameter-declarations like "foo(int,float)" (note that, syntax or correctness of parameter-declarations will not be checked). In addition, for plug-ins providing elements belonging to the same namespace "Bar", you can specify "Bar 1", "Bar 2", and so on. Also, you can specify "___VNANO_AUTO_KEY" for using a valid value generated automatically.

For the parameter "plugin", specify the plug-in to be connected. General "Object" type instances can be connected as a plug-in, for accessing their methods/fields from the script code as external functions/variables. For accessing only static methods and fields, "Class<T>" type instance can also be connected. In addition, if you want to choose a method/field to be accessible from script code, a "Method"/"Field" type instance can be connected. ( In that case, if the method/field is static, pass an Object type array for this argument, and store the Method/Field type instance at [0], and store "Class<T>" type instance of the class defining the method/field at [1] ). Furthermore, an instance of a class implementing less-overhead plug-in interfaces, e.g.: XFCI, can be connected by this method. Also, this method is used for connecting PACI1 type plug-ins which is used for managing permissions.

Parameters bindingName: The name in scripts of the variable/function/namespace provided by the connected plug-in.
plugin: The plug-in to be connected.
Return None
Exception VnanoException: Thrown if the plug-in could not be connected, caused by unsupported interfaces, incompatibility of data types, and so on.
Name disconnectAllPlugins
Signature void disconnectAllPlugins() throws VnanoException
Description Disconnects all plug-ins.
Parameters None
Return None
Exception VnanoException: Thrown when an exception occurred on the finalization of the plug-in to be disconnected.
Name includeLibraryScript
Signature void includeLibraryScript(String libraryScriptName, String libraryScriptContent) throws VnanoException
Description Add a library script which will be "include"-ed at the head of a executed script.
Parameters libraryScriptName: Names of the library script (displayed in error messages).
libraryScriptContent: Content (code) of the library script.
Return None
Exception VnanoException: Thrown when incorrect somethings have been detected for the specified library.
Name unincludeAllLibraryScripts
Signature void unincludeAllLibraryScripts() throws VnanoException
Description Uninclude all library scripts.
Parameters None
Return None
Exception VnanoException: Thrown when incorrect somethings have been detected for the specified library.
Name setOptionMap
Signature void setOptionMap(Map<String,Object> optionMap) throws VnanoException
Description

Sets options, by a Map (option map) storing names and values of options you want to set.

Type of the option map is Map, and its keys represents option names. For details, see the document of options.

Please note that, if any value stored in the option map is changed after setting the map by this method, it is NOT guaranteed that the engine reflects the change. Hence, when any value is changed, re-set the option map again by this method.

Parameters optionMap: The Map (option map) storing names and values of options.
Return None
Exception VnanoException: Thrown if invalid option settings is detected.
Name hasOptionMap
Signature boolean hasOptionMap()
Description Returns whether getOptionMap() method can return a Map.
Parameters None
Return Returns true if getOptionMap() method can return a Map.
Exception None
Name getOptionMap
Signature Map<String,Object> getOptionMap()
Description

Gets the Map (option map) storing names and values of options

Type of the option map is Map, and its keys represents option names. For details, see the document of options.

Parameters None
Return The Map (option map) storing names and values of options.
Exception VnanoFatalException (Unchecked Exception): Thrown if this method is called in a state in which hasOptionMap() returns false.
Name setPermissionMap
Signature void setPermissionMap(Map<String,String> permissionMap) throws VnanoException
Description

Sets permissions, by a Map (permission map) storing names and values of permission items you want to set.

Type of the permission map is Map<String,String>, and its keys represents names of permission items. For details, see the document of permission items.

Please note that, if any value stored in the permission map is changed after setting the map by this method, it is NOT guaranteed that the engine reflects the change. Hence, when any value is changed, re-set the permission map again by this method.

Parameters permissionMap: The Map (permission map) storing names and values of permission items.
Return None
Exception VnanoException: Thrown if invalid permission settings is detected.
Name hasPermissionMap
Signature boolean hasPermissionMap()
Description Returns whether getPermissionMap() method can return a Map.
Parameters None
Return Returns true if getPermissionMap() method can return a Map.
Exception None
Name getPermissionMap
Signature Map<String,String> getPermissionMap()
Description

Gets the Map (permission map) storing names and values of permission items.

Type of the permission map is Map, and its keys represents names of permission items. For details, see the document of permissions.

Parameters None
Return The Map (permission map) storing names and values of permission items.
Exception VnanoFatalException (Unchecked Exception): Thrown if this method is called in a state in which hasPermissionMap() returns false.
Name hasPerformanceMap
Signature boolean hasPerformanceMap()
Description

Returns whether getPerformanceMap() method can return a Map.

Internally, this method checks the value of "PERFORMANCE_MONITOR_ENABLED" option (disabled by default) and returns it.

Parameters None
Return Returns true if getPerformanceMap() method can return a Map.
Exception None
Name getPerformanceMap
Signature Map<String,Object> getPerformanceMap() throws VnanoException
Description

Gets the Map (performance map) storing names and values of performance monitoring items.

Note that, when some measured values for some monitoring items don't exist (e.g.: when any scripts are not running, or running but their performance values are not measualable yet), the returned performance map does not contain values for such monitoring items, so sometimes the returned performance map is incomplete (missing values for some items) or empty. Please be careful of the above point when you "get" measured performance values from the returned performance map.

Parameters None
Return The Map (performance map) storing names and values of performance monitoring items.
Exception VnanoFatalException (Unchecked Exception): Thrown if this method is called in a state in which hasPerformanceMap() returns false.