aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/container/search/searchchain/Provider.java
blob: 83897288a5af868e89d2ee73aececda13a158c18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.search.searchchain;

import com.yahoo.component.chain.model.ChainSpecification;
import com.yahoo.search.searchchain.model.federation.FederationOptions;
import com.yahoo.vespa.model.container.component.ConfigProducerGroup;

import java.util.Collection;
import java.util.List;

/**
 * Base config producer for search chains that communicate with backends.
 *
 * @author Tony Vaagenes
 */
public class Provider extends GenericTarget {

    private final ConfigProducerGroup<Source> sources;

    public Provider(ChainSpecification specWithoutInnerSearchers, FederationOptions federationOptions) {
        super(specWithoutInnerSearchers, federationOptions);
        sources = new ConfigProducerGroup<>(this, "source");
    }

    public void addSource(Source source) {
        sources.addComponent(source.getComponentId(), source);
    }

    public Collection<Source> getSources() {
        return sources.getComponents();
    }

    @Override
    protected boolean useByDefault() {
        return sources.getComponents().isEmpty();
    }

    public Collection<? extends GenericTarget> defaultFederationTargets() {
        if (sources.getComponents().isEmpty()) {
            return List.of(this);
        } else {
            return sources.getComponents();
        }
    }

}