#pragma once #include "config.h" #if USE_GRPC #include "clickhouse_grpc.grpc.pb.h" #include #include #include namespace Poco { class Logger; } namespace grpc { class Server; class ServerCompletionQueue; } namespace DB { class IServer; class GRPCServer { public: GRPCServer(IServer & iserver_, const Poco::Net::SocketAddress & address_to_listen_); ~GRPCServer(); /// Starts the server. A new thread will be created that waits for and accepts incoming connections. void start(); /// Stops the server. No new connections will be accepted. void stop(); /// Returns the port this server is listening to. UInt16 portNumber() const { return address_to_listen.port(); } /// Returns the number of currently handled connections. size_t currentConnections() const; /// Returns the number of current threads. size_t currentThreads() const { return currentConnections(); } private: using GRPCService = clickhouse::grpc::ClickHouse::AsyncService; class Runner; IServer & iserver; const Poco::Net::SocketAddress address_to_listen; LoggerRawPtr log; GRPCService grpc_service; std::unique_ptr grpc_server; std::unique_ptr queue; std::unique_ptr runner; }; } #endif