Class GremlinGroovyScriptEngine
- java.lang.Object
- 
- javax.script.AbstractScriptEngine
- 
- org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
- 
- org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine
 
 
 
- 
- All Implemented Interfaces:
- Compilable,- Invocable,- ScriptEngine,- GremlinScriptEngine
 
 public class GremlinGroovyScriptEngine extends org.codehaus.groovy.jsr223.GroovyScriptEngineImpl implements GremlinScriptEngine Provides methods to compile and evaluate Gremlin scripts. Compiled scripts are stored in a managed cache to cut down on compilation times of future evaluations of the same script. ThisScriptEngineimplementation is heavily adapted from theGroovyScriptEngineImplto include some additional functionality.- Author:
- Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com)
- See Also:
- GremlinExecutor
 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringCOLLECTED_BOUND_VARS_MAP_VARNAMEName of variable that holds local variables to be globally bound if "interpreter mode" is enabled withInterpreterModeGroovyCustomizer.static ThreadLocal<Map<String,Object>>COMPILE_OPTIONSstatic StringCOMPILE_OPTIONS_VAR_TYPESAn "internal" key for sandboxing the script engine - technically not for public use.static StringKEY_REFERENCE_TYPEThe attribute key (passed as a binding on the context) for how to cache scripts.static StringREFERENCE_TYPE_HARDA value to theKEY_REFERENCE_TYPEthat makes the evaluated script available in the cache for the life of the JVM.static StringREFERENCE_TYPE_PHANTOMA value to theKEY_REFERENCE_TYPEthat immediately garbage collects the script after evaluation.static StringREFERENCE_TYPE_SOFTA value to theKEY_REFERENCE_TYPEthat retains the script until memory is "low" and therefore should be reclaimed before anOutOfMemoryErroroccurs.static StringREFERENCE_TYPE_WEAKA value to theKEY_REFERENCE_TYPEthat marks the script as one that can be garbage collected even when memory is abundant.- 
Fields inherited from class javax.script.AbstractScriptEnginecontext
 - 
Fields inherited from interface org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineHIDDEN_G
 - 
Fields inherited from interface javax.script.ScriptEngineARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
 
- 
 - 
Constructor SummaryConstructors Constructor Description GremlinGroovyScriptEngine()Creates a new instance using noCustomizer.GremlinGroovyScriptEngine(Customizer... customizers)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description CompiledScriptcompile(Reader reader)CompiledScriptcompile(String scriptSource)BindingscreateBindings()Create bindings to be used by thisScriptEngine.Objecteval(Reader reader, ScriptContext context)Objecteval(String script, ScriptContext context)Traversal.Admineval(Bytecode bytecode, Bindings bindings, String traversalSource)doublegetClassCacheAverageLoadPenalty()Gets the average time spent compiling new scripts.longgetClassCacheEstimatedSize()Gets the estimated size of the class cache for compiled scripts.longgetClassCacheEvictionCount()Gets the number of times a script compiled to a class has been evicted from the cache.longgetClassCacheEvictionWeight()Gets the sum of the weights of evicted entries from the class cache.longgetClassCacheHitCount()Gets the number of times cache look up for a compiled script returned a cached value.doublegetClassCacheHitRate()Gets the hit rate of the class cache.longgetClassCacheLoadCount()Gets the total number of times the cache lookup method attempted to compile new scripts.longgetClassCacheLoadFailureCount()Gets the total number of times the cache lookup method failed to compile a new script.doublegetClassCacheLoadFailureRate()Gets the ratio of script compilation attempts that failed.longgetClassCacheLoadSuccessCount()Gets the total number of times the cache lookup method succeeded to compile a new script.longgetClassCacheLongRunCompilationCount()Gets the number of compilations that extended beyond theexpectedCompilationTime.longgetClassCacheMissCount()Gets the total number of times the cache lookup method returned a newly compiled script.doublegetClassCacheMissRate()Gets the ratio of script compilation attempts that were misses.longgetClassCacheRequestCount()Gets the total number of times the cache lookup method returned a cached or uncached value.longgetClassCacheTotalLoadTime()Gets the total number of nanoseconds that the cache spent compiling scripts.GremlinScriptEngineFactorygetFactory()<T> TgetInterface(Class<T> clazz)<T> TgetInterface(Object thiz, Class<T> clazz)protected ClassLoadergetParentLoader()SetgetPlugins()Get the list of loaded plugins.protected ScriptContextgetScriptContext(Bindings nn)Creates theScriptContextusing aGremlinScriptContextwhich avoids a significant amount of additional object creation on script evaluation.ObjectinvokeFunction(String name, Object... args)ObjectinvokeMethod(Object thiz, String name, Object... args)voidreset()Resets the entireGremlinGroovyScriptEngineby clearing script caches, recreating the classloader, clearing bindings.- 
Methods inherited from class org.codehaus.groovy.jsr223.GroovyScriptEngineImplgetClassLoader, setClassLoader
 - 
