summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/content/DispatchSpec.java
blob: 1072965772fdd84d69f0853d9c09814103adc170 (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
73
74
75
76
77
78
79
80
81
82
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.content;

import java.util.ArrayList;
import java.util.List;

/**
 * Represents the dispatch setup for a content cluster.
 * This EITHER has a number of dispatch groups OR a an explicit list of groups.
 *
 * @author geirst
 */
public class DispatchSpec {

    private final Integer numDispatchGroups;
    private final List<Group> groups;

    private DispatchSpec(Builder builder) {
        numDispatchGroups = builder.numDispatchGroups;
        groups = builder.groups;
    }

    public Integer getNumDispatchGroups() { return numDispatchGroups; }

    public List<Group> getGroups() {
        return groups;
    }

    public boolean valid() {
        return numDispatchGroups != null || groups != null;
    }

    /**
     * Reference to a node which is contained in a dispatch group.
     */
    public static class Node {
        private final int distributionKey;
        public Node(int distributionKey) {
            this.distributionKey = distributionKey;
        }
        public int getDistributionKey() {
            return distributionKey;
        }
    }

    /**
     * A dispatch group with a list of nodes contained in that group.
     */
    public static class Group {
        private final List<Node> nodes = new ArrayList<>();
        public Group() {

        }
        public Group addNode(Node node) {
            nodes.add(node);
            return this;
        }
        public List<Node> getNodes() {
            return nodes;
        }
    }

    public static class Builder {

        private Integer numDispatchGroups;
        private List<Group> groups;

        public DispatchSpec build() {
            return new DispatchSpec(this);
        }

        public Builder setNumDispatchGroups(Integer numDispatchGroups) {
            this.numDispatchGroups = numDispatchGroups;
            return this;
        }

        public Builder setGroups(List<Group> groups) {
            this.groups = groups;
            return this;
        }
    }
}