Fixed a gremlin server bug with global bindings

TraversalSources established in init scripts using the new plugin system 
weren't getting set to the GraphManager given the fact that the 
GremlinScriptEngineManager does runs the scripts when the GremlinScriptEngine 
is first initialized. By forcing the GremlinScriptEngine to initialize with a 
throw-away script the init scripts will execute. This is a bit of a hack - will 
consider other solutions for 3.3.0. CTR


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/956f3505
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/956f3505
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/956f3505

Branch: refs/heads/TINKERPOP-1602
Commit: 956f35056a967ecf1d8e74dc04bb227ba4823047
Parents: d08a68f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jan 25 09:24:49 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jan 25 09:24:49 2017 -0500

----------------------------------------------------------------------
 .../tinkerpop/gremlin/server/util/ServerGremlinExecutor.java   | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/956f3505/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
----------------------------------------------------------------------
diff --git 
a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
 
b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
index 2b2f1f1..199c9f8 100644
--- 
a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
+++ 
b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
@@ -145,6 +145,12 @@ public class ServerGremlinExecutor<T extends 
ScheduledExecutorService> {
 
         logger.info("Initialized GremlinExecutor and configured 
ScriptEngines.");
 
+        // force each scriptengine to process something so that the init 
scripts will fire (this is necessary if
+        // the GremlinExecutor is using the GremlinScriptEngineManager. this 
is a bit of hack, but it at least allows
+        // the global bindings to become available after the init scripts are 
run (DefaultGremlinScriptEngineManager
+        // runs the init scripts when the GremlinScriptEngine is created.
+        settings.scriptEngines.keySet().forEach(engineName -> 
gremlinExecutor.eval("1+1", engineName, Collections.emptyMap()).join());
+
         // script engine init may have altered the graph bindings or maybe 
even created new ones - need to
         // re-apply those references back
         gremlinExecutor.getGlobalBindings().entrySet().stream()

Reply via email to