aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Server/ProtocolServerAdapter.cpp
blob: 8d14a84989468bfb6cf2177e91288d15a6d8e0ee (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
#include <Server/ProtocolServerAdapter.h>
#include <Server/TCPServer.h>

#if USE_GRPC && !defined(CLICKHOUSE_KEEPER_STANDALONE_BUILD)
#include <Server/GRPCServer.h>
#endif


namespace DB
{
class ProtocolServerAdapter::TCPServerAdapterImpl : public Impl
{
public:
    explicit TCPServerAdapterImpl(std::unique_ptr<TCPServer> tcp_server_) : tcp_server(std::move(tcp_server_)) {}
    ~TCPServerAdapterImpl() override = default;

    void start() override { tcp_server->start(); }
    void stop() override { tcp_server->stop(); }
    bool isStopping() const override { return !tcp_server->isOpen(); }
    UInt16 portNumber() const override { return tcp_server->portNumber(); }
    size_t currentConnections() const override { return tcp_server->currentConnections(); }
    size_t currentThreads() const override { return tcp_server->currentThreads(); }

private:
    std::unique_ptr<TCPServer> tcp_server;
};

ProtocolServerAdapter::ProtocolServerAdapter(
    const std::string & listen_host_,
    const char * port_name_,
    const std::string & description_,
    std::unique_ptr<TCPServer> tcp_server_)
    : listen_host(listen_host_)
    , port_name(port_name_)
    , description(description_)
    , impl(std::make_unique<TCPServerAdapterImpl>(std::move(tcp_server_)))
{
}

#if USE_GRPC && !defined(CLICKHOUSE_KEEPER_STANDALONE_BUILD)
class ProtocolServerAdapter::GRPCServerAdapterImpl : public Impl
{
public:
    explicit GRPCServerAdapterImpl(std::unique_ptr<GRPCServer> grpc_server_) : grpc_server(std::move(grpc_server_)) {}
    ~GRPCServerAdapterImpl() override = default;

    void start() override { grpc_server->start(); }
    void stop() override
    {
        is_stopping = true;
        grpc_server->stop();
    }
    bool isStopping() const override { return is_stopping; }
    UInt16 portNumber() const override { return grpc_server->portNumber(); }
    size_t currentConnections() const override { return grpc_server->currentConnections(); }
    size_t currentThreads() const override { return grpc_server->currentThreads(); }

private:
    std::unique_ptr<GRPCServer> grpc_server;
    bool is_stopping = false;
};

ProtocolServerAdapter::ProtocolServerAdapter(
    const std::string & listen_host_,
    const char * port_name_,
    const std::string & description_,
    std::unique_ptr<GRPCServer> grpc_server_)
    : listen_host(listen_host_)
    , port_name(port_name_)
    , description(description_)
    , impl(std::make_unique<GRPCServerAdapterImpl>(std::move(grpc_server_)))
{
}
#endif
}