Search in sources :

Example 1 with Phase

use of com.yahoo.component.chain.Phase in project vespa by vespa-engine.

the class ChainBuilderTest method createDependencyHandler.

private ChainBuilder createDependencyHandler() {
    ChainBuilder chainBuilder = newChainBuilder();
    chainBuilder.addPhase(new Phase("phase1", Collections.<String>emptySet(), Collections.<String>emptySet()));
    chainBuilder.addPhase(new Phase("phase2", Collections.<String>emptySet(), Collections.<String>emptySet()));
    chainBuilder.addPhase(new Phase("phase3", Collections.<String>emptySet(), Collections.<String>emptySet()));
    return chainBuilder;
}
Also used : Phase(com.yahoo.component.chain.Phase)

Example 2 with Phase

use of com.yahoo.component.chain.Phase in project vespa by vespa-engine.

the class ChainBuilderTest method testPhaseAndSearcher.

@Test
public void testPhaseAndSearcher() {
    ChainBuilder depHandler = newChainBuilder();
    depHandler.addPhase(new Phase("phase1", set("phase2"), Collections.<String>emptySet()));
    depHandler.addPhase(new Phase("phase2", set("phase3"), set("phase1")));
    depHandler.addPhase(new Phase("phase3", Collections.<String>emptySet(), set("phase2", "phase1")));
    ChainedComponent first = new First();
    ChainedComponent second = new Second();
    depHandler.addComponent(first);
    depHandler.addComponent(second);
    assertEquals(depHandler.orderNodes().components(), Arrays.asList(first, second));
}
Also used : Phase(com.yahoo.component.chain.Phase) ChainedComponent(com.yahoo.component.chain.ChainedComponent) Test(org.junit.Test)

Example 3 with Phase

use of com.yahoo.component.chain.Phase in project vespa by vespa-engine.

the class ChainSpecification method flatten.

/**
 * @param allChainSpecifications resolves ChainSpecifications from ComponentSpecifications
 *                               as given in the inheritance fields.
 * @param path tracks which chains are used in each recursive invocation of flatten, used for detecting cycles.
 * @return ChainSpecification directly containing all the component references and phases of the inherited chains.
 */
private ChainSpecification flatten(Resolver<ChainSpecification> allChainSpecifications, Deque<ComponentId> path) {
    path.push(componentId);
    // if this turns out to be a bottleneck(which I seriously doubt), please add memoization
    Map<String, ComponentSpecification> resultingComponents = componentsByName(componentReferences);
    Map<String, Phase> resultingPhases = new LinkedHashMap<>(phases);
    for (ComponentSpecification inheritedChainSpecification : inheritance.chainSpecifications) {
        ChainSpecification inheritedChain = resolveChain(path, allChainSpecifications, inheritedChainSpecification).flatten(allChainSpecifications, path);
        mergeInto(resultingComponents, filterByComponentSpecification(filterByName(inheritedChain.componentReferences, names(componentReferences)), inheritance.excludedComponents));
        mergeInto(resultingPhases, inheritedChain.phases);
    }
    path.pop();
    return new ChainSpecification(componentId, inheritance.flattened(), resultingPhases.values(), new LinkedHashSet<>(resultingComponents.values()));
}
Also used : Phase(com.yahoo.component.chain.Phase) ComponentSpecification(com.yahoo.component.ComponentSpecification)

Example 4 with Phase

use of com.yahoo.component.chain.Phase in project vespa by vespa-engine.

the class ChainSpecification method mergeInto.

private static void mergeInto(Map<String, Phase> resultingPhases, Map<String, Phase> phases) {
    for (Phase phase : phases.values()) {
        String name = phase.getName();
        if (resultingPhases.containsKey(name)) {
            phase = phase.union(resultingPhases.get(name));
        }
        resultingPhases.put(name, phase);
    }
}
Also used : Phase(com.yahoo.component.chain.Phase)

Example 5 with Phase

use of com.yahoo.component.chain.Phase in project vespa by vespa-engine.

the class ChainSpecificationBuilder method readPhases.

private Set<Phase> readPhases(Element parentElement) {
    Set<Phase> phases = new LinkedHashSet<>();
    for (Element phaseSpec : XML.getChildren(parentElement, "phase")) {
        String name = XmlHelper.getIdString(phaseSpec);
        Dependencies dependencies = new DependenciesBuilder(phaseSpec).build();
        phases.add(new Phase(name, dependencies));
    }
    return phases;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Phase(com.yahoo.component.chain.Phase) Element(org.w3c.dom.Element) Dependencies(com.yahoo.component.chain.dependencies.Dependencies)

Aggregations

Phase (com.yahoo.component.chain.Phase)5 ComponentSpecification (com.yahoo.component.ComponentSpecification)1 ChainedComponent (com.yahoo.component.chain.ChainedComponent)1 Dependencies (com.yahoo.component.chain.dependencies.Dependencies)1 LinkedHashSet (java.util.LinkedHashSet)1 Test (org.junit.Test)1 Element (org.w3c.dom.Element)1