34class ConnectionHandler {
36 using OnDisconnectHook = std::function<void(
Connection const&)>;
37 using OnIpChangeHook = std::function<void(std::string
const&, std::string
const&)>;
38 using TargetToHandlerMap =
39 std::unordered_map<std::string, MessageHandler, util::StringHash, std::equal_to<>>;
45 ProcessingPolicy processingPolicy_;
46 std::optional<size_t> maxParallelRequests_;
48 std::reference_wrapper<util::TagDecoratorFactory> tagFactory_;
52 OnDisconnectHook onDisconnectHook_;
53 OnIpChangeHook onIpChangeHook_;
55 TargetToHandlerMap getHandlers_;
56 TargetToHandlerMap postHandlers_;
57 std::optional<MessageHandler> wsHandler_;
59 boost::signals2::signal<void()> onStop_;
60 std::unique_ptr<std::atomic_bool> stopping_ = std::make_unique<std::atomic_bool>(
false);
62 std::reference_wrapper<util::prometheus::GaugeInt> connectionsCounter_ =
64 "connections_total_number",
72 ProcessingPolicy processingPolicy,
73 std::optional<size_t> maxParallelRequests,
76 OnDisconnectHook onDisconnectHook,
77 OnIpChangeHook onIpChangeHook
80 ConnectionHandler(ConnectionHandler&&) =
delete;
82 static constexpr std::chrono::milliseconds kCloseConnectionTimeout{500};
85 onGet(std::string
const& target, MessageHandler handler);
88 onPost(std::string
const& target, MessageHandler handler);
91 onWs(MessageHandler handler);
94 processConnection(ConnectionPtr connection, boost::asio::yield_context yield);
97 stopConnection(
Connection& connection, boost::asio::yield_context yield);
100 stop(boost::asio::yield_context yield);
114 handleError(Error
const& error,
Connection const& connection)
const;
124 sequentRequestResponseLoop(
127 boost::asio::yield_context yield
131 parallelRequestResponseLoop(
134 boost::asio::yield_context yield
142 boost::asio::yield_context yield
150 boost::asio::yield_context yield
static util::prometheus::GaugeInt & gaugeInt(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get an integer based gauge metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:231
std::shared_ptr< SubscriptionContextInterface > SubscriptionContextPtr
An alias for shared pointer to a SubscriptionContextInterface.
Definition SubscriptionContextInterface.hpp:64