本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy类的典型用法代码示例。如果您正苦于以下问题:Java HaltedTraverserStrategy类的具体用法?Java HaltedTraverserStrategy怎么用?Java HaltedTraverserStrategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HaltedTraverserStrategy类属于org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration包,在下文中一共展示了HaltedTraverserStrategy类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldReturnDetachedElements
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy; //导入依赖的package包/类
@Test
public void shouldReturnDetachedElements() {
final Graph graph = TinkerFactory.createModern();
final GraphTraversalSource g = graph.traversal().withComputer().withStrategies(HaltedTraverserStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
put(HaltedTraverserStrategy.HALTED_TRAVERSER_FACTORY, DetachedFactory.class.getCanonicalName());
}})));
g.V().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(DetachedVertexProperty.class, vertexProperty.getClass()));
g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass()));
g.V().out().outE().forEachRemaining(edge -> assertEquals(DetachedEdge.class, edge.getClass()));
g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(DetachedProperty.class, property.getClass()));
g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass()));
g.V().out().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
g.V().out().out().path().forEachRemaining(path -> assertEquals(DetachedPath.class, path.getClass()));
g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
// should handle nested collections
g.V().out().fold().next().forEach(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
}
示例2: shouldReturnReferenceElements
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy; //导入依赖的package包/类
@Test
public void shouldReturnReferenceElements() {
final Graph graph = TinkerFactory.createModern();
GraphTraversalSource g = graph.traversal().withComputer().withStrategies(HaltedTraverserStrategy.reference());
g.V().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(ReferenceVertexProperty.class, vertexProperty.getClass()));
g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass()));
g.V().out().outE().forEachRemaining(edge -> assertEquals(ReferenceEdge.class, edge.getClass()));
g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(ReferenceProperty.class, property.getClass()));
g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass()));
g.V().out().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
g.V().out().out().path().forEachRemaining(path -> assertEquals(ReferencePath.class, path.getClass()));
g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
// the default should be reference elements
g = graph.traversal().withComputer();
g.V().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(ReferenceVertexProperty.class, vertexProperty.getClass()));
g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass()));
g.V().out().outE().forEachRemaining(edge -> assertEquals(ReferenceEdge.class, edge.getClass()));
g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(ReferenceProperty.class, property.getClass()));
g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass()));
g.V().out().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
g.V().out().out().path().forEachRemaining(path -> assertEquals(ReferencePath.class, path.getClass()));
g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
// should handle nested collections
g.V().out().fold().next().forEach(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
}
示例3: DetachingIterator
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy; //导入依赖的package包/类
public DetachingIterator(final Traversal.Admin<?, E> traversal) {
this.inner = traversal.getEndStep();
this.haltedTraverserStrategy = (HaltedTraverserStrategy) traversal.getStrategies().toList().stream().filter(s -> s instanceof HaltedTraverserStrategy).findAny().orElse(
Boolean.valueOf(System.getProperty("is.testing", "false")) ?
HaltedTraverserStrategy.detached() :
HaltedTraverserStrategy.reference());
}
示例4: shouldReturnDetachedElements
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy; //导入依赖的package包/类
@Test
public void shouldReturnDetachedElements() {
final Graph graph = TinkerFactory.createModern();
final GraphTraversalSource g = graph.traversal().withComputer().withStrategies(HaltedTraverserStrategy.detached());
g.V().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(DetachedVertexProperty.class, vertexProperty.getClass()));
g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass()));
g.V().out().outE().forEachRemaining(edge -> assertEquals(DetachedEdge.class, edge.getClass()));
g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(DetachedProperty.class, property.getClass()));
g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass()));
g.V().out().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
g.V().out().out().path().forEachRemaining(path -> assertEquals(DetachedPath.class, path.getClass()));
g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
}
示例5: shouldReturnReferenceElements
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy; //导入依赖的package包/类
@Test
public void shouldReturnReferenceElements() {
final Graph graph = TinkerFactory.createModern();
GraphTraversalSource g = graph.traversal().withComputer().withStrategies(HaltedTraverserStrategy.reference());
g.V().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(ReferenceVertexProperty.class, vertexProperty.getClass()));
g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass()));
g.V().out().outE().forEachRemaining(edge -> assertEquals(ReferenceEdge.class, edge.getClass()));
g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(ReferenceProperty.class, property.getClass()));
g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass()));
g.V().out().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
g.V().out().out().path().forEachRemaining(path -> assertEquals(ReferencePath.class, path.getClass()));
g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
// the default should be reference elements
g = graph.traversal().withComputer();
g.V().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(ReferenceVertexProperty.class, vertexProperty.getClass()));
g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass()));
g.V().out().outE().forEachRemaining(edge -> assertEquals(ReferenceEdge.class, edge.getClass()));
g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(ReferenceProperty.class, property.getClass()));
g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass()));
g.V().out().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
g.V().out().out().path().forEachRemaining(path -> assertEquals(ReferencePath.class, path.getClass()));
g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(ReferenceVertex.class, vertex.getClass()));
}
示例6: TraverserIterator
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy; //导入依赖的package包/类
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());
}
示例7: loadState
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy; //导入依赖的package包/类
@Override
public void loadState(final Graph graph, final Configuration configuration) {
if (!configuration.containsKey(TRAVERSAL))
throw new IllegalArgumentException("The configuration does not have a traversal: " + TRAVERSAL);
this.traversal = PureTraversal.loadState(configuration, TRAVERSAL, graph);
if (!this.traversal.get().isLocked())
this.traversal.get().applyStrategies();
/// traversal is compiled and ready to be introspected
this.traversalMatrix = new TraversalMatrix<>(this.traversal.get());
// get any master-traversal halted traversers
this.haltedTraversers = TraversalVertexProgram.loadHaltedTraversers(configuration);
// if results will be serialized out, don't save halted traversers across the cluster
this.returnHaltedTraversers =
(this.traversal.get().getParent().asStep().getNextStep() instanceof ComputerResultStep || // if its just going to stream it out, don't distribute
this.traversal.get().getParent().asStep().getNextStep() instanceof EmptyStep || // same as above, but if using TraversalVertexProgramStep directly
(this.traversal.get().getParent().asStep().getNextStep() instanceof ProfileStep && // same as above, but needed for profiling
this.traversal.get().getParent().asStep().getNextStep().getNextStep() instanceof ComputerResultStep));
// determine how to store halted traversers
this.haltedTraverserStrategy = ((HaltedTraverserStrategy) this.traversal.get().getStrategies().toList()
.stream()
.filter(strategy -> strategy instanceof HaltedTraverserStrategy)
.findAny()
.orElse(HaltedTraverserStrategy.reference()));
// register traversal side-effects in memory
this.memoryComputeKeys.addAll(MemoryTraversalSideEffects.getMemoryComputeKeys(this.traversal.get()));
// register MapReducer memory compute keys
for (final MapReducer<?, ?, ?, ?, ?> mapReducer : TraversalHelper.getStepsOfAssignableClassRecursively(MapReducer.class, this.traversal.get())) {
this.mapReducers.add(mapReducer.getMapReduce());
this.memoryComputeKeys.add(MemoryComputeKey.of(mapReducer.getMapReduce().getMemoryKey(), Operator.assign, false, false));
}
// register memory computing steps that use memory compute keys
for (final MemoryComputing<?> memoryComputing : TraversalHelper.getStepsOfAssignableClassRecursively(MemoryComputing.class, this.traversal.get())) {
this.memoryComputeKeys.add(memoryComputing.getMemoryComputeKey());
}
// register profile steps (TODO: try to hide this)
for (final ProfileStep profileStep : TraversalHelper.getStepsOfAssignableClassRecursively(ProfileStep.class, this.traversal.get())) {
this.traversal.get().getSideEffects().register(profileStep.getId(), new MutableMetricsSupplier(profileStep.getPreviousStep()), ProfileStep.ProfileBiOperator.instance());
}
// register TraversalVertexProgram specific memory compute keys
this.memoryComputeKeys.add(MemoryComputeKey.of(VOTE_TO_HALT, Operator.and, false, true));
this.memoryComputeKeys.add(MemoryComputeKey.of(HALTED_TRAVERSERS, Operator.addAll, false, false));
this.memoryComputeKeys.add(MemoryComputeKey.of(ACTIVE_TRAVERSERS, Operator.addAll, true, true));
this.memoryComputeKeys.add(MemoryComputeKey.of(MUTATED_MEMORY_KEYS, Operator.addAll, false, true));
this.memoryComputeKeys.add(MemoryComputeKey.of(COMPLETED_BARRIERS, Operator.addAll, true, true));
}
示例8: processTraversers
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy; //导入依赖的package包/类
protected static void processTraversers(final PureTraversal<?, ?> traversal,
final TraversalMatrix<?, ?> traversalMatrix,
TraverserSet<Object> toProcessTraversers,
final TraverserSet<Object> remoteActiveTraversers,
final TraverserSet<Object> haltedTraversers,
final HaltedTraverserStrategy haltedTraverserStrategy) {
while (!toProcessTraversers.isEmpty()) {
final TraverserSet<Object> localActiveTraversers = new TraverserSet<>();
Step<Object, Object> previousStep = EmptyStep.instance();
Step<Object, Object> currentStep = EmptyStep.instance();
// these are traversers that are at the master traversal and will either halt here or be distributed back to the workers as needed
final Iterator<Traverser.Admin<Object>> traversers = toProcessTraversers.iterator();
while (traversers.hasNext()) {
final Traverser.Admin<Object> traverser = traversers.next();
traversers.remove();
traverser.set(DetachedFactory.detach(traverser.get(), true)); // why?
traverser.setSideEffects(traversal.get().getSideEffects());
if (traverser.isHalted())
haltedTraversers.add(haltedTraverserStrategy.halt(traverser));
else if (isRemoteTraverser(traverser, traversalMatrix)) // this is so that patterns like order().name work as expected. try and stay local as long as possible
remoteActiveTraversers.add(traverser.detach());
else {
currentStep = traversalMatrix.getStepById(traverser.getStepId());
if (!currentStep.getId().equals(previousStep.getId()) && !(previousStep instanceof EmptyStep)) {
while (previousStep.hasNext()) {
final Traverser.Admin<Object> result = previousStep.next();
if (result.isHalted())
haltedTraversers.add(haltedTraverserStrategy.halt(result));
else if (isRemoteTraverser(result, traversalMatrix))
remoteActiveTraversers.add(result.detach());
else
localActiveTraversers.add(result);
}
}
currentStep.addStart(traverser);
previousStep = currentStep;
}
}
if (!(currentStep instanceof EmptyStep)) {
while (currentStep.hasNext()) {
final Traverser.Admin<Object> traverser = currentStep.next();
if (traverser.isHalted())
haltedTraversers.add(haltedTraverserStrategy.halt(traverser));
else if (isRemoteTraverser(traverser, traversalMatrix))
remoteActiveTraversers.add(traverser.detach());
else
localActiveTraversers.add(traverser);
}
}
assert toProcessTraversers.isEmpty();
toProcessTraversers = localActiveTraversers;
}
}
示例9: loadState
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy; //导入依赖的package包/类
@Override
public void loadState(final Graph graph, final Configuration configuration) {
if (!configuration.containsKey(TRAVERSAL))
throw new IllegalArgumentException("The configuration does not have a traversal: " + TRAVERSAL);
this.traversal = PureTraversal.loadState(configuration, TRAVERSAL, graph);
if (!this.traversal.get().isLocked())
this.traversal.get().applyStrategies();
/// traversal is compiled and ready to be introspected
this.traversalMatrix = new TraversalMatrix<>(this.traversal.get());
// get any master-traversal halted traversers
this.haltedTraversers = TraversalVertexProgram.loadHaltedTraversers(configuration);
// if results will be serialized out, don't save halted traversers across the cluster
this.returnHaltedTraversers =
(this.traversal.get().getParent().asStep().getNextStep() instanceof ComputerResultStep || // if its just going to stream it out, don't distribute
this.traversal.get().getParent().asStep().getNextStep() instanceof EmptyStep || // same as above, but if using TraversalVertexProgramStep directly
(this.traversal.get().getParent().asStep().getNextStep() instanceof ProfileStep && // same as above, but needed for profiling
this.traversal.get().getParent().asStep().getNextStep().getNextStep() instanceof ComputerResultStep));
// determine how to store halted traversers
this.haltedTraverserStrategy = ((HaltedTraverserStrategy) this.traversal.get().getStrategies().toList()
.stream()
.filter(strategy -> strategy instanceof HaltedTraverserStrategy)
.findAny()
.orElse(HaltedTraverserStrategy.reference()));
// register traversal side-effects in memory
this.memoryComputeKeys.addAll(MemoryTraversalSideEffects.getMemoryComputeKeys(this.traversal.get()));
// register MapReducer memory compute keys
for (final MapReducer<?, ?, ?, ?, ?> mapReducer : TraversalHelper.getStepsOfAssignableClassRecursively(MapReducer.class, this.traversal.get())) {
this.mapReducers.add(mapReducer.getMapReduce());
this.memoryComputeKeys.add(MemoryComputeKey.of(mapReducer.getMapReduce().getMemoryKey(), Operator.assign, false, false));
}
// register memory computing steps that use memory compute keys
for (final MemoryComputing<?> memoryComputing : TraversalHelper.getStepsOfAssignableClassRecursively(MemoryComputing.class, this.traversal.get())) {
this.memoryComputeKeys.add(memoryComputing.getMemoryComputeKey());
}
// register profile steps (TODO: try to hide this)
for (final ProfileStep profileStep : TraversalHelper.getStepsOfAssignableClassRecursively(ProfileStep.class, this.traversal.get())) {
this.traversal.get().getSideEffects().register(profileStep.getId(), new MutableMetricsSupplier(profileStep.getPreviousStep()), ProfileStep.ProfileBiOperator.instance());
}
// register TraversalVertexProgram specific memory compute keys
this.memoryComputeKeys.add(MemoryComputeKey.of(VOTE_TO_HALT, Operator.and, false, true));
this.memoryComputeKeys.add(MemoryComputeKey.of(HALTED_TRAVERSERS, Operator.addAll, false, false));
this.memoryComputeKeys.add(MemoryComputeKey.of(ACTIVE_TRAVERSERS, Operator.addAll, true, true));
this.memoryComputeKeys.add(MemoryComputeKey.of(MUTATED_MEMORY_KEYS, Operator.addAll, false, true));
this.memoryComputeKeys.add(MemoryComputeKey.of(COMPLETED_BARRIERS, Operator.addAll, true, true));
// does the traversal need profile information
this.profile = !TraversalHelper.getStepsOfAssignableClassRecursively(ProfileStep.class, this.traversal.get()).isEmpty();
}
示例10: processTraversers
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy; //导入依赖的package包/类
protected static void processTraversers(final PureTraversal<?, ?> traversal,
final TraversalMatrix<?, ?> traversalMatrix,
TraverserSet<Object> toProcessTraversers,
final TraverserSet<Object> remoteActiveTraversers,
final TraverserSet<Object> haltedTraversers,
final HaltedTraverserStrategy haltedTraverserStrategy) {
while (!toProcessTraversers.isEmpty()) {
final TraverserSet<Object> localActiveTraversers = new TraverserSet<>();
Step<Object, Object> previousStep = EmptyStep.instance();
Step<Object, Object> currentStep = EmptyStep.instance();
// these are traversers that are at the master traversal and will either halt here or be distributed back to the workers as needed
final Iterator<Traverser.Admin<Object>> traversers = toProcessTraversers.iterator();
while (traversers.hasNext()) {
final Traverser.Admin<Object> traverser = traversers.next();
traversers.remove();
traverser.set(DetachedFactory.detach(traverser.get(), true)); // why?
traverser.setSideEffects(traversal.get().getSideEffects());
if (traverser.isHalted())
haltedTraversers.add(haltedTraverserStrategy.halt(traverser));
else if (isRemoteTraverser(traverser, traversalMatrix)) // this is so that patterns like order().name work as expected. try and stay local as long as possible
remoteActiveTraversers.add(traverser.detach());
else {
currentStep = traversalMatrix.getStepById(traverser.getStepId());
if (!currentStep.getId().equals(previousStep.getId()) && !(previousStep instanceof EmptyStep)) {
GraphComputing.atMaster(previousStep, true);
while (previousStep.hasNext()) {
final Traverser.Admin<Object> result = previousStep.next();
if (result.isHalted())
haltedTraversers.add(haltedTraverserStrategy.halt(result));
else if (isRemoteTraverser(result, traversalMatrix))
remoteActiveTraversers.add(result.detach());
else
localActiveTraversers.add(result);
}
}
currentStep.addStart(traverser);
previousStep = currentStep;
}
}
if (!(currentStep instanceof EmptyStep)) {
GraphComputing.atMaster(currentStep, true);
while (currentStep.hasNext()) {
final Traverser.Admin<Object> traverser = currentStep.next();
if (traverser.isHalted())
haltedTraversers.add(haltedTraverserStrategy.halt(traverser));
else if (isRemoteTraverser(traverser, traversalMatrix))
remoteActiveTraversers.add(traverser.detach());
else
localActiveTraversers.add(traverser);
}
}
assert toProcessTraversers.isEmpty();
toProcessTraversers = localActiveTraversers;
}
}