Methods inherited from class javax.script.AbstractScriptEngineeval, eval, eval, eval, get, getBindings, getContext, put, setBindings, setContext
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineeval
 - 
Methods inherited from interface javax.script.ScriptEngineeval, eval, eval, eval, get, getBindings, getContext, put, setBindings, setContext
 
- 
 
- 
- 
- 
Field Detail- 
COMPILE_OPTIONS_VAR_TYPESpublic static final String COMPILE_OPTIONS_VAR_TYPES An "internal" key for sandboxing the script engine - technically not for public use.- See Also:
- Constant Field Values
 
 - 
KEY_REFERENCE_TYPEpublic static final String KEY_REFERENCE_TYPE The attribute key (passed as a binding on the context) for how to cache scripts. The value must be one of the following:- See Also:
- Constant Field Values
 
 - 
REFERENCE_TYPE_PHANTOMpublic static final String REFERENCE_TYPE_PHANTOM A value to theKEY_REFERENCE_TYPEthat immediately garbage collects the script after evaluation.- See Also:
- Constant Field Values
 
 - 
REFERENCE_TYPE_WEAKpublic static final String REFERENCE_TYPE_WEAK A value to theKEY_REFERENCE_TYPEthat marks the script as one that can be garbage collected even when memory is abundant.- See Also:
- Constant Field Values
 
 - 
REFERENCE_TYPE_SOFTpublic static final String REFERENCE_TYPE_SOFT A value to theKEY_REFERENCE_TYPEthat retains the script until memory is "low" and therefore should be reclaimed before anOutOfMemoryErroroccurs.- See Also:
- Constant Field Values
 
 - 
REFERENCE_TYPE_HARDpublic static final String REFERENCE_TYPE_HARD A value to theKEY_REFERENCE_TYPEthat makes the evaluated script available in the cache for the life of the JVM.- See Also:
- Constant Field Values
 
 - 
COLLECTED_BOUND_VARS_MAP_VARNAMEpublic static final String COLLECTED_BOUND_VARS_MAP_VARNAME Name of variable that holds local variables to be globally bound if "interpreter mode" is enabled withInterpreterModeGroovyCustomizer.- See Also:
- Constant Field Values
 
 - 
COMPILE_OPTIONSpublic static final ThreadLocal<Map<String,Object>> COMPILE_OPTIONS 
 
- 
 - 
Constructor Detail- 
GremlinGroovyScriptEnginepublic GremlinGroovyScriptEngine() Creates a new instance using noCustomizer.
 - 
GremlinGroovyScriptEnginepublic GremlinGroovyScriptEngine(Customizer... customizers) 
 
- 
 - 
Method Detail- 
getPluginspublic Set getPlugins() Get the list of loaded plugins.
 - 
evalpublic Traversal.Admin eval(Bytecode bytecode, Bindings bindings, String traversalSource) throws ScriptException Description copied from interface:GremlinScriptEngineEvaluatesTraversalBytecodewith the specifiedBindings. TheseBindingssupplied to this method will be merged with global engine bindings and override them where keys match.- Specified by:
- evalin interface- GremlinScriptEngine
- Throws:
- ScriptException
 
 - 
resetpublic void reset() Resets the entireGremlinGroovyScriptEngineby clearing script caches, recreating the classloader, clearing bindings.
 - 
getScriptContextprotected ScriptContext getScriptContext(Bindings nn) Creates theScriptContextusing aGremlinScriptContextwhich avoids a significant amount of additional object creation on script evaluation.- Overrides:
- getScriptContextin class- AbstractScriptEngine
 
 - 
evalpublic Object eval(Reader reader, ScriptContext context) throws ScriptException - Specified by:
- evalin interface- ScriptEngine
- Overrides:
- evalin class- org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
- Throws:
- ScriptException
 
 - 
