aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/federation/selection/FederationTarget.java
blob: ee8b59c1750344759529cf689ee75116f7bd81cf (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.federation.selection;

import com.yahoo.component.chain.Chain;
import com.yahoo.search.Searcher;
import com.yahoo.search.searchchain.model.federation.FederationOptions;

import java.util.Objects;

/**
 * Represents a search chain that the federation searcher should send a query to,
 * along with a timeout and
 * custom data reserved for use by the TargetSelector.
 *
 * @author Tony Vaagenes
 */
public final class FederationTarget<T> {

    private final Chain<Searcher> chain;
    private final FederationOptions federationOptions;
    private final T customData;

    public FederationTarget(Chain<Searcher> chain, FederationOptions federationOptions, T customData) {
        this.chain = Objects.requireNonNull(chain, "chain cannot be null");
        this.federationOptions = Objects.requireNonNull(federationOptions, "federationOptions cannot be null");
        this.customData = customData;
    }

    public Chain<Searcher> getChain() {
        return chain;
    }

    public FederationOptions getFederationOptions() {
        return federationOptions;
    }

    /**
     * Any data that the TargetSelector wants to associate with this target.
     * Owned exclusively by the TargetSelector that created this instance.
     */
    public T getCustomData() {
        return customData;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        FederationTarget that = (FederationTarget) o;

        if (!chain.equals(that.chain)) return false;
        if (customData != null ? !customData.equals(that.customData) : that.customData != null) return false;
        if (!federationOptions.equals(that.federationOptions)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return Objects.hash(chain, federationOptions);
    }

}