2020-09-21 22:12:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-10-11 02:19:01 +00:00
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
#include <Common/config.h>
|
|
|
|
#endif
|
2020-09-21 22:12:55 +00:00
|
|
|
|
2020-10-11 02:19:01 +00:00
|
|
|
#if USE_GRPC
|
2020-10-08 00:23:10 +00:00
|
|
|
#include <Poco/Net/SocketAddress.h>
|
2020-10-11 02:19:01 +00:00
|
|
|
#include "clickhouse_grpc.grpc.pb.h"
|
2020-09-21 22:12:55 +00:00
|
|
|
|
2020-10-15 00:45:13 +00:00
|
|
|
namespace Poco { class Logger; }
|
2020-09-21 22:12:55 +00:00
|
|
|
|
2020-10-11 02:19:01 +00:00
|
|
|
namespace grpc
|
2020-09-21 22:12:55 +00:00
|
|
|
{
|
2020-10-11 02:19:01 +00:00
|
|
|
class Server;
|
|
|
|
class ServerCompletionQueue;
|
|
|
|
}
|
2020-09-21 22:12:55 +00:00
|
|
|
|
2020-10-11 02:19:01 +00:00
|
|
|
namespace DB
|
2020-09-21 22:12:55 +00:00
|
|
|
{
|
2020-10-11 02:19:01 +00:00
|
|
|
class IServer;
|
2020-09-21 22:12:55 +00:00
|
|
|
|
2020-10-15 00:45:13 +00:00
|
|
|
class GRPCServer
|
2020-09-21 22:12:55 +00:00
|
|
|
{
|
2020-10-11 02:19:01 +00:00
|
|
|
public:
|
2020-10-15 00:45:13 +00:00
|
|
|
GRPCServer(IServer & iserver_, const Poco::Net::SocketAddress & address_to_listen_);
|
|
|
|
~GRPCServer();
|
2020-10-11 02:19:01 +00:00
|
|
|
|
2020-10-08 00:23:10 +00:00
|
|
|
/// 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.
|
2020-10-11 02:19:01 +00:00
|
|
|
void stop();
|
2020-10-08 00:23:10 +00:00
|
|
|
|
|
|
|
/// Returns the number of currently handled connections.
|
|
|
|
size_t currentConnections() const;
|
|
|
|
|
2020-12-17 13:47:03 +00:00
|
|
|
/// Returns the number of current threads.
|
|
|
|
size_t currentThreads() const { return currentConnections(); }
|
|
|
|
|
2020-10-08 00:23:10 +00:00
|
|
|
private:
|
2020-10-05 20:33:34 +00:00
|
|
|
using GRPCService = clickhouse::grpc::ClickHouse::AsyncService;
|
2020-10-15 00:45:13 +00:00
|
|
|
class Runner;
|
|
|
|
|
2020-10-11 02:19:01 +00:00
|
|
|
IServer & iserver;
|
2020-10-15 00:45:13 +00:00
|
|
|
const Poco::Net::SocketAddress address_to_listen;
|
2020-10-11 02:19:01 +00:00
|
|
|
Poco::Logger * log;
|
2020-10-05 20:33:34 +00:00
|
|
|
GRPCService grpc_service;
|
2020-10-11 02:19:01 +00:00
|
|
|
std::unique_ptr<grpc::Server> grpc_server;
|
2020-10-15 00:45:13 +00:00
|
|
|
std::unique_ptr<grpc::ServerCompletionQueue> queue;
|
|
|
|
std::unique_ptr<Runner> runner;
|
2020-09-21 22:12:55 +00:00
|
|
|
};
|
2020-10-11 02:19:01 +00:00
|
|
|
}
|
|
|
|
#endif
|