public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl implements DependencyManager, AutoCloseable
ScriptEngine
implementation is heavily adapted from the GroovyScriptEngineImpl
to include
some additional functionality.Modifier and Type | Field and Description |
---|---|
static ThreadLocal<Map<String,Object>> |
COMPILE_OPTIONS |
static String |
COMPILE_OPTIONS_VAR_TYPES |
static String |
KEY_REFERENCE_TYPE |
protected GremlinGroovyClassLoader |
loader |
static String |
REFERENCE_TYPE_HARD |
static String |
REFERENCE_TYPE_PHANTOM |
static String |
REFERENCE_TYPE_SOFT |
static String |
REFERENCE_TYPE_WEAK |
Constructor and Description |
---|
GremlinGroovyScriptEngine() |
GremlinGroovyScriptEngine(CompilerCustomizerProvider... compilerCustomizerProviders) |
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() |
Map[] |
dependencies()
List the dependencies in the ScriptEngine classloader.
|
Object |
eval(Reader reader,
ScriptContext context) |
Object |
eval(String script,
ScriptContext context) |
ScriptEngineFactory |
getFactory() |
<T> T |
getInterface(Class<T> clazz) |
<T> T |
getInterface(Object thiz,
Class<T> clazz) |
protected ClassLoader |
getParentLoader() |
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() |
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.
|
public static final String COMPILE_OPTIONS_VAR_TYPES
public static final String KEY_REFERENCE_TYPE
public static final String REFERENCE_TYPE_PHANTOM
public static final String REFERENCE_TYPE_WEAK
public static final String REFERENCE_TYPE_SOFT
public static final String REFERENCE_TYPE_HARD
public static final ThreadLocal<Map<String,Object>> COMPILE_OPTIONS
protected GremlinGroovyClassLoader loader
public GremlinGroovyScriptEngine()
public GremlinGroovyScriptEngine(CompilerCustomizerProvider... compilerCustomizerProviders)
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 DependencyManager
public void loadPlugins(List<GremlinPlugin> plugins) throws GremlinPluginException
DependencyManager
GremlinPlugin
instances. These plugins are typically returned from calls to
DependencyManager.use(String, String, String)
.loadPlugins
in interface DependencyManager
GremlinPluginException
- if there is a problem loading the plugin itself.public Map[] dependencies()
DependencyManager
dependencies
in interface DependencyManager
public Map<String,Set<String>> imports()
DependencyManager
imports
in interface DependencyManager
public void addImports(Set<String> importStatements)
DependencyManager
addImports
in interface DependencyManager
public Set plugins()
public void close() throws Exception
close
in interface AutoCloseable
Exception
public void reset()
DependencyManager
reset
in interface DependencyManager
public Object eval(Reader reader, ScriptContext context) throws ScriptException
ScriptException
public Object eval(String script, ScriptContext context) throws ScriptException
ScriptException
public Bindings createBindings()
public ScriptEngineFactory getFactory()
public CompiledScript compile(String scriptSource) throws ScriptException
ScriptException
public CompiledScript compile(Reader reader) throws ScriptException
ScriptException
public Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException
ScriptException
NoSuchMethodException
public Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException
ScriptException
NoSuchMethodException
public <T> T getInterface(Class<T> clazz)
protected ClassLoader getParentLoader()
Copyright © 2013–2015 Apache Software Foundation. All rights reserved.