Class GremlinExecutor
java.lang.Object
org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor
- All Implemented Interfaces:
AutoCloseable
Execute Gremlin scripts against a
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.- Author:
- Stephen Mallette (http://stephen.genoprime.com)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic classThe lifecycle of execution within theeval(String, String, Bindings, LifeCycle)method. -
Method Summary
Modifier and TypeMethodDescriptionstatic GremlinExecutor.Builderbuild()Create aBuilderwith the gremlin-groovy ScriptEngine configured.voidclose()Executors are only closed if they were not supplied externally in theGremlinExecutor.BuilderAttempts to compile a script and cache it in the defaultScriptEngine.Attempts to compile a script and cache it in the requestScriptEngine.Evaluate a script with empty bindings.Evaluate a script.eval(String gremlin, String language, Map<String, Object> boundVars, Long timeOut, Function<Object, Object> transformResult) Evaluate a script and allow for the submission of a transformFunctionthat will transform the result after script evaluates but before transaction commit and before the returnedCompletableFutureis completed.Evaluate a script and allow for the submission of aConsumerthat will take the result for additional processing after the script evaluates and after theCompletableFutureis completed, but before the transaction is committed.eval(String gremlin, String language, Map<String, Object> boundVars, Function<Object, Object> transformResult) Evaluate a script and allow for the submission of a transformFunctionthat will transform the result after script evaluates but before transaction commit and before the returnedCompletableFutureis completed.Evaluate a script.eval(String gremlin, String language, Bindings boundVars, Long timeOut, Function<Object, Object> transformResult, Consumer<Object> withResult) eval(String gremlin, String language, Bindings boundVars, Function<Object, Object> transformResult, Consumer<Object> withResult) eval(String gremlin, String language, Bindings boundVars, GremlinExecutor.LifeCycle lifeCycle) Evaluate a script and allow for the submission of alteration to the entire evaluation execution lifecycle.Evaluate a script with aMapof bindings.Evaluate a script with specified bindings.
-
Method Details
-
compile
Attempts to compile a script and cache it in the defaultScriptEngine. This is only possible if theScriptEngineimplementation implementsCompilable. In the event that the defaultScriptEnginedoes not implement it, the method will return empty.- Throws:
ScriptException
-
compile
public Optional<CompiledScript> compile(String script, Optional<String> language) throws ScriptException Attempts to compile a script and cache it in the requestScriptEngine. This is only possible if theScriptEngineimplementation implementsCompilable. In the event that the requestedScriptEnginedoes not implement it, the method will return empty.- Throws:
ScriptException
-
eval
Evaluate a script with empty bindings. -
eval
Evaluate a script with specified bindings. -
eval
Evaluate a script with aMapof bindings. -
eval
Evaluate a script.- Parameters:
script- the script to evaluatelanguage- the language to evaluate it inboundVars- the bindings as aMapto evaluate in the context of the script
-
eval
Evaluate a script.- Parameters:
script- the script to evaluatelanguage- the language to evaluate it inboundVars- the bindings to evaluate in the context of the script
-
eval
public CompletableFuture<Object> eval(String gremlin, String language, Map<String, Object> boundVars, Function<Object, Object> transformResult) Evaluate a script and allow for the submission of a transformFunctionthat will transform the result after script evaluates but before transaction commit and before the returnedCompletableFutureis completed.- Parameters:
gremlin- the script to evaluatelanguage- the language to evaluate it inboundVars- the bindings to evaluate in the context of the scripttransformResult- aFunctionthat transforms the result - can benull
-
eval
public CompletableFuture<Object> eval(String gremlin, String language, Map<String, Object> boundVars, Long timeOut, Function<Object, Object> transformResult) Evaluate a script and allow for the submission of a transformFunctionthat will transform the result after script evaluates but before transaction commit and before the returnedCompletableFutureis completed.- Parameters:
gremlin- the script to evaluatelanguage- the language to evaluate it inboundVars- the bindings to evaluate in the context of the scripttimeOut- optional override for evaluation timeouttransformResult- aFunctionthat transforms the result - can benull
-
eval
public CompletableFuture<Object> eval(String script, String language, Map<String, Object> boundVars, Consumer<Object> withResult) Evaluate a script and allow for the submission of aConsumerthat will take the result for additional processing after the script evaluates and after theCompletableFutureis completed, but before the transaction is committed.- Parameters:
script- the script to evaluatelanguage- the language to evaluate it inboundVars- the bindings to evaluate in the context of the scriptwithResult- aConsumerthat accepts the result - can benull
-
eval
public CompletableFuture<Object> eval(String gremlin, String language, Bindings boundVars, Function<Object, Object> transformResult, Consumer<Object> withResult) Evaluate a script and allow for the submission of both a transformFunctionandConsumer. TheFunctionwill transform the result after script evaluates but before transaction commit and before the returnedCompletableFutureis completed. TheConsumerwill take the result for additional processing after the script evaluates and after theCompletableFutureis completed, but before the transaction is committed. -
eval
public CompletableFuture<Object> eval(String gremlin, String language, Bindings boundVars, Long timeOut, Function<Object, Object> transformResult, Consumer<Object> withResult) Evaluate a script and allow for the submission of both a transformFunctionandConsumer. TheFunctionwill transform the result after script evaluates but before transaction commit and before the returnedCompletableFutureis completed. TheConsumerwill take the result for additional processing after the script evaluates and after theCompletableFutureis completed, but before the transaction is committed.- Parameters:
gremlin- the script to evaluatelanguage- the language to evaluate it inboundVars- the bindings to evaluate in the context of the scripttimeOut- optional override for evaluation timeouttransformResult- aFunctionthat transforms the result - can benullwithResult- aConsumerthat accepts the result - can benull
-
eval
public CompletableFuture<Object> eval(String gremlin, String language, Bindings boundVars, GremlinExecutor.LifeCycle lifeCycle) Evaluate a script and allow for the submission of alteration to the entire evaluation execution lifecycle.- Parameters:
gremlin- 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
-
getScriptEngineManager
-
getExecutorService
-
getScheduledExecutorService
-
close
Executors are only closed if they were not supplied externally in theGremlinExecutor.Builder- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
closeAsync
Executors are only closed if they were not supplied externally in theGremlinExecutor.Builder- Throws:
Exception
-
build
Create aBuilderwith the gremlin-groovy ScriptEngine configured.
-