]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #pragma once | |
5 | ||
9f95a23c TL |
6 | #include <seastar/core/timer.hh> |
7 | ||
f67539c2 | 8 | #include "crimson/common/gated.h" |
9f95a23c TL |
9 | #include "crimson/net/Dispatcher.h" |
10 | #include "crimson/net/Fwd.h" | |
11 | #include "mon/MgrMap.h" | |
12 | ||
13 | template<typename Message> using Ref = boost::intrusive_ptr<Message>; | |
14 | namespace crimson::net { | |
15 | class Messenger; | |
16 | } | |
17 | ||
18 | class MMgrMap; | |
19 | class MMgrConfigure; | |
20 | ||
21 | namespace crimson::mgr | |
22 | { | |
23 | ||
24 | // implement WithStats if you want to report stats to mgr periodically | |
25 | class WithStats { | |
26 | public: | |
1e59de90 | 27 | virtual seastar::future<MessageURef> get_stats() const = 0; |
9f95a23c TL |
28 | virtual ~WithStats() {} |
29 | }; | |
30 | ||
31 | class Client : public crimson::net::Dispatcher { | |
32 | public: | |
33 | Client(crimson::net::Messenger& msgr, | |
34 | WithStats& with_stats); | |
35 | seastar::future<> start(); | |
36 | seastar::future<> stop(); | |
f67539c2 TL |
37 | void report(); |
38 | ||
9f95a23c | 39 | private: |
f67539c2 TL |
40 | std::optional<seastar::future<>> ms_dispatch( |
41 | crimson::net::ConnectionRef conn, Ref<Message> m) override; | |
42 | void ms_handle_reset(crimson::net::ConnectionRef conn, bool is_replace) final; | |
aee94f69 | 43 | void ms_handle_connect(crimson::net::ConnectionRef conn, seastar::shard_id) final; |
f67539c2 | 44 | seastar::future<> handle_mgr_map(crimson::net::ConnectionRef conn, |
9f95a23c | 45 | Ref<MMgrMap> m); |
f67539c2 | 46 | seastar::future<> handle_mgr_conf(crimson::net::ConnectionRef conn, |
9f95a23c TL |
47 | Ref<MMgrConfigure> m); |
48 | seastar::future<> reconnect(); | |
9f95a23c | 49 | |
f67539c2 TL |
50 | void print(std::ostream&) const; |
51 | friend std::ostream& operator<<(std::ostream& out, const Client& client); | |
9f95a23c TL |
52 | private: |
53 | MgrMap mgrmap; | |
54 | crimson::net::Messenger& msgr; | |
55 | WithStats& with_stats; | |
56 | crimson::net::ConnectionRef conn; | |
f67539c2 TL |
57 | seastar::timer<seastar::lowres_clock> report_timer; |
58 | crimson::common::Gated gate; | |
aee94f69 | 59 | uint64_t last_config_bl_version = 0; |
9f95a23c TL |
60 | }; |
61 | ||
f67539c2 TL |
62 | inline std::ostream& operator<<(std::ostream& out, const Client& client) { |
63 | client.print(out); | |
64 | return out; | |
65 | } | |
66 | ||
9f95a23c | 67 | } |
1e59de90 TL |
68 | |
69 | #if FMT_VERSION >= 90000 | |
70 | template <> struct fmt::formatter<crimson::mgr::Client> : fmt::ostream_formatter {}; | |
71 | #endif |