Class GremlinExecutor
- java.lang.Object
- 
- org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor
 
- 
- All Implemented Interfaces:
- AutoCloseable
 
 public class GremlinExecutor extends Object implements AutoCloseable Execute Gremlin scripts against aScriptEngineinstance. It is designed to host any JSR-223 enabledScriptEngineand assumes such engines are designed to be thread-safe in the evaluation. Script evaluation functions return aCompletableFuturewhere scripts may timeout if their evaluation takes too long. The default timeout is 8000ms. By default, theGremlinExecutorinitializes 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 returnedCompletableFutureto 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 SummaryNested Classes Modifier and Type Class Description static classGremlinExecutor.Builderstatic classGremlinExecutor.LifeCycleThe lifecycle of execution within the#eval(String, String, Bindings, LifeCycle)method.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static GremlinExecutor.Builderbuild()Create aBuilderwith the gremlin-groovy ScriptEngine configured.voidclose()CompletableFuture<Void>closeAsync()Executors are only closed if they were not supplied externally in theGremlinExecutor.BuilderOptional<CompiledScript>compile(String script)Attempts to compile a script and cache it in the defaultScriptEngine.Optional<CompiledScript>compile(String script, Optional<String> language)Attempts to compile a script and cache it in the requestScriptEngine.CompletableFuture<Object>eval(Object 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.CompletableFuture<Object>eval(Object 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.CompletableFuture<Object>eval(Object gremlin, String language, Bindings boundVars, Long timeOut, Function<Object,Object> transformResult, Consumer<Object> withResult)CompletableFuture<Object>eval(Object gremlin, String language, Bindings boundVars, Function<Object,Object> transformResult, Consumer<Object> withResult)CompletableFuture<Object>eval(Object gremlin, 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)Evaluate a script with empty bindings.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 aConsumerthat will take the result for additional processing after the script evaluates and after theCompletableFutureis completed, but before the transaction is committed.CompletableFuture<Object>eval(String script, String language, Bindings boundVars)Evaluate a script.CompletableFuture<Object>eval(String script, Map<String,Object> boundVars)Evaluate a script with aMapof bindings.CompletableFuture<Object>eval(String script, Bindings boundVars)Evaluate a script with specified bindings.Traversal.Admineval(Bytecode bytecode, Bindings boundVars, String language, String traversalSource)Evaluates bytecode with bindings for a specific language into aTraversal.ExecutorServicegetExecutorService()ScheduledExecutorServicegetScheduledExecutorService()GremlinScriptEngineManagergetScriptEngineManager()
 
- 
- 
- 
Method Detail- 
compilepublic Optional<CompiledScript> compile(String script) throws ScriptException 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
 
 - 
compilepublic 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
 
 - 
evalpublic CompletableFuture<Object> eval(String script) Evaluate a script with empty bindings.
 - 
evalpublic CompletableFuture<Object> eval(String script, Bindings boundVars) Evaluate a script with specified bindings.
 - 
evalpublic CompletableFuture<Object> eval(String script, Map<String,Object> boundVars) Evaluate a script with aMapof bindings.
 - 
evalpublic CompletableFuture<Object> eval(String script, String language, Map<String,Object> boundVars) Evaluate a script.- Parameters:
- script- the script to evaluate
- language- the language to evaluate it in
- boundVars- the bindings as a- Mapto evaluate in the context of the script
 
 - 
evalpublic CompletableFuture<Object> eval(String script, String language, Bindings boundVars) Evaluate a script.- Parameters:
- script- the script to evaluate
- language- the language to evaluate it in
- boundVars- the bindings to evaluate in the context of the script
 
 - 
evalpublic CompletableFuture<Object> eval(Object 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 or bytecode to evaluate
- language- the language to evaluate it in
- boundVars- the bindings to evaluate in the context of the script
- transformResult- a- Functionthat transforms the result - can be- null
 
 - 
evalpublic CompletableFuture<Object> eval(Object 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 or bytecode to evaluate
- language- the language to evaluate it in
- boundVars- the bindings to evaluate in the context of the script
- timeOut- optional override for evaluation timeout
- transformResult- a- Functionthat transforms the result - can be- null
 
 - 
evalpublic 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 evaluate
- language- the language to evaluate it in
- boundVars- the bindings to evaluate in the context of the script
- withResult- a- Consumerthat accepts the result - can be- null
 
 - 
evalpublic CompletableFuture<Object> eval(Object 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.
 - 
evalpublic CompletableFuture<Object> eval(Object 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 or bytecode to evaluate
- language- the language to evaluate it in
- boundVars- the bindings to evaluate in the context of the script
- timeOut- optional override for evaluation timeout
- transformResult- a- Functionthat transforms the result - can be- null
- withResult- a- Consumerthat accepts the result - can be- null
 
 - 
evalpublic CompletableFuture<Object> eval(Object 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 or bytecode to evaluate
- language- the language to evaluate it in
- boundVars- the bindings to evaluate in the context of the script
- lifeCycle- a set of functions that can be applied at various stages of the evaluation process
 
 - 
evalpublic Traversal.Admin eval(Bytecode bytecode, Bindings boundVars, String language, String traversalSource) throws ScriptException Evaluates bytecode with bindings for a specific language into aTraversal.- Throws:
- ScriptException
 
 - 
getScriptEngineManagerpublic GremlinScriptEngineManager getScriptEngineManager() 
 - 
getExecutorServicepublic ExecutorService getExecutorService() 
 - 
getScheduledExecutorServicepublic ScheduledExecutorService getScheduledExecutorService() 
 - 
closepublic void close() throws ExceptionExecutors are only closed if they were not supplied externally in theGremlinExecutor.Builder- Specified by:
- closein interface- AutoCloseable
- Throws:
- Exception
 
 - 
closeAsyncpublic CompletableFuture<Void> closeAsync() throws Exception Executors are only closed if they were not supplied externally in theGremlinExecutor.Builder- Throws:
- Exception
 
 - 
buildpublic static GremlinExecutor.Builder build() Create aBuilderwith the gremlin-groovy ScriptEngine configured.
 
- 
 
-