summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/filedistribution/FileDistributionConfigProducer.java
blob: 095a5e2945017bc650b920108b63a348c879a76d (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.filedistribution;

import com.yahoo.config.application.api.FileRegistry;
import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.vespa.model.Host;
import com.yahoo.vespa.model.admin.FileDistributionOptions;

import java.util.IdentityHashMap;
import java.util.Map;

/**
 * @author tonytv
 */
public class FileDistributionConfigProducer extends AbstractConfigProducer {

    private final Map<Host, FileDistributorService> fileDistributorServices = new IdentityHashMap<>();
    private final FileDistributor fileDistributor;
    private final FileDistributionOptions options;

    private FileDistributionConfigProducer(AbstractConfigProducer parent, FileDistributor fileDistributor, FileDistributionOptions options) {
        super(parent, "filedistribution");
        this.fileDistributor = fileDistributor;
        this.options = options;
    }

    public FileDistributorService getFileDistributorService(Host host) {
        FileDistributorService service = fileDistributorServices.get(host);
        if (service == null) {
            throw new IllegalStateException("No file distribution service for host " + host);
        }
        return service;
    }

    public FileDistributor getFileDistributor() {
        return fileDistributor;
    }

    public FileDistributionOptions getOptions() {
        return options;
    }

    public void addFileDistributionService(Host host, FileDistributorService fds) {
        fileDistributorServices.put(host, fds);
    }

    public static class Builder {

        private final FileDistributionOptions options;

        public Builder(FileDistributionOptions fileDistributionOptions) {
            this.options = fileDistributionOptions;
        }

        public FileDistributionConfigProducer build(AbstractConfigProducer ancestor, FileRegistry fileRegistry) {
            FileDistributor fileDistributor = new FileDistributor(fileRegistry);
            return new FileDistributionConfigProducer(ancestor, fileDistributor, options);
        }
    }

}