summaryrefslogtreecommitdiffstats
path: root/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/Cluster.java
blob: fccb79c77b4019389a447de32a73f3b3c31c5e4a (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
65
66
67
68
69
70
71
72
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.http.client.config;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
 * A set of {@link Endpoint} instances. Construct using {@link Cluster.Builder}.
 *
 * @author Einar M R Rosenvinge
 */
public final class Cluster {

    /** Builder for {@link Cluster}. */
    public final static class Builder {
        private final List<Endpoint> endpoints = new LinkedList<>();
        private String route = null;

        /**
         * Adds an Endpoint (a HTTP gateway) to this Cluster.
         *
         * @param endpoint the Endpoint to add
         * @return this, for chaining
         */
        public Builder addEndpoint(Endpoint endpoint) {
            endpoints.add(endpoint);
            return this;
        }

        /**
         * Sets a route specific to this cluster, which overrides the route set in {@link com.yahoo.vespa.http.client.config.FeedParams#getRoute()}.
         *
         * @param route a route specific to this cluster
         * @return this, for chaining
         */
        public Builder setRoute(String route) {
            this.route = route;
            return this;
        }

        public Cluster build() {
            return new Cluster(endpoints, route);
        }

        public String getRoute() {
            return route;
        }
    }
    private final List<Endpoint> endpoints;
    private final String route;

    private Cluster(List<Endpoint> endpoints, String route) {
        this.endpoints = Collections.unmodifiableList(new ArrayList<>(endpoints));
        this.route = route;
    }

    public List<Endpoint> getEndpoints() {
        return endpoints;
    }

    public String getRoute() {
        return route;
    }

    @Override
    public String toString() {
        return "cluster with endpoints " + endpoints + " and route '" + route + "'";
    }

}