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. This
ScriptEngine implementation is
heavily adapted from the GroovyScriptEngineImpl to include some additional functionality.- Author:
- Marko A. Rodriguez (http://markorodriguez.com), Stephen Mallette (http://stephen.genoprime.com)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of variable that holds local variables to be globally bound if "interpreter mode" is enabled withInterpreterModeGroovyCustomizer.static final ThreadLocal<Map<String,Object>> static final StringAn "internal" key for sandboxing the script engine - technically not for public use.static final StringThe attribute key (passed as a binding on the context) for how to cache scripts.static final StringA value to theKEY_REFERENCE_TYPEthat makes the evaluated script available in the cache for the life of the JVM.static final StringA value to theKEY_REFERENCE_TYPEthat immediately garbage collects the script after evaluation.static final StringA value to theKEY_REFERENCE_TYPEthat retains the script until memory is "low" and therefore should be reclaimed before anOutOfMemoryErroroccurs.static final StringA 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.AbstractScriptEngine
contextFields inherited from interface org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine
HIDDEN_GFields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance using noCustomizer.GremlinGroovyScriptEngine(Customizer... customizers) -
Method Summary
Modifier and TypeMethodDescriptionCreate bindings to be used by thisScriptEngine.eval(Reader reader, ScriptContext context) eval(String script, ScriptContext context) doubleGets the average time spent compiling new scripts.longGets the estimated size of the class cache for compiled scripts.longGets the number of times a script compiled to a class has been evicted from the cache.longGets the sum of the weights of evicted entries from the class cache.longGets the number of times cache look up for a compiled script returned a cached value.doubleGets the hit rate of the class cache.longGets the total number of times the cache lookup method attempted to compile new scripts.longGets the total number of times the cache lookup method failed to compile a new script.doubleGets the ratio of script compilation attempts that failed.longGets the total number of times the cache lookup method succeeded to compile a new script.longGets the number of compilations that extended beyond theexpectedCompilationTime.longGets the total number of times the cache lookup method returned a newly compiled script.doubleGets the ratio of script compilation attempts that were misses.longGets the total number of times the cache lookup method returned a cached or uncached value.longGets the total number of nanoseconds that the cache spent compiling scripts.<T> TgetInterface(Class<T> clazz) <T> TgetInterface(Object thiz, Class<T> clazz) protected ClassLoaderGet the list of loaded plugins.protected ScriptContextCreates theScriptContextusing aGremlinScriptContextwhich avoids a significant amount of additional object creation on script evaluation.invokeFunction(String name, Object... args) invokeMethod(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.GroovyScriptEngineImpl
getClassLoader, setClassLoaderMethods inherited from class javax.script.AbstractScriptEngine
eval, eval, eval, eval, get, getBindings, getContext, put, setBindings, setContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.script.ScriptEngine
eval, eval, eval, eval, get, getBindings, getContext, put, setBindings, setContext
-
Field Details
-
COMPILE_OPTIONS_VAR_TYPES
An "internal" key for sandboxing the script engine - technically not for public use.- See Also:
-
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:
-
REFERENCE_TYPE_PHANTOM
A value to theKEY_REFERENCE_TYPEthat immediately garbage collects the script after evaluation.- See Also:
-
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:
-
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:
-
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:
-
COLLECTED_BOUND_VARS_MAP_VARNAME
Name of variable that holds local variables to be globally bound if "interpreter mode" is enabled withInterpreterModeGroovyCustomizer.- See Also:
-
COMPILE_OPTIONS
-
-
Constructor Details
-
GremlinGroovyScriptEngine
public GremlinGroovyScriptEngine()Creates a new instance using noCustomizer. -
GremlinGroovyScriptEngine
-
-
Method Details
-
getPlugins
Get the list of loaded plugins. -
reset
public void reset()Resets the entireGremlinGroovyScriptEngineby clearing script caches, recreating the classloader, clearing bindings. -
getScriptContext
Creates theScriptContextusing aGremlinScriptContextwhich avoids a significant amount of additional object creation on script evaluation.- Overrides:
getScriptContextin classAbstractScriptEngine
-
eval
- Specified by:
evalin interfaceScriptEngine- Overrides:
evalin classorg.codehaus.groovy.jsr223.GroovyScriptEngineImpl- Throws:
ScriptException
-
eval
- Specified by:
evalin interfaceScriptEngine- Overrides:
evalin classorg.codehaus.groovy.jsr223.GroovyScriptEngineImpl- Throws:
ScriptException
-
createBindings
Create bindings to be used by thisScriptEngine. In this case,SimpleBindingsare returned.- Specified by:
createBindingsin interfaceScriptEngine- Overrides:
createBindingsin classorg.codehaus.groovy.jsr223.GroovyScriptEngineImpl
-
getFactory
- Specified by:
getFactoryin interfaceGremlinScriptEngine- Specified by:
getFactoryin interfaceScriptEngine- Overrides:
getFactoryin classorg.codehaus.groovy.jsr223.GroovyScriptEngineImpl
-
compile
- Specified by:
compilein interfaceCompilable- Overrides:
compilein classorg.codehaus.groovy.jsr223.GroovyScriptEngineImpl- Throws:
ScriptException
-
compile
- Specified by:
compilein interfaceCompilable- Overrides:
compilein classorg.codehaus.groovy.jsr223.GroovyScriptEngineImpl- Throws:
ScriptException
-
invokeFunction
public Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException - Specified by:
invokeFunctionin interfaceInvocable- Overrides:
invokeFunctionin classorg.codehaus.groovy.jsr223.GroovyScriptEngineImpl- Throws:
ScriptExceptionNoSuchMethodException
-
invokeMethod
public Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException - Specified by:
invokeMethodin interfaceInvocable- Overrides:
invokeMethodin classorg.codehaus.groovy.jsr223.GroovyScriptEngineImpl- Throws:
ScriptExceptionNoSuchMethodException
-
getInterface
- Specified by:
getInterfacein interfaceInvocable- Overrides:
getInterfacein classorg.codehaus.groovy.jsr223.GroovyScriptEngineImpl
-
getInterface
- Specified by:
getInterfacein interfaceInvocable- Overrides:
getInterfacein classorg.codehaus.groovy.jsr223.GroovyScriptEngineImpl
-
getClassCacheLongRunCompilationCount
public long getClassCacheLongRunCompilationCount()Gets the number of compilations that extended beyond theexpectedCompilationTime. -
getClassCacheEstimatedSize
public long getClassCacheEstimatedSize()Gets the estimated size of the class cache for compiled scripts. -
getClassCacheAverageLoadPenalty
public double getClassCacheAverageLoadPenalty()Gets the average time spent compiling new scripts. -
getClassCacheEvictionCount
public long getClassCacheEvictionCount()Gets the number of times a script compiled to a class has been evicted from the cache. -
getClassCacheEvictionWeight
public long getClassCacheEvictionWeight()Gets the sum of the weights of evicted entries from the class cache. -
getClassCacheHitCount
public long getClassCacheHitCount()Gets the number of times cache look up for a compiled script returned a cached value. -
getClassCacheHitRate
public double getClassCacheHitRate()Gets the hit rate of the class cache. -
getClassCacheLoadCount
public long getClassCacheLoadCount()Gets the total number of times the cache lookup method attempted to compile new scripts. -
getClassCacheLoadFailureCount
public long getClassCacheLoadFailureCount()Gets the total number of times the cache lookup method failed to compile a new script. -
getClassCacheLoadFailureRate
public double getClassCacheLoadFailureRate()Gets the ratio of script compilation attempts that failed. -
getClassCacheLoadSuccessCount
public long getClassCacheLoadSuccessCount()Gets the total number of times the cache lookup method succeeded to compile a new script. -
getClassCacheMissCount
public long getClassCacheMissCount()Gets the total number of times the cache lookup method returned a newly compiled script. -
getClassCacheMissRate
public double getClassCacheMissRate()Gets the ratio of script compilation attempts that were misses. -
getClassCacheRequestCount
public long getClassCacheRequestCount()Gets the total number of times the cache lookup method returned a cached or uncached value. -
getClassCacheTotalLoadTime
public long getClassCacheTotalLoadTime()Gets the total number of nanoseconds that the cache spent compiling scripts. -
getParentLoader
-