Class GremlinLangScriptEngine
java.lang.Object
javax.script.AbstractScriptEngine
org.apache.tinkerpop.gremlin.jsr223.GremlinLangScriptEngine
- All Implemented Interfaces:
ScriptEngine,GremlinScriptEngine
A
GremlinScriptEngine implementation that evaluates Gremlin scripts using gremlin-language. As it
uses gremlin-language and thus the ANTLR parser, it is not capable of process arbitrary scripts as the
GremlinGroovyScriptEngine can and is therefore a more secure Gremlin evaluator. It is obviously restricted
to the capabilities of the ANTLR grammar so therefore syntax that includes things like lambdas are not supported.
As an internal note, technically, this is an incomplete implementation of the GremlinScriptEngine in the
traditional sense as a drop-in replacement for something like the GremlinGroovyScriptEngine. As a result,
this GremlinScriptEngine cannot pass the GremlinScriptEngineSuite tests in full. On the other hand,
this limitation is precisely what makes this implementation better from a security perspective. Ultimately, this
implementation represents the first step to changes in what it means to have a GremlinScriptEngine. In some
sense, there is question why a GremlinScriptEngine approach is necessary at all except for easily plugging
into the existing internals of Gremlin Server or more specifically the GremlinExecutor.
The engine includes a cache that can help spare repeated parsing of the same traversal. It is keyed to each
configuration of the GraphTraversalSource that initially requested its execution via the bindings given to
the eval method. Each cache is keyed on the original Gremlin string and holds the initialized parsed
traversal for its value. If that Gremlin string is matched again in the future, it will use the one from the cache
rather than parse again via the ANTLR grammar. In addition, if GValue instances were used in formation of
the traversal, it will substitute in new bindings given with the eval.-
Field Summary
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.GremlinLangScriptEngine(Customizer... customizers) -
Method Summary
Modifier and TypeMethodDescriptioneval(Reader reader, ScriptContext context) eval(String script, ScriptContext context) Gremlin scripts evaluated by the grammar must be bound to "g" and should evaluate to a "g" in theScriptContextthat is of typeTraversalSourceprotected ScriptContextCreates theScriptContextusing aGremlinScriptContextwhich avoids a significant amount of additional object creation on script evaluation.Methods 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
-
Constructor Details
-
GremlinLangScriptEngine
public GremlinLangScriptEngine()Creates a new instance using noCustomizer. -
GremlinLangScriptEngine
-
-
Method Details
-
getFactory
- Specified by:
getFactoryin interfaceGremlinScriptEngine- Specified by:
getFactoryin interfaceScriptEngine
-
eval
Gremlin scripts evaluated by the grammar must be bound to "g" and should evaluate to a "g" in theScriptContextthat is of typeTraversalSource- Specified by:
evalin interfaceScriptEngine- Throws:
ScriptException
-
eval
- Specified by:
evalin interfaceScriptEngine- Throws:
ScriptException
-
createBindings
- Specified by:
createBindingsin interfaceScriptEngine
-
getScriptContext
Creates theScriptContextusing aGremlinScriptContextwhich avoids a significant amount of additional object creation on script evaluation.- Overrides:
getScriptContextin classAbstractScriptEngine
-