public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements DependencyManager, AutoCloseable, GremlinScriptEngine
ScriptEngine implementation is
heavily adapted from the GroovyScriptEngineImpl to include some additional functionality.GremlinExecutor| Modifier and Type | Field and Description |
|---|---|
static String |
COLLECTED_BOUND_VARS_MAP_VARNAME
Name of variable that holds local variables to be globally bound if "interpreter mode" is enabled with
InterpreterModeCustomizerProvider. |
static ThreadLocal<Map<String,Object>> |
COMPILE_OPTIONS |
static String |
COMPILE_OPTIONS_VAR_TYPES
An "internal" key for sandboxing the script engine - technically not for public use.
|
static String |
KEY_REFERENCE_TYPE
The attribute key (passed as a binding on the context) for how to cache scripts.
|
static String |
REFERENCE_TYPE_HARD
A value to the
KEY_REFERENCE_TYPE that makes the evaluated script available in the cache for the life
of the JVM. |
static String |
REFERENCE_TYPE_PHANTOM
A value to the
KEY_REFERENCE_TYPE that immediately garbage collects the script after evaluation. |
static String |
REFERENCE_TYPE_SOFT
A value to the
KEY_REFERENCE_TYPE that retains the script until memory is "low" and therefore
should be reclaimed before an OutOfMemoryError occurs. |
static String |
REFERENCE_TYPE_WEAK
A value to the
KEY_REFERENCE_TYPE that marks the script as one that can be garbage collected
even when memory is abundant. |
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME| Constructor and Description |
|---|
GremlinGroovyScriptEngine()
Creates a new instance using the
DefaultImportCustomizerProvider. |
GremlinGroovyScriptEngine(CompilerCustomizerProvider... compilerCustomizerProviders)
Creates a new instance with the specified
CompilerCustomizerProvider objects. |
GremlinGroovyScriptEngine(Customizer... customizers) |
GremlinGroovyScriptEngine(ImportCustomizerProvider importCustomizerProvider)
Deprecated.
As of release 3.0.1, replaced by
GremlinGroovyScriptEngine(CompilerCustomizerProvider...) |
| Modifier and Type | Method and Description |
|---|---|
void |
addImports(Set<String> importStatements)
Perform class imports for the ScriptEngine.
|
void |
close() |
CompiledScript |
compile(Reader reader) |
CompiledScript |
compile(String scriptSource) |
Bindings |
createBindings()
Create bindings to be used by this
ScriptEngine. |
Map[] |
dependencies()
List the dependencies in the ScriptEngine classloader.
|
Traversal.Admin |
eval(Bytecode bytecode,
Bindings bindings)
|
Object |
eval(Reader reader,
ScriptContext context) |
Object |
eval(String script,
ScriptContext context) |
GremlinScriptEngineFactory |
getFactory() |
<T> T |
getInterface(Class<T> clazz) |
<T> T |
getInterface(Object thiz,
Class<T> clazz) |
protected ClassLoader |
getParentLoader() |
Set |
getPlugins()
Get the list of loaded plugins.
|
Map<String,Set<String>> |
imports()
List the imports in the ScriptEngine;
|
Object |
invokeFunction(String name,
Object... args) |
Object |
invokeMethod(Object thiz,
String name,
Object... args) |
void |
loadPlugins(List<GremlinPlugin> plugins)
Load a list of
GremlinPlugin instances. |
Set |
plugins()
Deprecated.
As of release 3.0.1, replaced by
getPlugins() |
void |
reset()
Reset the ScriptEngine.
|
List<GremlinPlugin> |
use(String group,
String artifact,
String version)
Take maven coordinates and load the classes into the classloader used by the ScriptEngine.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitevaleval, eval, eval, eval, get, getBindings, getContext, put, setBindings, setContextpublic static final String COMPILE_OPTIONS_VAR_TYPES
public static final String KEY_REFERENCE_TYPE
public static final String REFERENCE_TYPE_PHANTOM
KEY_REFERENCE_TYPE that immediately garbage collects the script after evaluation.public static final String REFERENCE_TYPE_WEAK
KEY_REFERENCE_TYPE that marks the script as one that can be garbage collected
even when memory is abundant.public static final String REFERENCE_TYPE_SOFT
KEY_REFERENCE_TYPE that retains the script until memory is "low" and therefore
should be reclaimed before an OutOfMemoryError occurs.public static final String REFERENCE_TYPE_HARD
KEY_REFERENCE_TYPE that makes the evaluated script available in the cache for the life
of the JVM.public static final String COLLECTED_BOUND_VARS_MAP_VARNAME
InterpreterModeCustomizerProvider.public static final ThreadLocal<Map<String,Object>> COMPILE_OPTIONS
public GremlinGroovyScriptEngine()
DefaultImportCustomizerProvider.@Deprecated public GremlinGroovyScriptEngine(ImportCustomizerProvider importCustomizerProvider)
GremlinGroovyScriptEngine(CompilerCustomizerProvider...)public GremlinGroovyScriptEngine(Customizer... customizers)
public GremlinGroovyScriptEngine(CompilerCustomizerProvider... compilerCustomizerProviders)
CompilerCustomizerProvider objects.public List<GremlinPlugin> use(String group, String artifact, String version)
GremlinPlugin
implementations in the classloader. The GremlinGroovyScriptEngine
implementation uses ServiceLoader to figure out if there are such classes to return.
It is up to the caller to execute the
GremlinPlugin.pluginTo(org.apache.tinkerpop.gremlin.groovy.plugin.PluginAcceptor) method. The reason for
this has to do with conflicts that can occur with mapper imports that are added via the
ImportCustomizerProvider and scripts executed through the
PluginAcceptor. Generally speaking, all calls to this "use" method
should be complete prior to calling
GremlinPlugin.pluginTo(PluginAcceptor).
This method should be called after "expected" imports have been added to the DependencyManager
because adding imports with addImports(java.util.Set) will reset the classloader and flush away
dependencies.use in interface DependencyManagerpublic void loadPlugins(List<GremlinPlugin> plugins) throws GremlinPluginException
GremlinPlugin instances. These plugins are typically returned from calls to
DependencyManager.use(String, String, String).loadPlugins in interface DependencyManagerGremlinPluginException - if there is a problem loading the plugin itself.public Map[] dependencies()
dependencies in interface DependencyManagerpublic Map<String,Set<String>> imports()
imports in interface DependencyManagerpublic void addImports(Set<String> importStatements)
addImports in interface DependencyManager@Deprecated public Set plugins()
getPlugins()public Set getPlugins()
public Traversal.Admin eval(Bytecode bytecode, Bindings bindings) throws ScriptException
GremlinScriptEngineTraversal Bytecode with the specified Bindings. These Bindings
supplied to this method will be merged with global engine bindings and override them where keys match.eval in interface GremlinScriptEngineScriptExceptionpublic void close()
throws Exception
close in interface AutoCloseableExceptionpublic void reset()
reset in interface DependencyManagerpublic Object eval(Reader reader, ScriptContext context) throws ScriptException
eval in interface ScriptEngineScriptExceptionpublic Object eval(String script, ScriptContext context) throws ScriptException
eval in interface ScriptEngineScriptExceptionpublic Bindings createBindings()
ScriptEngine. In this case, SimpleBindings are returned.createBindings in interface ScriptEnginepublic GremlinScriptEngineFactory getFactory()
getFactory in interface ScriptEnginegetFactory in interface GremlinScriptEnginepublic CompiledScript compile(String scriptSource) throws ScriptException
ScriptExceptionpublic CompiledScript compile(Reader reader) throws ScriptException
ScriptExceptionpublic Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException
ScriptExceptionNoSuchMethodExceptionpublic Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException
ScriptExceptionNoSuchMethodExceptionpublic <T> T getInterface(Class<T> clazz)
protected ClassLoader getParentLoader()
Copyright © 2013–2016 Apache Software Foundation. All rights reserved.