NetKernel Scripting Framework
The NetKernel Scripting Framework (NSF) enables, manages and optimizes the execution of scripting languages
in NetKernel. Currently Javascript, Groovy, Python and Beanshell (aka scripted Java) languages are provided.
This guide provides a detailed discussion of the NSF and highlights important features relating to the
supported languages.
Architecture
The NSF is an accessor (org.ten60.netkernel.script.accessor.ScriptEngineNKFAccessor)
which manages and executes scripts. The ScriptEngine services requests for the following languages...
The script engine expects to receive an operator active URI argument with the script to be executed.
When a newly requested script execution is received the ScriptEngine sources the script and, using the underlying scripting language implementation,
generates a compiled and cacheable representation. The compiled script is then executed. Any subsequent request for the script will
automatically retrieve the cached pre-compiled script which will execute without the overhead of parsing and/or interpreting. Netkernel's
dependency-based caching means that scripts are automatically recompiled if edited.
The ScriptEngine runs on the NetKernel Foundation API
every script execution is provided with an
INKFConvenienceHelper
, which in the script is
called the context object. The context object is used to obtain resources from the initiating request, to schedule new requests
with the kernel and finally to issue a response - to understand what is provided to a script by the context object read the
NetKernel Foundation
API guide.
It is valid to think of a script execution in the Script Engine as simply equivalent to an accessor - that is,
a script executing in the NSF is an NKF accessor. Please see the accessor scripting
guide for discussion of how to implement an accessor with a script implementation.
Script Sources
The ScriptEngine will accept scripts either as text files or as an XML document with a <script> root element.
Java Classpath and Imports
A script will inherit the classpath
of the host module from which it is invoked. This includes the
classpaths exported by any modules which are imported into the host module. In addition the kernel and layer1 classpaths are always accessible.
Each dynamic language can access native Java classes - refer to the specific language reference guide for language-specific details.
Language-Specific Libraries
Each language is able to import language-specific script libraries from the modular NetKernel address-space context - refer to the
detailed reference guide of your preferred language for details.
Thread Safety
The ScriptEngine is thread-safe and scripts can and will be executed on NetKernel concurrently. If you create
local threads in your scripts, for example in Beanshell, you are responsible for their management and local
thread safety considerations - we highly recommend you delegate threading and concurrency to NetKernel.
Reference
We are using the following versions of language runtimes - links are to the language reference documentation.