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_;
49 std::optional<size_t> maxSubscriptionSendQueueSize_;
53 OnDisconnectHook onDisconnectHook_;
54 OnIpChangeHook onIpChangeHook_;
56 TargetToHandlerMap getHandlers_;
57 TargetToHandlerMap postHandlers_;
58 std::optional<MessageHandler> wsHandler_;
60 boost::signals2::signal<void()> onStop_;
61 std::unique_ptr<std::atomic_bool> stopping_ = std::make_unique<std::atomic_bool>(
false);
63 std::reference_wrapper<util::prometheus::GaugeInt> connectionsCounter_ =
65 "connections_total_number",
73 ProcessingPolicy processingPolicy,
74 std::optional<size_t> maxParallelRequests,
76 std::optional<size_t> maxSubscriptionSendQueueSize,
78 OnDisconnectHook onDisconnectHook,
79 OnIpChangeHook onIpChangeHook
82 ConnectionHandler(ConnectionHandler&&) =
delete;
84 static constexpr std::chrono::milliseconds kCLOSE_CONNECTION_TIMEOUT{500};
87 onGet(std::string
const& target, MessageHandler handler);
90 onPost(std::string
const& target, MessageHandler handler);
93 onWs(MessageHandler handler);
96 processConnection(ConnectionPtr connection, boost::asio::yield_context yield);
99 stopConnection(
Connection& connection, boost::asio::yield_context yield);
102 stop(boost::asio::yield_context yield);
116 handleError(Error
const& error,
Connection const& connection)
const;
126 sequentRequestResponseLoop(
129 boost::asio::yield_context yield
133 parallelRequestResponseLoop(
136 boost::asio::yield_context yield
144 boost::asio::yield_context yield
152 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