当前位置: 首页>>代码示例>>Java>>正文


Java ProfileStep类代码示例

本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep的典型用法代码示例。如果您正苦于以下问题:Java ProfileStep类的具体用法?Java ProfileStep怎么用?Java ProfileStep使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProfileStep类属于org.apache.tinkerpop.gremlin.process.traversal.step.util包,在下文中一共展示了ProfileStep类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepTraversalForProfiling

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
private void prepTraversalForProfiling(Traversal.Admin<?, ?> traversal) {
    // Add .profile() step after every pre-existing step.
    final List<Step> steps = traversal.getSteps();
    final int numSteps = steps.size();
    for (int ii = 0; ii < numSteps; ii++) {
        // Get the original step
        final Step step = steps.get(ii * 2);

        // Do not inject profiling after ProfileSideEffectStep as this will be the last step on the root traversal.
        if (step instanceof ProfileSideEffectStep) {
            break;
        }

        // Create and inject ProfileStep
        ProfileStep profileStep = new ProfileStep(traversal);
        traversal.addStep((ii * 2) + 1, profileStep);
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:19,代码来源:ProfileStrategy.java

示例2: validate_g_V_out_out_profile_modern

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
private void validate_g_V_out_out_profile_modern(final Traversal traversal, final TraversalMetrics traversalMetrics) {
    traversalMetrics.toString(); // ensure no exceptions are thrown

    Metrics metrics = traversalMetrics.getMetrics(0);
    assertEquals(6, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertEquals(6, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());

    metrics = traversalMetrics.getMetrics(1);
    assertEquals(6, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertNotEquals(0, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());

    metrics = traversalMetrics.getMetrics(2);
    assertEquals(2, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertNotEquals(0, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());

    if (!onGraphComputer(traversal.asAdmin())) {
        // Every other step should be a Profile step
        List<Step> steps = traversal.asAdmin().getSteps();
        for (int ii = 1; ii <= 6; ii += 2) {
            assertEquals("Every other Step should be a ProfileStep.", ProfileStep.class, steps.get(ii).getClass());
        }
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:24,代码来源:ProfileTest.java

示例3: addTopLevelMetrics

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
private void addTopLevelMetrics(final Traversal.Admin traversal, final boolean onGraphComputer) {
    this.totalStepDuration = 0;

    final List<ProfileStep> profileSteps = TraversalHelper.getStepsOfClass(ProfileStep.class, traversal);
    final List<Pair<Integer, MutableMetrics>> tempMetrics = new ArrayList<>(profileSteps.size());

    for (int ii = 0; ii < profileSteps.size(); ii++) {
        // The index is necessary to ensure that step order is preserved after a merge.
        final ProfileStep step = profileSteps.get(ii);
        final MutableMetrics stepMetrics = onGraphComputer ? traversal.getSideEffects().get(step.getId()) : step.getMetrics();

        this.totalStepDuration += stepMetrics.getDuration(MutableMetrics.SOURCE_UNIT);
        tempMetrics.add(Pair.with(ii, stepMetrics.clone()));
    }

    tempMetrics.forEach(m -> {
        final double dur = m.getValue1().getDuration(TimeUnit.NANOSECONDS) * 100.d / this.totalStepDuration;
        m.getValue1().setAnnotation(PERCENT_DURATION_KEY, dur);
    });

    tempMetrics.forEach(p -> {
        this.stepIndexedMetrics.put(p.getValue1().getId(), p.getValue1().getImmutableClone());
        this.positionIndexedMetrics.put(p.getValue0(), p.getValue1().getImmutableClone());
    });
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:26,代码来源:DefaultTraversalMetrics.java

示例4: apply

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if ((traversal.getParent() instanceof EmptyStep || traversal.getParent() instanceof VertexProgramStep) &&
            TraversalHelper.hasStepOfAssignableClassRecursively(ProfileSideEffectStep.class, traversal))
        TraversalHelper.applyTraversalRecursively(t -> t.getEndStep().addLabel(MARKER), traversal);
    if (traversal.getEndStep().getLabels().contains(MARKER)) {
        traversal.getEndStep().removeLabel(MARKER);
        // Add .profile() step after every pre-existing step.
        final List<Step> steps = traversal.getSteps();
        final int numSteps = steps.size();
        for (int i = 0; i < numSteps; i++) {
            // Do not inject profiling after ProfileSideEffectStep as this will be the last step on the root traversal.
            if (steps.get(i * 2) instanceof ProfileSideEffectStep)
                break;
            // Create and inject ProfileStep
            traversal.addStep((i * 2) + 1, new ProfileStep(traversal));
        }
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:20,代码来源:ProfileStrategy.java

示例5: workerIterationEnd

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
@Override
public void workerIterationEnd(final Memory memory) {
    // store profile metrics in proper ProfileStep metrics
    if (this.profile) {
        List<ProfileStep> profileSteps = TraversalHelper.getStepsOfAssignableClassRecursively(ProfileStep.class, this.traversal.get());
        // guess the profile step to store data
        int profileStepIndex = memory.getIteration();
        // if we guess wrongly write timing into last step
        profileStepIndex = profileStepIndex >= profileSteps.size() ? profileSteps.size() - 1 : profileStepIndex;
        this.iterationMetrics.finish(0);
        // reset counts
        this.iterationMetrics.setCount(TraversalMetrics.TRAVERSER_COUNT_ID,0);
        if (null != MemoryTraversalSideEffects.getMemorySideEffectsPhase(this.traversal.get())) {
            this.traversal.get().getSideEffects().add(profileSteps.get(profileStepIndex).getId(), this.iterationMetrics);
        }
        this.iterationMetrics = null;
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:19,代码来源:TraversalVertexProgram.java

示例6: validate_g_V_out_out_profile_modern

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
private void validate_g_V_out_out_profile_modern(final Traversal traversal, final TraversalMetrics traversalMetrics) {
    traversalMetrics.toString(); // ensure no exceptions are thrown

    assumeThat("The following assertions apply to TinkerGraph only as provider strategies can alter the steps to not comply with expectations",
            graph.getClass().getSimpleName(), equalTo("TinkerGraph"));

    Metrics metrics = traversalMetrics.getMetrics(0);
    assertEquals(6, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertEquals(6, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());

    metrics = traversalMetrics.getMetrics(1);
    assertEquals(6, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertNotEquals(0, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());

    metrics = traversalMetrics.getMetrics(2);
    assertEquals(2, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertNotEquals(0, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());

    if (!onGraphComputer(traversal.asAdmin())) {
        // Every other step should be a Profile step
        List<Step> steps = traversal.asAdmin().getSteps();
        for (int ii = 1; ii <= 6; ii += 2) {
            assertEquals("Every other Step should be a ProfileStep.", ProfileStep.class, steps.get(ii).getClass());
        }
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:27,代码来源:ProfileTest.java

示例7: map

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
@Override
protected Object map(final Traverser.Admin<S> traverser) {
    if (this.getTraversal().getEndStep() instanceof WhereEndStep)
        ((WhereEndStep) this.getTraversal().getEndStep()).processStartTraverser(traverser);
    else if (this.getTraversal().getEndStep() instanceof ProfileStep && this.getTraversal().getEndStep().getPreviousStep() instanceof WhereEndStep)     // TOTAL SUCKY HACK!
        ((WhereEndStep) this.getTraversal().getEndStep().getPreviousStep()).processStartTraverser(traverser);
    return null == this.selectKey ? traverser.get() : this.getScopeValue(Pop.last, this.selectKey, traverser);
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:9,代码来源:WhereTraversalStep.java

示例8: apply

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.onGraphComputer(traversal) ||
            traversal.getTraverserRequirements().contains(TraverserRequirement.PATH) ||
            (IS_TESTING && ((TraversalHelper.hasStepOfAssignableClass(ProfileStep.class, TraversalHelper.getRootTraversal(traversal)) ||
                    TraversalHelper.hasStepOfAssignableClass(ProfileSideEffectStep.class, TraversalHelper.getRootTraversal(traversal)))))) // necessary cause ProfileTest analyzes counts
        return;

    boolean foundFlatMap = false;
    boolean labeledPath = false;
    for (int i = 0; i < traversal.getSteps().size(); i++) {
        final Step<?, ?> step = traversal.getSteps().get(i);

        if (step instanceof PathProcessor) {
            final Set<String> keepLabels = ((PathProcessor) step).getKeepLabels();
            if (null != keepLabels && keepLabels.isEmpty()) // if no more path data, then start barrier'ing again
                labeledPath = false;
        }
        if (step instanceof FlatMapStep &&
                !(step instanceof VertexStep && ((VertexStep) step).returnsEdge()) ||
                (step instanceof GraphStep &&
                        (i > 0 || ((GraphStep) step).getIds().length >= BIG_START_SIZE ||
                                (((GraphStep) step).getIds().length == 0 && !(step.getNextStep() instanceof HasStep))))) {
            if (foundFlatMap && !labeledPath &&
                    !(step.getNextStep() instanceof Barrier) &&
                    !(step.getNextStep() instanceof NoneStep) &&
                    !(step.getNextStep() instanceof EmptyStep)) {
                final Step noOpBarrierStep = new NoOpBarrierStep<>(traversal, MAX_BARRIER_SIZE);
                TraversalHelper.copyLabels(step, noOpBarrierStep, true);
                TraversalHelper.insertAfterStep(noOpBarrierStep, step, traversal);
            } else
                foundFlatMap = true;
        }
        if (!step.getLabels().isEmpty())
            labeledPath = true;

    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:39,代码来源:LazyBarrierStrategy.java

示例9: apply

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (!TraversalHelper.onGraphComputer(traversal))
        return;

    if (traversal.getParent() instanceof TraversalVertexProgramStep) {
        if (TraversalHelper.getStepsOfAssignableClassRecursively(GraphStep.class, traversal).size() > 1)
            throw new VerificationException("Mid-traversal V()/E() is currently not supported on GraphComputer", traversal);
        if (TraversalHelper.hasStepOfAssignableClassRecursively(ProfileStep.class, traversal) && TraversalHelper.getStepsOfAssignableClass(VertexProgramStep.class, TraversalHelper.getRootTraversal(traversal)).size() > 1)
            throw new VerificationException("Profiling a multi-VertexProgramStep traversal is currently not supported on GraphComputer", traversal);
    }

    // this is a problem because sideEffect.merge() is transient on the OLAP reduction
    if (TraversalHelper.getRootTraversal(traversal).getTraverserRequirements().contains(TraverserRequirement.ONE_BULK))
        throw new VerificationException("One bulk is currently not supported on GraphComputer: " + traversal, traversal);

    // you can not traverse past the local star graph with localChildren (e.g. by()-modulators).
    if (!TraversalHelper.isGlobalChild(traversal) && !TraversalHelper.isLocalStarGraph(traversal))
        throw new VerificationException("Local traversals may not traverse past the local star-graph on GraphComputer: " + traversal, traversal);

    for (final Step<?, ?> step : traversal.getSteps()) {
        if (step instanceof PathProcessor && ((PathProcessor) step).getMaxRequirement() != PathProcessor.ElementRequirement.ID)
            throw new VerificationException("It is not possible to access more than a path element's id on GraphComputer: " + step + " requires " + ((PathProcessor) step).getMaxRequirement(), traversal);

        if (UNSUPPORTED_STEPS.stream().filter(c -> c.isAssignableFrom(step.getClass())).findFirst().isPresent())
            throw new VerificationException("The following step is currently not supported on GraphComputer: " + step, traversal);
    }

    Step<?, ?> nextParentStep = traversal.getParent().asStep();
    while (!(nextParentStep instanceof EmptyStep)) {
        if (nextParentStep instanceof PathProcessor && ((PathProcessor) nextParentStep).getMaxRequirement() != PathProcessor.ElementRequirement.ID)
            throw new VerificationException("The following path processor step requires more than the element id on GraphComputer: " + nextParentStep + " requires " + ((PathProcessor) nextParentStep).getMaxRequirement(), traversal);
        nextParentStep = nextParentStep.getNextStep();
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:36,代码来源:ComputerVerificationStrategy.java

示例10: map

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
@Override
protected Object map(final Traverser.Admin<S> traverser) {
    if (this.getTraversal().getEndStep() instanceof SqlgWhereTraversalStepBarrier.SqlgWhereEndStep)
        ((SqlgWhereEndStep) this.getTraversal().getEndStep()).processStartTraverser(traverser);
    else if (this.getTraversal().getEndStep() instanceof ProfileStep && this.getTraversal().getEndStep().getPreviousStep() instanceof SqlgWhereTraversalStepBarrier.SqlgWhereEndStep)     // TOTAL SUCKY HACK!
        ((SqlgWhereEndStep) this.getTraversal().getEndStep().getPreviousStep()).processStartTraverser(traverser);
    return null == this.selectKey ? traverser.get() : this.getScopeValue(Pop.last, this.selectKey, traverser);
}
 
开发者ID:pietermartin,项目名称:sqlg,代码行数:9,代码来源:SqlgWhereTraversalStepBarrier.java

示例11: getEndLabel

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
public static Optional<String> getEndLabel(final Traversal.Admin<Object, Object> traversal) {
    final Step<?, ?> endStep = traversal.getEndStep();
    return endStep instanceof ProfileStep ?           // TOTAL HACK
            ((MatchEndStep) endStep.getPreviousStep()).getMatchKey() :
            ((MatchEndStep) endStep).getMatchKey();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:7,代码来源:MatchStep.java

示例12: apply

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {

    if (!TraversalHelper.onGraphComputer(traversal))
        return;

    final boolean globalChild = TraversalHelper.isGlobalChild(traversal);

    if (traversal.getParent() instanceof TraversalVertexProgramStep) {
        if (TraversalHelper.getStepsOfAssignableClassRecursively(GraphStep.class, traversal).size() > 1)
            throw new VerificationException("Mid-traversal V()/E() is currently not supported on GraphComputer", traversal);
        if (TraversalHelper.hasStepOfAssignableClassRecursively(ProfileStep.class, traversal) && TraversalHelper.getStepsOfAssignableClass(VertexProgramStep.class, TraversalHelper.getRootTraversal(traversal)).size() > 1)
            throw new VerificationException("Profiling a multi-VertexProgramStep traversal is currently not supported on GraphComputer", traversal);
    }

    for (final Step<?, ?> step : traversal.getSteps()) {

        // only global children are graph computing
        if (globalChild && step instanceof GraphComputing)
            ((GraphComputing) step).onGraphComputer();

        // you can not traverse past the local star graph with localChildren (e.g. by()-modulators).
        if (step instanceof TraversalParent) {
            final Optional<Traversal.Admin<Object, Object>> traversalOptional = ((TraversalParent) step).getLocalChildren().stream()
                    .filter(t -> !TraversalHelper.isLocalStarGraph(t.asAdmin()))
                    .findAny();
            if (traversalOptional.isPresent())
                throw new VerificationException("Local traversals may not traverse past the local star-graph on GraphComputer: " + traversalOptional.get(), traversal);
        }

        // collecting barriers and dedup global use can only operate on the element and its properties (no incidences)
        if (step instanceof CollectingBarrierStep && step instanceof TraversalParent) {
            if (((TraversalParent) step).getLocalChildren().stream().filter(t -> !TraversalHelper.isLocalProperties(t)).findAny().isPresent())
                throw new VerificationException("The following barrier step can not process the incident edges of a vertex on GraphComputer: " + step, traversal);
        }

        // this is a problem because sideEffect.merge() is transient on the OLAP reduction
        if (TraversalHelper.getRootTraversal(traversal).getTraverserRequirements().contains(TraverserRequirement.ONE_BULK))
            throw new VerificationException("One bulk is currently not supported on GraphComputer: " + step, traversal);

        if (step instanceof PathProcessor && ((PathProcessor) step).getMaxRequirement() != PathProcessor.ElementRequirement.ID)
            throw new VerificationException("It is not possible to access more than a path element's id on GraphComputer: " + step + " requires " + ((PathProcessor) step).getMaxRequirement(), traversal);

        if (UNSUPPORTED_STEPS.stream().filter(c -> c.isAssignableFrom(step.getClass())).findFirst().isPresent())
            throw new VerificationException("The following step is currently not supported on GraphComputer: " + step, traversal);

    }

    Step<?, ?> nextParentStep = traversal.getParent().asStep();
    while (!(nextParentStep instanceof EmptyStep)) {
        if (nextParentStep instanceof PathProcessor && ((PathProcessor) nextParentStep).getMaxRequirement() != PathProcessor.ElementRequirement.ID)
            throw new VerificationException("The following path processor step requires more than the element id on GraphComputer: " + nextParentStep + " requires " + ((PathProcessor) nextParentStep).getMaxRequirement(), traversal);
        nextParentStep = nextParentStep.getNextStep();
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:56,代码来源:ComputerVerificationStrategy.java

示例13: isEndStep

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的package包/类
protected boolean isEndStep() {
    return this.getNextStep() instanceof ComputerResultStep || (this.getNextStep() instanceof ProfileStep && this.getNextStep().getNextStep() instanceof ComputerResultStep);
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:4,代码来源:VertexProgramStep.java

示例14: loadState

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的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));
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:46,代码来源:TraversalVertexProgram.java

示例15: loadState

import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep; //导入依赖的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();
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:49,代码来源:TraversalVertexProgram.java


注:本文中的org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。