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 2016/07/13 20:42:54 UTC

tinkerpop git commit: Deprecate the groovy ConcurrentBindings and move to core.

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 099ae6b7c -> 9158431c0


Deprecate the groovy ConcurrentBindings and move to core.

This class is quite re-usable. Now that gremlin-core holds ScriptEngine stuff, this Bindings implementation should be there too.


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

Branch: refs/heads/TINKERPOP-1278
Commit: 9158431c0611206b4f4084f507fb587c46b2592c
Parents: 099ae6b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Jul 13 16:41:59 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Jul 13 16:41:59 2016 -0400

----------------------------------------------------------------------
 .../gremlin/jsr223/ConcurrentBindings.java      | 42 ++++++++++++++++++++
 .../DefaultGremlinScriptEngineManager.java      |  5 ++-
 .../groovy/engine/ConcurrentBindings.java       |  2 +
 .../gremlin/groovy/engine/GremlinExecutor.java  |  7 ++--
 4 files changed, 51 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9158431c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ConcurrentBindings.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ConcurrentBindings.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ConcurrentBindings.java
new file mode 100644
index 0000000..bdadabc
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/ConcurrentBindings.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.jsr223;
+
+import javax.script.SimpleBindings;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A {@code Bindings} that can be accessed concurrently by multiple threads. It is needed in cases where "global"
+ * bindings are required for the {@link GremlinScriptEngine} and need to be shared across threads.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class ConcurrentBindings extends SimpleBindings {
+
+    public ConcurrentBindings() {
+        super(new ConcurrentHashMap<>());
+    }
+
+    public ConcurrentBindings(final Map<String, Object> m) {
+        // initialize the bindings first with a ConcurrentHashMap and then copy in the bindings
+        this();
+        this.putAll(m);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9158431c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultGremlinScriptEngineManager.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultGremlinScriptEngineManager.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultGremlinScriptEngineManager.java
index 2d0ba93..02dac59 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultGremlinScriptEngineManager.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/DefaultGremlinScriptEngineManager.java
@@ -22,7 +22,6 @@ import org.apache.tinkerpop.gremlin.util.CoreImports;
 
 import javax.script.Bindings;
 import javax.script.ScriptContext;
-import javax.script.SimpleBindings;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
@@ -89,7 +88,7 @@ public class DefaultGremlinScriptEngineManager implements GremlinScriptEngineMan
     /**
      * Global bindings associated with script engines created by this manager.
      */
-    private Bindings globalScope = new SimpleBindings();
+    private Bindings globalScope = new ConcurrentBindings();
 
     /**
      * The effect of calling this constructor is the same as calling
@@ -117,6 +116,8 @@ public class DefaultGremlinScriptEngineManager implements GremlinScriptEngineMan
 
     /**
      * Stores the specified {@code Bindings} as a global for all {@link GremlinScriptEngine} objects created by it.
+     * If the bindings are to be updated by multiple threads it is recommended that a {@link ConcurrentBindings}
+     * instance is supplied.
      *
      * @throws IllegalArgumentException if bindings is null.
      */

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9158431c/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ConcurrentBindings.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ConcurrentBindings.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ConcurrentBindings.java
index 0c12ea4..fe68773 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ConcurrentBindings.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/ConcurrentBindings.java
@@ -27,7 +27,9 @@ import java.util.concurrent.ConcurrentHashMap;
  * bindings are required for the {@code ScriptEngine}.
  *
  * @author Stephen Mallette (http://stephen.genoprime.com)
+ * @deprecated As of release 3.2.2, replaced by {@link org.apache.tinkerpop.gremlin.jsr223.ConcurrentBindings}.
  */
+@Deprecated
 public class ConcurrentBindings extends SimpleBindings {
 
     public ConcurrentBindings() {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9158431c/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 d70ff3d..0af5ca5 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
@@ -504,7 +504,7 @@ public class GremlinExecutor implements AutoCloseable {
         private BiConsumer<Bindings, Throwable> afterFailure = (b, e) -> {
         };
         private List<List<String>> use = new ArrayList<>();
-        private Bindings globalBindings = new ConcurrentBindings();
+        private Bindings globalBindings = new org.apache.tinkerpop.gremlin.jsr223.ConcurrentBindings();
 
         private Builder() {
         }
@@ -532,10 +532,11 @@ public class GremlinExecutor implements AutoCloseable {
 
         /**
          * Bindings to apply to every script evaluated. Note that the entries of the supplied {@code Bindings} object
-         * will be copied into a newly created {@link ConcurrentBindings} object at the call of this method.
+         * will be copied into a newly created {@link org.apache.tinkerpop.gremlin.jsr223.ConcurrentBindings} object
+         * at the call of this method.
          */
         public Builder globalBindings(final Bindings bindings) {
-            this.globalBindings = new ConcurrentBindings(bindings);
+            this.globalBindings = new org.apache.tinkerpop.gremlin.jsr223.ConcurrentBindings(bindings);
             return this;
         }