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.
By default, the 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 |
static class |
GremlinExecutor.LifeCycle
The lifecycle of execution within the
eval(String, String, Bindings, LifeCycle) method. |
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)
Deprecated.
As of release 3.2.4, replaced by
build() . |
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 . |
Traversal.Admin |
eval(Bytecode bytecode,
Bindings boundVars,
String language)
Deprecated.
As of release 3.2.7, replaced by
eval(Bytecode, Bindings, String, String) |
Traversal.Admin |
eval(Bytecode bytecode,
Bindings boundVars,
String language,
String traversalSource)
Evaluates bytecode with bindings for a specific language into a
Traversal . |
CompletableFuture<Object> |
eval(String script)
Evaluate a script with empty bindings.
|
CompletableFuture<Object> |
eval(String script,
Bindings boundVars)
Evaluate a script with specified bindings.
|
CompletableFuture<Object> |
eval(String script,
Map<String,Object> boundVars)
Evaluate a script with a
Map of bindings. |
CompletableFuture<Object> |
eval(String script,
String language,
Bindings boundVars)
Evaluate a script.
|
CompletableFuture<Object> |
eval(String script,
String language,
Bindings boundVars,
Function<Object,Object> transformResult,
Consumer<Object> withResult)
|
CompletableFuture<Object> |
eval(String script,
String language,
Bindings boundVars,
GremlinExecutor.LifeCycle lifeCycle)
Evaluate a script and allow for the submission of alteration to the entire evaluation execution lifecycle.
|
CompletableFuture<Object> |
eval(String script,
String language,
Map<String,Object> boundVars)
Evaluate a script.
|
CompletableFuture<Object> |
eval(String script,
String language,
Map<String,Object> boundVars,
Consumer<Object> withResult)
Evaluate a script and allow for the submission of a
Consumer that will take the result for additional
processing after the script evaluates and after the CompletableFuture is completed, but before the
transaction is committed. |
CompletableFuture<Object> |
eval(String script,
String language,
Map<String,Object> boundVars,
Function<Object,Object> transformResult)
Evaluate a script and allow for the submission of a transform
Function that will transform the
result after script evaluates but before transaction commit and before the returned CompletableFuture
is completed. |
ExecutorService |
getExecutorService() |
Bindings |
getGlobalBindings()
Deprecated.
As of release 3.2.5, replaced by
getScriptEngineManager() to add global scoped bindings
directly to that object. |
ScheduledExecutorService |
getScheduledExecutorService() |
GremlinScriptEngineManager |
getScriptEngineManager() |
ScriptEngines |
getScriptEngines()
Deprecated.
As of release 3.2.4, replaced by
getScriptEngineManager() . |
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, Map<String,Object> boundVars)
Map
of bindings.public CompletableFuture<Object> eval(String script, String language, Map<String,Object> boundVars)
script
- the script to evaluatelanguage
- the language to evaluate it inboundVars
- the bindings as a Map
to evaluate in the context of the scriptpublic CompletableFuture<Object> eval(String script, String language, Bindings boundVars)
script
- the script to evaluatelanguage
- the language to evaluate it inboundVars
- the bindings to evaluate in the context of the scriptpublic CompletableFuture<Object> eval(String script, String language, Map<String,Object> boundVars, Function<Object,Object> transformResult)
Function
that will transform the
result after script evaluates but before transaction commit and before the returned CompletableFuture
is completed.script
- the script to evaluatelanguage
- the language to evaluate it inboundVars
- the bindings to evaluate in the context of the scripttransformResult
- a Function
that transforms the result - can be null
public CompletableFuture<Object> eval(String script, String language, Map<String,Object> boundVars, Consumer<Object> withResult)
Consumer
that will take the result for additional
processing after the script evaluates and after the CompletableFuture
is completed, but before the
transaction is committed.script
- the script to evaluatelanguage
- the language to evaluate it inboundVars
- the bindings to evaluate in the context of the scriptwithResult
- a Consumer
that accepts the result - can be null
public CompletableFuture<Object> eval(String script, String language, Bindings boundVars, Function<Object,Object> transformResult, Consumer<Object> withResult)
Function
and Consumer
.
The Function
will transform the result after script evaluates but before transaction commit and before
the returned CompletableFuture
is completed. The Consumer
will take the result for additional
processing after the script evaluates and after the CompletableFuture
is completed, but before the
transaction is committed.public CompletableFuture<Object> eval(String script, String language, Bindings boundVars, GremlinExecutor.LifeCycle lifeCycle)
script
- the script to evaluatelanguage
- the language to evaluate it inboundVars
- the bindings to evaluate in the context of the scriptlifeCycle
- a set of functions that can be applied at various stages of the evaluation process@Deprecated public Traversal.Admin eval(Bytecode bytecode, Bindings boundVars, String language) throws ScriptException
eval(Bytecode, Bindings, String, String)
Traversal
.ScriptException
public Traversal.Admin eval(Bytecode bytecode, Bindings boundVars, String language, String traversalSource) throws ScriptException
Traversal
.bytecode
- to execute as a traversalboundVars
- local bindingslanguage
- the scripting language to use to process the bytecodetraversalSource
- the specific traversal source to execute the bytecode againstScriptException
@Deprecated public ScriptEngines getScriptEngines()
getScriptEngineManager()
.public GremlinScriptEngineManager getScriptEngineManager()
public ExecutorService getExecutorService()
public ScheduledExecutorService getScheduledExecutorService()
@Deprecated public Bindings getGlobalBindings()
getScriptEngineManager()
to add global scoped bindings
directly to that object.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–2018 Apache Software Foundation. All rights reserved.