summaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/container/Server.java
blob: 293e8b4674e5bf60985387dd53e086c514fe43bb (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
83
84
85
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container;

import com.yahoo.config.subscription.ConfigSubscriber;
import com.yahoo.container.QrConfig.Rpc;
import com.yahoo.container.osgi.ContainerRpcAdaptor;

/**
 * The http server singleton managing listeners for various ports,
 * and the threads used to respond to requests on the ports
 *
 * @author bratseth
 */
@SuppressWarnings("deprecation")
public class Server {

    //TODO: Make this final again.
    private static Server instance = new Server();
    private ConfigSubscriber subscriber = new ConfigSubscriber();

    /** The OSGi container instance of this server */
    private Container container = Container.get();

    /** A short string which is different for all the qrserver instances on a given node. */
    private String localServerDiscriminator = "qrserver.0";

    /** Creates a new server instance. Not usually useful, use get() to get the current server */
    private Server() { }

    /** @deprecated returns 0 */
    @Deprecated
    public int searchQueriesInFlight() {
        return 0;
    }

    /**
     * An estimate of current number of connections. It is better to be
     * inaccurate than to acquire a lock per query fsync.
     *
     * @return The current number of open search connections
     */
    /** @deprecated returns 0 */
    @Deprecated
    public int getCurrentConnections() {
        return 0;
    }

    public static Server get() {
        return instance;
    }

    private void initRpcServer(Rpc rpcConfig) {
        if (rpcConfig.enabled()) {
            ContainerRpcAdaptor rpcAdaptor = container.getRpcAdaptor();
            rpcAdaptor.listen(rpcConfig.port());
            rpcAdaptor.setSlobrokId(rpcConfig.slobrokId());
        }
    }

    /** Ugly hack, see Container.resetInstance */
    static void resetInstance() {
        instance = new Server();
    }

    // TODO: Make independent of config
    public void initialize(QrConfig config) {
        localServerDiscriminator = config.discriminator();
        container.setupFileAcquirer(config.filedistributor());
        initRpcServer(config.rpc());
    }

    /**
     * A string unique for this QRS on this server.
     *
     * @return a server specific string
     */
    public String getServerDiscriminator() {
        return localServerDiscriminator;
    }

    public void shutdown() {
        if (subscriber!=null) subscriber.close();
    }

}