Undeprecated ScriptEngineCache We tend to use vanilla non-Gremlin-enabled ScriptEngine instances for various things and since the GremlinScriptEngineManager only loads Gremlin-enabled ones we can't use it for everything. I still dont' wonder if ScriptEngineCache can't go away, but it's not gonna happen today.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/26b8556f Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/26b8556f Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/26b8556f Branch: refs/heads/TINKERPOP-1278 Commit: 26b8556f69958159ee7bd90c904ca093e697b6f8 Parents: 46958f2 Author: Stephen Mallette <sp...@genoprime.com> Authored: Tue Jul 12 16:56:08 2016 -0400 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Tue Jul 12 16:56:08 2016 -0400 ---------------------------------------------------------------------- .../strategy/creation/TranslationStrategy.java | 4 ++-- .../gremlin/process/traversal/util/ScriptTraversal.java | 4 ++-- .../process/traversal/util/TraversalScriptFunction.java | 4 ++-- .../tinkerpop/gremlin/util/ScriptEngineCache.java | 12 +++++++----- .../gremlin/util/function/ScriptEngineLambda.java | 4 ++-- .../java/translator/PythonTranslatorProvider.java | 5 +---- .../java/translator/groovy/PythonGroovyTranslator.java | 3 +-- .../java/translator/jython/PythonJythonTranslator.java | 3 +-- .../gremlin/python/driver/RESTRemoteConnectionTest.java | 3 +-- .../gremlin/python/jsr223/JythonScriptEngineSetup.java | 3 +-- 10 files changed, 20 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/26b8556f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/creation/TranslationStrategy.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/creation/TranslationStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/creation/TranslationStrategy.java index b290af0..98f549d 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/creation/TranslationStrategy.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/creation/TranslationStrategy.java @@ -19,6 +19,7 @@ package org.apache.tinkerpop.gremlin.process.traversal.strategy.creation; +import org.apache.tinkerpop.gremlin.jsr223.SingleGremlinScriptEngineManager; import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph; import org.apache.tinkerpop.gremlin.process.traversal.Step; import org.apache.tinkerpop.gremlin.process.traversal.Translator; @@ -28,7 +29,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy; import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep; import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy; import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; -import org.apache.tinkerpop.gremlin.util.ScriptEngineCache; import javax.script.Bindings; import javax.script.ScriptContext; @@ -64,7 +64,7 @@ public class TranslationStrategy extends AbstractTraversalStrategy<TraversalStra } else if (this.translator instanceof Translator.ScriptTranslator) { try { // script based translation - final ScriptEngine scriptEngine = ScriptEngineCache.get(this.translator.getTargetLanguage()); + final ScriptEngine scriptEngine = SingleGremlinScriptEngineManager.get(this.translator.getTargetLanguage()); final Bindings bindings = scriptEngine.createBindings(); scriptEngine.getContext().getBindings(ScriptContext.ENGINE_SCOPE).forEach(bindings::put); bindings.put(this.translator.getTraversalSource().toString(), this.traversalSource); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/26b8556f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/ScriptTraversal.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/ScriptTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/ScriptTraversal.java index 236ff80..d1933ad 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/ScriptTraversal.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/ScriptTraversal.java @@ -19,13 +19,13 @@ package org.apache.tinkerpop.gremlin.process.traversal.util; +import org.apache.tinkerpop.gremlin.jsr223.SingleGremlinScriptEngineManager; import org.apache.tinkerpop.gremlin.process.remote.traversal.strategy.decoration.RemoteStrategy; import org.apache.tinkerpop.gremlin.process.traversal.Translator; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource; import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy; import org.apache.tinkerpop.gremlin.process.traversal.strategy.creation.TranslationStrategy; -import org.apache.tinkerpop.gremlin.util.ScriptEngineCache; import javax.script.Bindings; import javax.script.ScriptEngine; @@ -77,7 +77,7 @@ public final class ScriptTraversal<S, E> extends DefaultTraversal<S, E> { public void applyStrategies() throws IllegalStateException { try { assert 0 == this.getSteps().size(); - final ScriptEngine engine = ScriptEngineCache.get(this.scriptEngine); + final ScriptEngine engine = SingleGremlinScriptEngineManager.get(this.scriptEngine); final Bindings engineBindings = engine.createBindings(); final List<TraversalStrategy<?>> strategyList = this.getStrategies().toList(); engineBindings.put(this.alias, this.factory.createTraversalSource(this.graph).withStrategies(strategyList.toArray(new TraversalStrategy[strategyList.size()]))); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/26b8556f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalScriptFunction.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalScriptFunction.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalScriptFunction.java index 03e3521..fcd5408 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalScriptFunction.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalScriptFunction.java @@ -18,10 +18,10 @@ */ package org.apache.tinkerpop.gremlin.process.traversal.util; +import org.apache.tinkerpop.gremlin.jsr223.SingleGremlinScriptEngineManager; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.util.ScriptEngineCache; import javax.script.Bindings; import javax.script.ScriptEngine; @@ -51,7 +51,7 @@ public final class TraversalScriptFunction<S, E> implements Function<Graph, Trav public Traversal.Admin<S, E> apply(final Graph graph) { try { - final ScriptEngine engine = ScriptEngineCache.get(this.scriptEngineName); + final ScriptEngine engine = SingleGremlinScriptEngineManager.get(this.scriptEngineName); final Bindings engineBindings = engine.createBindings(); engineBindings.put("g", this.traversalSourceFactory.createTraversalSource(graph)); for (int i = 0; i < this.bindings.length; i = i + 2) { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/26b8556f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ScriptEngineCache.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ScriptEngineCache.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ScriptEngineCache.java index 9e942d9..1ce7d05 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ScriptEngineCache.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ScriptEngineCache.java @@ -18,8 +18,7 @@ */ package org.apache.tinkerpop.gremlin.util; -import org.apache.tinkerpop.gremlin.jsr223.DefaultGremlinScriptEngineManager; -import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngineManager; +import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine; import org.apache.tinkerpop.gremlin.jsr223.SingleGremlinScriptEngineManager; import javax.script.ScriptEngine; @@ -28,17 +27,20 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** + * A cache of standard {@code ScriptEngine} instances, instantiated by the standard {@code ScriptEngineManager}. + * These instances are not "Gremlin-enabled". See {@link SingleGremlinScriptEngineManager} for the analogous class + * that loads {@link GremlinScriptEngine} instances. + * * @author Daniel Kuppitz (http://gremlin.guru) - * @deprecated As of release 3.3.0, replaced by {@link SingleGremlinScriptEngineManager}. + * @author Stephen Mallette (http://stephen.genoprime.com) */ -@Deprecated public final class ScriptEngineCache { private ScriptEngineCache() {} public final static String DEFAULT_SCRIPT_ENGINE = "gremlin-groovy"; - private final static GremlinScriptEngineManager SCRIPT_ENGINE_MANAGER = new DefaultGremlinScriptEngineManager(); + private final static ScriptEngineManager SCRIPT_ENGINE_MANAGER = new ScriptEngineManager(); private final static Map<String, ScriptEngine> CACHED_ENGINES = new ConcurrentHashMap<>(); public static ScriptEngine get(final String engineName) { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/26b8556f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/function/ScriptEngineLambda.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/function/ScriptEngineLambda.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/function/ScriptEngineLambda.java index 20a622c..046d833 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/function/ScriptEngineLambda.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/function/ScriptEngineLambda.java @@ -18,7 +18,7 @@ */ package org.apache.tinkerpop.gremlin.util.function; -import org.apache.tinkerpop.gremlin.util.ScriptEngineCache; +import org.apache.tinkerpop.gremlin.jsr223.SingleGremlinScriptEngineManager; import javax.script.Bindings; import javax.script.ScriptEngine; @@ -43,7 +43,7 @@ public final class ScriptEngineLambda implements Function, Supplier, Consumer, P protected final String script; public ScriptEngineLambda(final String engineName, final String script) { - this.engine = ScriptEngineCache.get(engineName); + this.engine = SingleGremlinScriptEngineManager.get(engineName); this.script = script; } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/26b8556f/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonTranslatorProvider.java ---------------------------------------------------------------------- diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonTranslatorProvider.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonTranslatorProvider.java index 985e8bc..8b3ff5c 100644 --- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonTranslatorProvider.java +++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/PythonTranslatorProvider.java @@ -22,14 +22,11 @@ package org.apache.tinkerpop.gremlin.java.translator; import org.apache.commons.configuration.Configuration; import org.apache.tinkerpop.gremlin.AbstractGraphProvider; import org.apache.tinkerpop.gremlin.LoadGraphWith; -import org.apache.tinkerpop.gremlin.jsr223.SingleGremlinScriptEngineManager; import org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionComputerTest; import org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionTest; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.process.traversal.step.map.ProgramTest; import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ElementIdStrategyProcessTest; -import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategyProcessTest; -import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.PartitionStrategyProcessTest; import org.apache.tinkerpop.gremlin.python.jsr223.JythonScriptEngineSetup; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.VertexProperty; @@ -139,7 +136,7 @@ public abstract class PythonTranslatorProvider extends AbstractGraphProvider { //throw new VerificationException("This test current does not work with Gremlin-Python", EmptyTraversal.instance()); else { try { - SingleGremlinScriptEngineManager.getInstance().getEngineByName("gremlin-jython").eval(IMPORT_STATICS ? + ScriptEngineCache.get("jython").eval(IMPORT_STATICS ? "statics.load_statics(globals())" : "statics.unload_statics(globals())"); } catch (final ScriptException e) { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/26b8556f/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/groovy/PythonGroovyTranslator.java ---------------------------------------------------------------------- diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/groovy/PythonGroovyTranslator.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/groovy/PythonGroovyTranslator.java index eb11f7e..cd2c85c 100644 --- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/groovy/PythonGroovyTranslator.java +++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/groovy/PythonGroovyTranslator.java @@ -20,7 +20,6 @@ package org.apache.tinkerpop.gremlin.java.translator.groovy; import org.apache.tinkerpop.gremlin.java.translator.PythonTranslator; -import org.apache.tinkerpop.gremlin.jsr223.SingleGremlinScriptEngineManager; import org.apache.tinkerpop.gremlin.process.traversal.Bytecode; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.apache.tinkerpop.gremlin.util.ScriptEngineCache; @@ -55,7 +54,7 @@ public class PythonGroovyTranslator extends PythonTranslator { public String translate(final Bytecode bytecode) { final String traversal = super.translate(bytecode); try { - final ScriptEngine jythonEngine = SingleGremlinScriptEngineManager.getInstance().getEngineByName("gremlin-jython"); + final ScriptEngine jythonEngine = ScriptEngineCache.get("jython"); jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE) .put(this.traversalSource, jythonEngine.eval("RemoteGraph(GroovyTranslator(\"" + this.traversalSource + "\"), None).traversal()")); return jythonEngine.eval(traversal).toString(); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/26b8556f/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/jython/PythonJythonTranslator.java ---------------------------------------------------------------------- diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/jython/PythonJythonTranslator.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/jython/PythonJythonTranslator.java index 0b7d5b8..6637a2b 100644 --- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/jython/PythonJythonTranslator.java +++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/java/translator/jython/PythonJythonTranslator.java @@ -20,7 +20,6 @@ package org.apache.tinkerpop.gremlin.java.translator.jython; import org.apache.tinkerpop.gremlin.java.translator.PythonTranslator; -import org.apache.tinkerpop.gremlin.jsr223.SingleGremlinScriptEngineManager; import org.apache.tinkerpop.gremlin.process.traversal.Bytecode; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.apache.tinkerpop.gremlin.util.ScriptEngineCache; @@ -55,7 +54,7 @@ public class PythonJythonTranslator extends PythonTranslator { public String translate(final Bytecode bytecode) { final String traversal = super.translate(bytecode); try { - final ScriptEngine jythonEngine = SingleGremlinScriptEngineManager.getInstance().getEngineByName("gremlin-jython"); + final ScriptEngine jythonEngine = ScriptEngineCache.get("jython"); jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE) .put(this.traversalSource, jythonEngine.eval("RemoteGraph(JythonTranslator(\"" + this.traversalSource + "\"), None).traversal()")); return jythonEngine.eval(traversal).toString(); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/26b8556f/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java ---------------------------------------------------------------------- diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java index 056c1a6..640e5ef 100644 --- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java +++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java @@ -19,7 +19,6 @@ package org.apache.tinkerpop.gremlin.python.driver; -import org.apache.tinkerpop.gremlin.jsr223.SingleGremlinScriptEngineManager; import org.apache.tinkerpop.gremlin.python.jsr223.JythonScriptEngineSetup; import org.apache.tinkerpop.gremlin.server.GremlinServer; import org.apache.tinkerpop.gremlin.server.Settings; @@ -41,7 +40,7 @@ import static org.junit.Assert.assertTrue; */ public class RESTRemoteConnectionTest { - private static final ScriptEngine jython = SingleGremlinScriptEngineManager.getInstance().getEngineByName("gremlin-jython"); + private static final ScriptEngine jython = ScriptEngineCache.get("jython"); private final List<String> aliases = Arrays.asList("g", "j"); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/26b8556f/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java ---------------------------------------------------------------------- diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java index abe9dc9..8fe0c72 100644 --- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java +++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java @@ -19,7 +19,6 @@ package org.apache.tinkerpop.gremlin.python.jsr223; -import org.apache.tinkerpop.gremlin.jsr223.SingleGremlinScriptEngineManager; import org.apache.tinkerpop.gremlin.util.ScriptEngineCache; import javax.script.ScriptEngine; @@ -35,7 +34,7 @@ public class JythonScriptEngineSetup { public static void setup() { try { - final ScriptEngine jythonEngine = SingleGremlinScriptEngineManager.getInstance().getEngineByName("gremlin-jython"); + final ScriptEngine jythonEngine = ScriptEngineCache.get("jython"); jythonEngine.eval("import gremlin_python.statics"); jythonEngine.eval("from gremlin_python.process.traversal import *"); jythonEngine.eval("from gremlin_python.process.graph_traversal import *");