2020-12-09 08:45:36 +00:00
|
|
|
#pragma once
|
2021-02-01 13:18:17 +00:00
|
|
|
|
2021-02-01 14:14:59 +00:00
|
|
|
#include <Server/NuKeeperTCPHandler.h>
|
2020-12-09 08:45:36 +00:00
|
|
|
#include <Poco/Net/TCPServerConnectionFactory.h>
|
|
|
|
#include <Poco/Net/NetException.h>
|
|
|
|
#include <common/logger_useful.h>
|
|
|
|
#include <Server/IServer.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-02-01 14:14:59 +00:00
|
|
|
class NuKeeperTCPHandlerFactory : public Poco::Net::TCPServerConnectionFactory
|
2020-12-09 08:45:36 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
IServer & server;
|
|
|
|
Poco::Logger * log;
|
|
|
|
class DummyTCPHandler : public Poco::Net::TCPServerConnection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using Poco::Net::TCPServerConnection::TCPServerConnection;
|
|
|
|
void run() override {}
|
|
|
|
};
|
|
|
|
public:
|
2021-02-01 14:14:59 +00:00
|
|
|
NuKeeperTCPHandlerFactory(IServer & server_)
|
2020-12-09 08:45:36 +00:00
|
|
|
: server(server_)
|
2021-02-01 14:14:59 +00:00
|
|
|
, log(&Poco::Logger::get("NuKeeperTCPHandlerFactory"))
|
2020-12-09 08:45:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Poco::Net::TCPServerConnection * createConnection(const Poco::Net::StreamSocket & socket) override
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-02-01 14:14:59 +00:00
|
|
|
LOG_TRACE(log, "NuKeeper request. Address: {}", socket.peerAddress().toString());
|
|
|
|
return new NuKeeperTCPHandler(server, socket);
|
2020-12-09 08:45:36 +00:00
|
|
|
}
|
|
|
|
catch (const Poco::Net::NetException &)
|
|
|
|
{
|
|
|
|
LOG_TRACE(log, "TCP Request. Client is not connected (most likely RST packet was sent).");
|
|
|
|
return new DummyTCPHandler(socket);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|