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 Details

  • Constructor Details

    • GremlinGroovyScriptEngine

      public GremlinGroovyScriptEngine()
      Creates a new instance using no Customizer.
    • GremlinGroovyScriptEngine

      public GremlinGroovyScriptEngine(Customizer... customizers)
  • Method Details

    • getPlugins

      public Set getPlugins()
      Get the list of loaded plugins.
    • reset

      public void reset()
      Resets the entire GremlinGroovyScriptEngine by clearing script caches, recreating the classloader, clearing bindings.
    • getScriptContext

      protected ScriptContext getScriptContext(Bindings nn)
      Creates the ScriptContext using a GremlinScriptContext which avoids a significant amount of additional object creation on script evaluation.
      Overrides:
      getScriptContext in class AbstractScriptEngine
    • eval

      public Object eval(Reader reader, ScriptContext context) throws ScriptException
      Specified by:
      eval in interface ScriptEngine
      Overrides:
      eval in class org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
      Throws:
      ScriptException
    • eval

      public Object eval(String script, ScriptContext context) throws ScriptException
      Specified by:
      eval in interface ScriptEngine
      Overrides:
      eval in class org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
      Throws:
      ScriptException
    • createBindings

      public Bindings createBindings()
      Create bindings to be used by this ScriptEngine. In this case, SimpleBindings are returned.
      Specified by:
      createBindings in interface ScriptEngine
      Overrides:
      createBindings in class org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
    • getFactory

      public GremlinScriptEngineFactory getFactory()
      Specified by:
      getFactory in interface GremlinScriptEngine
      Specified by:
      getFactory in interface ScriptEngine
      Overrides:
      getFactory in class org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
    • compile

      public CompiledScript compile(String scriptSource) throws ScriptException
      Specified by:
      compile in interface Compilable
      Overrides:
      compile in class org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
      Throws:
      ScriptException
    • compile

      public CompiledScript compile(Reader reader) throws ScriptException
      Specified by:
      compile in interface Compilable
      Overrides:
      compile in class org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
      Throws:
      ScriptException
    • invokeFunction

      public Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException
      Specified by:
      invokeFunction in interface Invocable
      Overrides:
      invokeFunction in class org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
      Throws:
      ScriptException
      NoSuchMethodException
    • invokeMethod

      public Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException
      Specified by:
      invokeMethod in interface Invocable
      Overrides:
      invokeMethod in class org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
      Throws:
      ScriptException
      NoSuchMethodException
    • getInterface

      public <T> T getInterface(Class<T> clazz)
      Specified by:
      getInterface in interface Invocable
      Overrides:
      getInterface in class org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
    • getInterface

      public <T> T getInterface(Object thiz, Class<T> clazz)
      Specified by:
      getInterface in interface Invocable
      Overrides:
      getInterface in class org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
    • getClassCacheLongRunCompilationCount

      public long getClassCacheLongRunCompilationCount()
      Gets the number of compilations that extended beyond the expectedCompilationTime.
    • 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

      protected ClassLoader getParentLoader()