You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/07/27 20:00:29 UTC

[9/9] incubator-tinkerpop git commit: Removed bindings promotion from GremlinExecutor.

Removed bindings promotion from GremlinExecutor.

The revised approach that simply takes values from a Map returned from the init script simplifies the initialization of global bindings and introduces new flexibility over the old more limited method of binding promotion.  As a result, binding promotion no longer needs to be supported as it really should not be the recommended way to deal with this issue.


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

Branch: refs/heads/master
Commit: 7286a909e5fc2be9c3444f6c51fe5e0a4d4b66b3
Parents: 59735db
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Jul 27 13:48:07 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Jul 27 13:48:07 2015 -0400

----------------------------------------------------------------------
 .../gremlin/groovy/engine/GremlinExecutor.java  | 31 +++-----------------
 .../groovy/engine/GremlinExecutorTest.java      | 11 +++----
 .../groovy/engine/GremlinExecutorInit.groovy    |  3 +-
 .../gremlin/server/op/session/Session.java      |  2 --
 .../server/util/ServerGremlinExecutor.java      |  4 ---
 5 files changed, 9 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7286a909/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
index bd549ea..99bf36f 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
@@ -82,7 +82,6 @@ public class GremlinExecutor implements AutoCloseable {
     private final Map<String, EngineSettings> settings;
     private final long scriptEvaluationTimeout;
     private final Bindings globalBindings;
-    private final Predicate<Map.Entry<String,Object>> promoteBinding;
     private final List<List<String>> use;
     private final ExecutorService executorService;
     private final ScheduledExecutorService scheduledExecutorService;
@@ -107,7 +106,6 @@ public class GremlinExecutor implements AutoCloseable {
         this.settings = builder.settings;
         this.scriptEvaluationTimeout = builder.scriptEvaluationTimeout;
         this.globalBindings = builder.globalBindings;
-        this.promoteBinding = builder.promoteBinding;
         this.enabledPlugins = builder.enabledPlugins;
         this.scriptEngines = createScriptEngines();
         this.suppliedExecutor = suppliedExecutor;
@@ -422,23 +420,12 @@ public class GremlinExecutor implements AutoCloseable {
                         // evaluate init scripts with hard reference so as to ensure it doesn't get garbage collected
                         bindings.put(GremlinGroovyScriptEngine.KEY_REFERENCE_TYPE, GremlinGroovyScriptEngine.REFERENCE_TYPE_HARD);
 
-                        // todo: drop the "old method" in 3.1.0
-                        // the returned object should be a Map of initialized global bindings - this is in contrast
-                        // to the older method of scanning bindings for certain types/keys to promote.  the reason
-                        // for this change has to do with CompileStatic/TypeChecked "secure" configurations that
-                        // require the defined variables to be typed.  Under that scenario they are not "unresolved"
-                        // and thus don't get set to bindings automatically by the InvokerHelper.
+                        // the returned object should be a Map of initialized global bindings
                         final Object initializedBindings = se.eval(p.getValue1(), bindings, language);
-                        if (initializedBindings != null && initializedBindings instanceof Map) {
+                        if (initializedBindings != null && initializedBindings instanceof Map)
                             globalBindings.putAll((Map) initializedBindings);
-                        } else {
-                            // re-assign graph bindings back to global bindings and grab TraversalSource creations.
-                            // prevent assignment of non-graph implementations just in case someone tries to overwrite
-                            // them in the init
-                            bindings.entrySet().stream()
-                                    .filter(promoteBinding)
-                                    .forEach(kv -> globalBindings.put(kv.getKey(), kv.getValue()));
-                        }
+                        else
+                            logger.warn("Initialization script {} did not return a Map - no global bindings specified", p.getValue0());
 
                         logger.info("Initialized {} ScriptEngine with {}", language, p.getValue0());
                     } catch (ScriptException sx) {
@@ -482,7 +469,6 @@ public class GremlinExecutor implements AutoCloseable {
         };
         private List<List<String>> use = new ArrayList<>();
         private Bindings globalBindings = new SimpleBindings();
-        private Predicate<Map.Entry<String,Object>> promoteBinding = kv -> false;
 
         private Builder() {
         }
@@ -509,15 +495,6 @@ public class GremlinExecutor implements AutoCloseable {
         }
 
         /**
-         * A predicate applied to the binding list to determine if it should be promoted to a "global" binding
-         * that should be tied to every script.
-         */
-        public Builder promoteBindings(final Predicate<Map.Entry<String,Object>> promoteBinding) {
-            this.promoteBinding = promoteBinding;
-            return this;
-        }
-
-        /**
          * Bindings to apply to every script evaluated.
          */
         public Builder globalBindings(final Bindings bindings) {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7286a909/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
index 1268a3e..1c164da 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java
@@ -412,23 +412,20 @@ public class GremlinExecutorTest {
     }
 
     @Test
-    public void shouldInitializeWithScriptAndPromoteBinding() throws Exception {
+    public void shouldInitializeWithScriptAndMakeGlobalBinding() throws Exception {
         final GremlinExecutor gremlinExecutor = GremlinExecutor.build()
                 .addEngineSettings("gremlin-groovy",
                         Collections.emptyList(),
                         Collections.emptyList(),
                         Arrays.asList(PATHS.get("GremlinExecutorInit.groovy")),
                         Collections.emptyMap())
-                .promoteBindings(kv -> kv.getValue() instanceof Set)
                 .create();
 
         assertEquals(2, gremlinExecutor.eval("add(1,1)").get());
-        assertThat(gremlinExecutor.getGlobalBindings().keySet(), contains("someSet"));
-        assertThat(gremlinExecutor.getGlobalBindings().keySet(), not(contains("someMap")));
+        assertThat(gremlinExecutor.getGlobalBindings().keySet(), not(contains("someSet")));
+        assertThat(gremlinExecutor.getGlobalBindings().keySet(), contains("name"));
 
-        final Set<String> s = (Set<String>) gremlinExecutor.getGlobalBindings().get("someSet");
-        assertThat(s, contains("test"));
-        assertEquals(1, s.size());
+        assertEquals("stephen", gremlinExecutor.getGlobalBindings().get("name"));
 
         gremlinExecutor.close();
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7286a909/gremlin-groovy/src/test/resources/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorInit.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/resources/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorInit.groovy b/gremlin-groovy/src/test/resources/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorInit.groovy
index db046b0..6f92355 100644
--- a/gremlin-groovy/src/test/resources/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorInit.groovy
+++ b/gremlin-groovy/src/test/resources/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorInit.groovy
@@ -19,5 +19,4 @@
 def add(x, y) { x + y }
 
 someSet = ["test"] as Set
-someMap = [name:"stephen"]
-""
\ No newline at end of file
+[name:"stephen"]

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7286a909/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
index 7c5bc54..0c2c1c0 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java
@@ -135,8 +135,6 @@ public class Session {
                 })
                 .enabledPlugins(new HashSet<>(settings.plugins))
                 .globalBindings(graphManager.getAsBindings())
-                .promoteBindings(kv -> kv.getValue() instanceof Graph
-                        || kv.getValue() instanceof TraversalSource)
                 .executorService(executor)
                 .scheduledExecutorService(scheduledExecutorService);
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7286a909/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 02a763a..a3a2175 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
@@ -95,7 +95,6 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService> {
 
         logger.info("Initialized Gremlin thread pool.  Threads in pool named with pattern gremlin-*");
 
-        // todo: deprecate promoteBindings in 3.1.0
         final GremlinExecutor.Builder gremlinExecutorBuilder = GremlinExecutor.build()
                 .scriptEvaluationTimeout(settings.scriptEvaluationTimeout)
                 .afterFailure((b, e) -> graphManager.rollbackAll())
@@ -103,9 +102,6 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService> {
                 .afterTimeout(b -> graphManager.rollbackAll())
                 .enabledPlugins(new HashSet<>(settings.plugins))
                 .globalBindings(graphManager.getAsBindings())
-                .promoteBindings(kv -> kv.getValue() instanceof Graph
-                        || kv.getValue() instanceof TraversalSource
-                        || kv.getValue() instanceof LifeCycleHook)
                 .executorService(this.gremlinExecutorService)
                 .scheduledExecutorService(this.scheduledExecutorService);