public class GremlinExecutor extends Object implements AutoCloseable
ScriptEngine
instance. It is designed to host any JSR-223 enabled
ScriptEngine
and assumes such engines are designed to be thread-safe in the evaluation. Script evaluation
functions return a CompletableFuture
where scripts may timeout if their evaluation
takes too long. The default timeout is 8000ms.
GremlinExecutor
initializes itself to use a shared thread pool initialized with four
threads. This default thread pool is shared for both the task of executing script evaluations and for scheduling
timeouts. It is worth noting that a timeout simply triggers the returned CompletableFuture
to abort, but
the thread processing the script will continue to evaluate until completion. This offers only marginal protection
against run-away scripts.Modifier and Type | Class and Description |
---|---|
static class |
GremlinExecutor.Builder |
Modifier and Type | Method and Description |
---|---|
static GremlinExecutor.Builder |
build()
Create a
Builder with the gremlin-groovy ScriptEngine configured. |
static GremlinExecutor.Builder |
build(String engineName,
List<String> imports,
List<String> staticImports,
List<String> scripts,
Map<String,Object> config)
Create a
Builder and specify the first ScriptEngine to be included. |
void |
close()
Executors are only closed if they were not supplied externally in the
GremlinExecutor.Builder |
CompletableFuture<Void> |
closeAsync()
Executors are only closed if they were not supplied externally in the
GremlinExecutor.Builder |
Optional<CompiledScript> |
compile(String script)
Attempts to compile a script and cache it in the default
ScriptEngine . |
Optional<CompiledScript> |
compile(String script,
Optional<String> language)
Attempts to compile a script and cache it in the request
ScriptEngine . |
CompletableFuture<Object> |
eval(String script) |
CompletableFuture<Object> |
eval(String script,
Bindings boundVars) |
CompletableFuture<Object> |
eval(String script,
Map<String,Object> boundVars) |
CompletableFuture<Object> |
eval(String script,
String language,
Bindings boundVars) |
CompletableFuture<Object> |
eval(String script,
String language,
Bindings boundVars,
Function<Object,Object> transformResult) |
CompletableFuture<Object> |
eval(String script,
String language,
Map<String,Object> boundVars) |
CompletableFuture<Object> |
eval(String script,
String language,
Map<String,Object> boundVars,
Function<Object,Object> transformResult) |
ExecutorService |
getExecutorService() |
Bindings |
getGlobalBindings() |
ScheduledExecutorService |
getScheduledExecutorService() |
ScriptEngines |
getScriptEngines() |
public Optional<CompiledScript> compile(String script) throws ScriptException
ScriptEngine
. This is only
possible if the ScriptEngine
implementation implements Compilable
.
In the event that the default ScriptEngine
does not implement it, the method will
return empty.ScriptException
public Optional<CompiledScript> compile(String script, Optional<String> language) throws ScriptException
ScriptEngine
. This is only
possible if the ScriptEngine
implementation implements Compilable
.
In the event that the requested ScriptEngine
does not implement it, the method will
return empty.ScriptException
public CompletableFuture<Object> eval(String script)
public CompletableFuture<Object> eval(String script, Bindings boundVars)
public CompletableFuture<Object> eval(String script, String language, Map<String,Object> boundVars)
public CompletableFuture<Object> eval(String script, String language, Bindings boundVars)
public CompletableFuture<Object> eval(String script, String language, Map<String,Object> boundVars, Function<Object,Object> transformResult)
public CompletableFuture<Object> eval(String script, String language, Bindings boundVars, Function<Object,Object> transformResult)
public ScriptEngines getScriptEngines()
public ExecutorService getExecutorService()
public ScheduledExecutorService getScheduledExecutorService()
public Bindings getGlobalBindings()
public void close() throws Exception
GremlinExecutor.Builder
close
in interface AutoCloseable
Exception
public CompletableFuture<Void> closeAsync() throws Exception
GremlinExecutor.Builder
Exception
public static GremlinExecutor.Builder build()
Builder
with the gremlin-groovy ScriptEngine configured.Copyright © 2013–2015 Apache Software Foundation. All rights reserved.