public static String traversalStrategiesString(final TraversalStrategies traversalStrategies) { return "strategies" + traversalStrategies.toList(); }
public TraverserIterator(final Traversal.Admin traversal) { this.traversal = traversal; this.barrierSize = traversal.getTraverserRequirements().contains(TraverserRequirement.ONE_BULK) ? 1 : 1000; this.haltedTraverserStrategy = traversal.getStrategies().getStrategy(HaltedTraverserStrategy.class).orElse( Boolean.valueOf(System.getProperty("is.testing", "false")) ? HaltedTraverserStrategy.detached() : HaltedTraverserStrategy.reference()); }
public static void addRequirements(final TraversalStrategies traversalStrategies, final TraverserRequirement... requirements) { RequirementsStrategy strategy = (RequirementsStrategy) traversalStrategies.toList().stream().filter(s -> s instanceof RequirementsStrategy).findAny().orElse(null); if (null == strategy) { strategy = new RequirementsStrategy(); traversalStrategies.addStrategies(strategy); } else { final RequirementsStrategy cloneStrategy = new RequirementsStrategy(); cloneStrategy.requirements.addAll(strategy.requirements); strategy = cloneStrategy; traversalStrategies.addStrategies(strategy); } Collections.addAll(strategy.requirements, requirements); }
public SparqlTraversalSource(final RemoteConnection connection) { this(EmptyGraph.instance(), TraversalStrategies.GlobalCache.getStrategies(EmptyGraph.class).clone()); this.connection = connection; this.strategies.addStrategies(new RemoteStrategy(connection)); }
@Override public TraversalVertexProgram generateProgram(final Graph graph, final Memory memory) { final Traversal.Admin<?, ?> computerSpecificTraversal = this.computerTraversal.getPure(); final TraversalStrategies computerSpecificStrategies = this.getTraversal().getStrategies().clone(); IteratorUtils.filter(TraversalStrategies.GlobalCache.getStrategies(graph.getClass()).toList(), s -> s instanceof TraversalStrategy.ProviderOptimizationStrategy).forEach(computerSpecificStrategies::addStrategies); computerSpecificTraversal.setStrategies(computerSpecificStrategies); computerSpecificTraversal.setSideEffects(new MemoryTraversalSideEffects(this.getTraversal().getSideEffects())); computerSpecificTraversal.setParent(this); final TraversalVertexProgram.Builder builder = TraversalVertexProgram.build().traversal(computerSpecificTraversal); if (memory.exists(TraversalVertexProgram.HALTED_TRAVERSERS)) builder.haltedTraversers(memory.get(TraversalVertexProgram.HALTED_TRAVERSERS)); return builder.create(graph); }
.clone(); if (graphStrategies.getStrategy(EventStrategy.class) != null) graphStrategies.removeStrategies(EventStrategy.class); graphStrategies.addStrategies(EventStrategy.build().addListener(mutationListener).create()); TraversalStrategies.GlobalCache.registerStrategies(StandardJanusGraph.class, graphStrategies); mutationListener.setGraph(this);
/** * {@inheritDoc} * * @deprecated As of release 3.3.5, replaced by {@link AnonymousTraversalSource#withRemote(RemoteConnection)}. * @see <a href="https://issues.apache.org/jira/browse/TINKERPOP-2078">TINKERPOP-2078</a> */ @Override @Deprecated public GraphTraversalSource withRemote(final RemoteConnection connection) { // check if someone called withRemote() more than once, so just release resources on the initial // connection as you can't have more than one. maybe better to toss IllegalStateException?? if (this.connection != null) throw new IllegalStateException(String.format("TraversalSource already configured with a RemoteConnection [%s]", connection)); final GraphTraversalSource clone = this.clone(); clone.connection = connection; clone.getStrategies().addStrategies(new RemoteStrategy(connection)); return clone; }
private synchronized JanusGraph newJanusGraph(boolean batchLoading){ JanusGraph JanusGraph = configureGraph(batchLoading); buildJanusIndexes(JanusGraph); JanusGraph.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK); if (!strategiesApplied.getAndSet(true)) { TraversalStrategies strategies = TraversalStrategies.GlobalCache.getStrategies(StandardJanusGraph.class); strategies = strategies.clone().addStrategies(new JanusPreviousPropertyStepStrategy()); //TODO: find out why Tinkerpop added these strategies. They result in many NoOpBarrier steps which slowed down our queries so we had to remove them. strategies.removeStrategies(PathRetractionStrategy.class, LazyBarrierStrategy.class); TraversalStrategies.GlobalCache.registerStrategies(StandardJanusGraph.class, strategies); TraversalStrategies.GlobalCache.registerStrategies(StandardJanusGraphTx.class, strategies); } return JanusGraph; }
/** * Remove an arbitrary collection of {@link TraversalStrategy} classes from the traversal source. * * @param traversalStrategyClasses a collection of traversal strategy classes to remove * @return a new traversal source with updated strategies */ @SuppressWarnings({"unchecked", "varargs"}) public default TraversalSource withoutStrategies(final Class<? extends TraversalStrategy>... traversalStrategyClasses) { final TraversalSource clone = this.clone(); clone.getStrategies().removeStrategies(traversalStrategyClasses); clone.getBytecode().addSource(TraversalSource.Symbols.withoutStrategies, traversalStrategyClasses); return clone; }
@SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException") public SparqlTraversalSource clone() { try { final SparqlTraversalSource clone = (SparqlTraversalSource) super.clone(); clone.strategies = this.strategies.clone(); clone.bytecode = this.bytecode.clone(); return clone; } catch (final CloneNotSupportedException e) { throw new IllegalStateException(e.getMessage(), e); } }
if (this.locked) throw Traversal.Exceptions.traversalIsLocked(); TraversalHelper.reIdSteps(this.stepPosition, this); this.strategies.applyStrategies(this); boolean hasGraph = null != this.graph; for (int i = 0, j = this.steps.size(); i < j; i++) { // "foreach" can lead to ConcurrentModificationExceptions
.clone(); if (graphStrategies.getStrategy(EventStrategy.class) != null) graphStrategies.removeStrategies(EventStrategy.class); graphStrategies.addStrategies(EventStrategy.build().addListener(mutationListener).create()); TraversalStrategies.GlobalCache.registerStrategies(StandardJanusGraph.class, graphStrategies); mutationListener.setGraph(this);
@Override public SparqlTraversalSource withRemote(final RemoteConnection connection) { try { // check if someone called withRemote() more than once, so just release resources on the initial // connection as you can't have more than one. maybe better to toss IllegalStateException?? if (this.connection != null) this.connection.close(); } catch (Exception ignored) { // not sure there's anything to do here } this.connection = connection; final TraversalSource clone = this.clone(); clone.getStrategies().addStrategies(new RemoteStrategy(connection)); return (SparqlTraversalSource) clone; }
public GraphTraversalSource(final RemoteConnection connection) { this(EmptyGraph.instance(), TraversalStrategies.GlobalCache.getStrategies(EmptyGraph.class).clone()); this.connection = connection; this.strategies.addStrategies(new RemoteStrategy(connection)); }
@Override public TraversalVertexProgram generateProgram(final Graph graph, final Memory memory) { final Traversal.Admin<?, ?> computerSpecificTraversal = this.computerTraversal.getPure(); final TraversalStrategies computerSpecificStrategies = this.getTraversal().getStrategies().clone(); IteratorUtils.filter(TraversalStrategies.GlobalCache.getStrategies(graph.getClass()).toList(), s -> s instanceof TraversalStrategy.ProviderOptimizationStrategy).forEach(computerSpecificStrategies::addStrategies); computerSpecificTraversal.setStrategies(computerSpecificStrategies); computerSpecificTraversal.setSideEffects(new MemoryTraversalSideEffects(this.getTraversal().getSideEffects())); computerSpecificTraversal.setParent(this); final TraversalVertexProgram.Builder builder = TraversalVertexProgram.build().traversal(computerSpecificTraversal); if (memory.exists(TraversalVertexProgram.HALTED_TRAVERSERS)) builder.haltedTraversers(memory.get(TraversalVertexProgram.HALTED_TRAVERSERS)); return builder.create(graph); }
traversal.removeStep(0); // remove GraphStep traversal.removeStep(traversal.getSteps().size() - 1); // remove ReducingBarrierStep traversal.setStrategies(traversal.clone().getStrategies().removeStrategies(ComputerVerificationStrategy.class, ComputerFinalizationStrategy.class)); // no longer a computer job, but parallel standard jobs
@SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException") public GraphTraversalSource clone() { try { final GraphTraversalSource clone = (GraphTraversalSource) super.clone(); clone.strategies = this.strategies.clone(); clone.bytecode = this.bytecode.clone(); return clone; } catch (final CloneNotSupportedException e) { throw new IllegalStateException(e.getMessage(), e); } }
if (this.locked) throw Traversal.Exceptions.traversalIsLocked(); TraversalHelper.reIdSteps(this.stepPosition, this); this.strategies.applyStrategies(this); boolean hasGraph = null != this.graph; for (int i = 0, j = this.steps.size(); i < j; i++) { // "foreach" can lead to ConcurrentModificationExceptions
/** * Return the {@link TraversalStrategy} instance associated with the provided class. * * @param traversalStrategyClass the class of the strategy to get * @param <T> the strategy class type * @return an optional containing the strategy instance or not */ public default <T extends TraversalStrategy> Optional<T> getStrategy(final Class<T> traversalStrategyClass) { return (Optional) toList().stream().filter(s -> traversalStrategyClass.isAssignableFrom(s.getClass())).findAny(); }
public static <A> void addSideEffect(final TraversalStrategies traversalStrategies, final String key, final A value, final BinaryOperator<A> reducer) { SideEffectStrategy strategy = (SideEffectStrategy) traversalStrategies.toList().stream().filter(s -> s instanceof SideEffectStrategy).findAny().orElse(null); if (null == strategy) { strategy = new SideEffectStrategy(); traversalStrategies.addStrategies(strategy); } else { final SideEffectStrategy cloneStrategy = new SideEffectStrategy(); cloneStrategy.sideEffects.addAll(strategy.sideEffects); strategy = cloneStrategy; traversalStrategies.addStrategies(strategy); } strategy.sideEffects.add(new Triplet<>(key, null == value ? null : value instanceof Supplier ? (Supplier) value : new ConstantSupplier<>(value), reducer)); } }