aboutsummaryrefslogtreecommitdiffstats
path: root/zookeeper-server/zookeeper-server-3.9.2/src/main/java/com/yahoo/vespa/zookeeper/VespaZooKeeperServerImpl.java
blob: 4f93eb0efa52ae5916d812ad5ddacefe30e6832f (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.zookeeper;

import ai.vespa.validation.Validation;
import com.yahoo.cloud.config.ZookeeperServerConfig;
import com.yahoo.component.AbstractComponent;
import com.yahoo.component.annotation.Inject;
import com.yahoo.vespa.zookeeper.server.VespaZooKeeperServer;

import java.nio.file.Path;
import java.time.Duration;

/**
 * ZooKeeper server. Guarantees that the server is up by writing a node to ZooKeeper successfully before
 * returning from constructor.
 *
 * @author Ulf Lilleengen
 * @author Harald Musum
 */
public class VespaZooKeeperServerImpl extends AbstractComponent implements VespaZooKeeperServer {

    private final VespaQuorumPeer peer;
    private final ZooKeeperRunner runner;

    @Inject
    public VespaZooKeeperServerImpl(ZookeeperServerConfig zookeeperServerConfig) {
        Validation.require(! zookeeperServerConfig.dynamicReconfiguration(),
                           ! zookeeperServerConfig.dynamicReconfiguration(),
                           "dynamicReconfiguration must be false");
        this.peer = new VespaQuorumPeer();
        this.runner = new ZooKeeperRunner(zookeeperServerConfig, this);
        new VespaZooKeeperAdminImpl().createDummyNode(zookeeperServerConfig);
    }

    @Override
    public void deconstruct() {
        runner.shutdown();
        super.deconstruct();
    }

    @Override
    public void shutdown() {
        peer.shutdown(Duration.ofMinutes(1));
    }

    @Override
    public void start(Path configFilePath) {
        peer.start(configFilePath);
    }

    @Override
    public boolean reconfigurable() {
        return false;
    }

}