evalpublic Object eval(String script, ScriptContext context) throws ScriptException - Specified by:
- evalin interface- ScriptEngine
- Overrides:
- evalin class- org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
- Throws:
- ScriptException
 
 - 
createBindingspublic Bindings createBindings() Create bindings to be used by thisScriptEngine. In this case,SimpleBindingsare returned.- Specified by:
- createBindingsin interface- ScriptEngine
- Overrides:
- createBindingsin class- org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
 
 - 
getFactorypublic GremlinScriptEngineFactory getFactory() - Specified by:
- getFactoryin interface- GremlinScriptEngine
- Specified by:
- getFactoryin interface- ScriptEngine
- Overrides:
- getFactoryin class- org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
 
 - 
compilepublic CompiledScript compile(String scriptSource) throws ScriptException - Specified by:
- compilein interface- Compilable
- Overrides:
- compilein class- org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
- Throws:
- ScriptException
 
 - 
compilepublic CompiledScript compile(Reader reader) throws ScriptException - Specified by:
- compilein interface- Compilable
- Overrides:
- compilein class- org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
- Throws:
- ScriptException
 
 - 
invokeFunctionpublic Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException - Specified by:
- invokeFunctionin interface- Invocable
- Overrides:
- invokeFunctionin class- org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
- Throws:
- ScriptException
- NoSuchMethodException
 
 - 
invokeMethodpublic Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException - Specified by:
- invokeMethodin interface- Invocable
- Overrides:
- invokeMethodin class- org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
- Throws:
- ScriptException
- NoSuchMethodException
 
 - 
getInterfacepublic <T> T getInterface(Class<T> clazz) - Specified by:
- getInterfacein interface- Invocable
- Overrides:
- getInterfacein class- org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
 
 - 
getInterfacepublic <T> T getInterface(Object thiz, Class<T> clazz) - Specified by:
- getInterfacein interface- Invocable
- Overrides:
- getInterfacein class- org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
 
 - 
getClassCacheLongRunCompilationCountpublic long getClassCacheLongRunCompilationCount() Gets the number of compilations that extended beyond theexpectedCompilationTime.
 - 
getClassCacheEstimatedSizepublic long getClassCacheEstimatedSize() Gets the estimated size of the class cache for compiled scripts.
 - 
getClassCacheAverageLoadPenaltypublic double getClassCacheAverageLoadPenalty() Gets the average time spent compiling new scripts.
 - 
getClassCacheEvictionCountpublic long getClassCacheEvictionCount() Gets the number of times a script compiled to a class has been evicted from the cache.
 - 
getClassCacheEvictionWeightpublic long getClassCacheEvictionWeight() Gets the sum of the weights of evicted entries from the class cache.
 - 
getClassCacheHitCountpublic long getClassCacheHitCount() Gets the number of times cache look up for a compiled script returned a cached value.
 - 
getClassCacheHitRatepublic double getClassCacheHitRate() Gets the hit rate of the class cache.
 - 
getClassCacheLoadCountpublic long getClassCacheLoadCount() Gets the total number of times the cache lookup method attempted to compile new scripts.
 - 
getClassCacheLoadFailureCountpublic long getClassCacheLoadFailureCount() Gets the total number of times the cache lookup method failed to compile a new script.
 - 
getClassCacheLoadFailureRatepublic double getClassCacheLoadFailureRate() Gets the ratio of script compilation attempts that failed.
 - 
getClassCacheLoadSuccessCountpublic long getClassCacheLoadSuccessCount() Gets the total number of times the cache lookup method succeeded to compile a new script.
 - 
getClassCacheMissCountpublic long getClassCacheMissCount() Gets the total number of times the cache lookup method returned a newly compiled script.
 - 
getClassCacheMissRatepublic double getClassCacheMissRate() Gets the ratio of script compilation attempts that were misses.
 - 
getClassCacheRequestCountpublic long getClassCacheRequestCount() Gets the total number of times the cache lookup method returned a cached or uncached value.
 - 
getClassCacheTotalLoadTimepublic long getClassCacheTotalLoadTime() Gets the total number of nanoseconds that the cache spent compiling scripts.
 - 
getParentLoaderprotected ClassLoader getParentLoader() 
 
- 
 
-