Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1758 [created] 528851411
TINKERPOP-1758 Apply RemoteStrategy before all DecorationStrategy instances Played around with a few ways to test this, but none seemed especially good. Everything I try to do seems fairly contrived or redundant. In the end, I ended up feeling like it was safe to just rely on the TraversalStrategies sorting system with posts/priors. Perhaps that is enough... Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/52885141 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/52885141 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/52885141 Branch: refs/heads/TINKERPOP-1758 Commit: 528851411c6494bf92f2f929324a79ba28a941b2 Parents: 6fbf130 Author: Stephen Mallette <sp...@genoprime.com> Authored: Mon Mar 5 13:18:35 2018 -0500 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Mon Mar 5 13:18:35 2018 -0500 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 1 + .../strategy/decoration/RemoteStrategy.java | 27 +++++++++++++++++++- .../process/traversal/TraversalStrategies.java | 22 ++++++++-------- 3 files changed, 38 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/52885141/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index b9f22e1..037d94c 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -27,6 +27,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima * Modified `GremlinDslProcessor` so that it generated the `getAnonymousTraversalClass()` method to return the DSL version of `__`. * Added the "Kitchen Sink" test data set. * Fixed deserialization of `P.not()` for GraphSON. +* Ensure that `RemoteStrategy` is applied before all other `DecorationStrategy` instances. * Added `idleConnectionTimeout` and `keepAliveInterval` to Gremlin Server that enables a "ping" and auto-close for seemingly dead clients. * Fixed a bug in `NumberHelper` that led to wrong min/max results if numbers exceeded the Integer limits. * Delayed setting of the request identifier until `RequestMessage` construction by the builder. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/52885141/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/strategy/decoration/RemoteStrategy.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/strategy/decoration/RemoteStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/strategy/decoration/RemoteStrategy.java index d1b14d5..f6e3ed6 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/strategy/decoration/RemoteStrategy.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/strategy/decoration/RemoteStrategy.java @@ -27,11 +27,22 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.ProfileSideEffectStep; 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.strategy.decoration.ConnectiveStrategy; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ElementIdStrategy; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.PartitionStrategy; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.RequirementsStrategy; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SideEffectStrategy; +import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy; import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.VerificationException; import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph; +import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.Optional; import java.util.Set; @@ -49,7 +60,21 @@ public final class RemoteStrategy extends AbstractTraversalStrategy<TraversalStr private static final RemoteStrategy INSTANCE = new RemoteStrategy(); private final Optional<RemoteConnection> remoteConnection; - private static final Set<Class<? extends DecorationStrategy>> POSTS = Collections.singleton(VertexProgramStrategy.class); + /** + * Should be applied before all {@link DecorationStrategy} instances. + */ + private static final Set<Class<? extends DecorationStrategy>> POSTS = new HashSet<Class<? extends DecorationStrategy>>() {{ + add(VertexProgramStrategy.class); + add(ConnectiveStrategy.class); + add(ElementIdStrategy.class); + add(EventStrategy.class); + add(HaltedTraverserStrategy.class); + add(PartitionStrategy.class); + add(RequirementsStrategy.class); + add(SackStrategy.class); + add(SideEffectStrategy.class); + add(SubgraphStrategy.class); + }}; private RemoteStrategy() { remoteConnection = Optional.empty(); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/52885141/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java index 63ae23f..c7ee5bf 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java @@ -141,9 +141,9 @@ public interface TraversalStrategies extends Serializable, Cloneable { }); //Add dependencies by category - List<Class<? extends TraversalStrategy>> strategiesInPreviousCategories = new ArrayList<>(); + final List<Class<? extends TraversalStrategy>> strategiesInPreviousCategories = new ArrayList<>(); for (Class<? extends TraversalStrategy> category : STRATEGY_CATEGORIES) { - Set<Class<? extends TraversalStrategy>> strategiesInThisCategory = MultiMap.get(strategiesByCategory, category); + final Set<Class<? extends TraversalStrategy>> strategiesInThisCategory = MultiMap.get(strategiesByCategory, category); for (Class<? extends TraversalStrategy> strategy : strategiesInThisCategory) { for (Class<? extends TraversalStrategy> previousStrategy : strategiesInPreviousCategories) { MultiMap.put(dependencyMap, strategy, previousStrategy); @@ -153,16 +153,16 @@ public interface TraversalStrategies extends Serializable, Cloneable { } //Finally sort via t-sort - List<Class<? extends TraversalStrategy>> unprocessedStrategyClasses = new ArrayList<>(strategies.stream().map(s -> s.getClass()).collect(Collectors.toSet())); - List<Class<? extends TraversalStrategy>> sortedStrategyClasses = new ArrayList<>(); - Set<Class<? extends TraversalStrategy>> seenStrategyClasses = new HashSet<>(); + final List<Class<? extends TraversalStrategy>> unprocessedStrategyClasses = new ArrayList<>(strategies.stream().map(s -> s.getClass()).collect(Collectors.toSet())); + final List<Class<? extends TraversalStrategy>> sortedStrategyClasses = new ArrayList<>(); + final Set<Class<? extends TraversalStrategy>> seenStrategyClasses = new HashSet<>(); while (!unprocessedStrategyClasses.isEmpty()) { - Class<? extends TraversalStrategy> strategy = unprocessedStrategyClasses.get(0); + final Class<? extends TraversalStrategy> strategy = unprocessedStrategyClasses.get(0); visit(dependencyMap, sortedStrategyClasses, seenStrategyClasses, unprocessedStrategyClasses, strategy); } - List<TraversalStrategy<?>> sortedStrategies = new ArrayList<>(); + final List<TraversalStrategy<?>> sortedStrategies = new ArrayList<>(); //We now have a list of sorted strategy classes for (Class<? extends TraversalStrategy> strategyClass : sortedStrategyClasses) { for (TraversalStrategy strategy : strategies) { @@ -172,12 +172,13 @@ public interface TraversalStrategies extends Serializable, Cloneable { } } - return sortedStrategies; } - - static void visit(Map<Class<? extends TraversalStrategy>, Set<Class<? extends TraversalStrategy>>> dependencyMap, List<Class<? extends TraversalStrategy>> sortedStrategyClasses, Set<Class<? extends TraversalStrategy>> seenStrategyClases, List<Class<? extends TraversalStrategy>> unprocessedStrategyClasses, Class<? extends TraversalStrategy> strategyClass) { + static void visit(final Map<Class<? extends TraversalStrategy>, Set<Class<? extends TraversalStrategy>>> dependencyMap, + final List<Class<? extends TraversalStrategy>> sortedStrategyClasses, + final Set<Class<? extends TraversalStrategy>> seenStrategyClases, + final List<Class<? extends TraversalStrategy>> unprocessedStrategyClasses, Class<? extends TraversalStrategy> strategyClass) { if (seenStrategyClases.contains(strategyClass)) { throw new IllegalStateException("Cyclic dependency between traversal strategies: [" + seenStrategyClases + ']'); @@ -195,7 +196,6 @@ public interface TraversalStrategies extends Serializable, Cloneable { } } - public static final class GlobalCache { private static final Map<Class<? extends Graph>, TraversalStrategies> GRAPH_CACHE = new HashMap<>();