/** * @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())); }
public ChainSpecification setComponentId(ComponentId newComponentId) { return new ChainSpecification(newComponentId, inheritance, phases(), componentReferences); }
public ChainSpecification(ComponentId componentId, Inheritance inheritance, Collection<Phase> phases, Set<ComponentSpecification> componentReferences) { assertNotNull(componentId, inheritance, phases, componentReferences); if (componentsByName(componentReferences).size() != componentReferences.size()) throw new RuntimeException("Two components with the same name are specified in '" + componentId + "', but name must be unique inside a given chain."); this.componentId = componentId; this.inheritance = inheritance; this.phases = copyPhasesImmutable(phases); this.componentReferences = ImmutableSet.copyOf( filterByComponentSpecification(componentReferences, inheritance.excludedComponents)); }
public ChainSpecification build(Set<ComponentSpecification> outerComponentReferences) { return new ChainSpecification(componentId, inheritance, phases, outerComponentReferences); } }
private static <COMPONENT extends ChainedComponent> void instantiateChains( ComponentRegistry<Chain<COMPONENT>> chainRegistry, ChainsModel model, ComponentRegistry<COMPONENT> allComponents) { for (ChainSpecification chain : model.allChainsFlattened()) { try { Chain<COMPONENT> componentChain = new Chain<>(chain.componentId, resolveComponents(chain.componentReferences, allComponents), chain.phases()); chainRegistry.register(chain.componentId, componentChain); } catch (Exception e) { throw new ConfigurationRuntimeException("Invalid chain '" + chain.componentId + "'", e); } } }
public ChainSpecification getChainSpecification() { Collection<ComponentSpecification> innerComponentSpecifications = new ArrayList<>(); for (ChainedComponent innerComponent : getInnerComponents()) { innerComponentSpecifications.add(innerComponent.getGlobalComponentId().toSpecification()); } return specWithoutInnerComponents. addComponents(innerComponentSpecifications). setComponentId(getGlobalComponentId()); }
public ChainSpecification flatten(Resolver<ChainSpecification> allChainSpecifications) { Deque<ComponentId> path = new ArrayDeque<>(); return flatten(allChainSpecifications, path); }
@Override public ChainSpecification getChainSpecification() { return super.getChainSpecification().addInherits( Arrays.asList(getParentProvider().getComponentId().toSpecification())); }
public static ChainSpecification emptyChainSpec(ComponentId chainId) { return new ChainSpecification(chainId, new ChainSpecification.Inheritance(null, null), Collections.<Phase>emptySet(), Collections.<ComponentSpecification>emptySet()); }
private static <T extends Chain> ChainsConfig.Chains.Builder getChain(T chain) { ChainSpecification specification = chain.getChainSpecification(); return new ChainsConfig.Chains.Builder() .type(chain.getType()) .id(specification.componentId.stringValue()) .components(getComponents(specification.componentReferences)) .inherits(getComponents(specification.inheritance.chainSpecifications)) .excludes(getComponents(specification.inheritance.excludedComponents)) .phases(getPhases(specification.phases())); }
public Collection<ChainSpecification> allChainsFlattened() { Resolver<ChainSpecification> resolver = new Resolver<ChainSpecification>() { @Override public ChainSpecification resolve(ComponentSpecification componentSpecification) { ComponentAdaptor<ChainSpecification> spec = chainSpecifications.getComponent(componentSpecification); return (spec==null) ? null : spec.model; } }; Collection<ChainSpecification> chains = new ArrayList<>(); for (ComponentAdaptor<ChainSpecification> chain : chainSpecifications.allComponents()) { chains.add(chain.model.flatten(resolver)); } return chains; }
public ChainSpecification addComponents(Collection<ComponentSpecification> componentSpecifications) { Set<ComponentSpecification> newComponentReferences = new LinkedHashSet<>(componentReferences); newComponentReferences.addAll(componentSpecifications); return new ChainSpecification(componentId, inheritance, phases(), newComponentReferences); }
static ChainSpecification emptySearchChainSpecification(String componentName) { return new ChainSpecification( new ComponentId(componentName), VespaSearchChainsCreator.inheritsVespaPhases(), //TODO: refactor Collections.<Phase>emptyList(), Collections.<ComponentSpecification>emptySet()); }
public ChainSpecification addInherits(Collection<ComponentSpecification> inheritedChains) { return new ChainSpecification(componentId, inheritance.addInherits(inheritedChains), phases(), componentReferences); }
public IndexingDocprocChain() { super(new ChainSpecification(new ComponentId(NAME), new ChainSpecification.Inheritance(Collections.<ComponentSpecification>emptySet(), Collections.<ComponentSpecification>emptySet()), phases, Collections.<ComponentSpecification>emptySet()), new HashMap<>()); addInnerComponent(new IndexingProcessor()); }
@Override public ChainSpecification getChainSpecification() { ChainSpecification spec = super.getChainSpecification(); return new ChainSpecification(spec.componentId, spec.inheritance, spec.phases(), disableStemmingIfStreaming(spec.componentReferences)); }
private static ChainSpecification nativeSearchChainSpecification() { return new ChainSpecification( new ComponentId("native"), inheritsVespaPhases(), noPhases(), noSearcherReferences()); }
private static ChainSpecification vespaSearchChainSpecification() { return new ChainSpecification( new ComponentId("vespa"), inherits(nativeSearchChainSpecification().componentId), noPhases(), noSearcherReferences()); }
private static ChainSpecification vespaPhasesSpecification() { return new ChainSpecification( new ComponentId("vespaPhases"), new ChainSpecification.Inheritance(null, null), PhasesCreator.linearPhases( PhaseNames.RAW_QUERY, PhaseNames.TRANSFORMED_QUERY, PhaseNames.BLENDED_RESULT, PhaseNames.UNBLENDED_RESULT, PhaseNames.BACKEND), noSearcherReferences()); }
private static ChainSpecification createChainSpecification(ChainsConfig.Chains config) { return new ChainSpecification(new ComponentId(config.id()), createInheritance(config.inherits(), config.excludes()), createPhases(config.phases()), createComponentSpecifications(config.components())); }