Modern C++ Kafka API
Interceptors.h
1 #pragma once
2 
3 #include <kafka/Project.h>
4 
5 #include <functional>
6 
7 
8 namespace KAFKA_API { namespace clients {
9 
14 {
15 public:
19  using ThreadStartCb = std::function<void(const std::string&, const std::string&)>;
20 
24  using ThreadExitCb = std::function<void(const std::string&, const std::string&)>;
25 
29  using BrokerStateChangeCb = std::function<void(int, const std::string&, const std::string&, int, const std::string&)>;
30 
34  Interceptors& onThreadStart(ThreadStartCb cb) { _valid = true; _threadStartCb = std::move(cb); return *this; }
35 
39  Interceptors& onThreadExit(ThreadExitCb cb) { _valid = true; _threadExitCb = std::move(cb); return *this; }
40 
44  Interceptors& onBrokerStateChange(BrokerStateChangeCb cb) { _valid = true; _brokerStateChangeCb = std::move(cb); return *this; }
45 
49  ThreadStartCb onThreadStart() const { return _threadStartCb; }
50 
54  ThreadExitCb onThreadExit() const { return _threadExitCb; }
55 
59  BrokerStateChangeCb onBrokerStateChange() const { return _brokerStateChangeCb; }
60 
64  bool empty() const { return !_valid; }
65 
66 private:
67  ThreadStartCb _threadStartCb;
68  ThreadExitCb _threadExitCb;
69  BrokerStateChangeCb _brokerStateChangeCb;
70 
71  bool _valid = false;
72 };
73 
74 } } // end of KAFKA_API::clients
75 
Interceptors for Kafka clients.
Definition: Interceptors.h:14
std::function< void(const std::string &, const std::string &)> ThreadExitCb
Callback type for thread-exit interceptor.
Definition: Interceptors.h:24
Interceptors & onBrokerStateChange(BrokerStateChangeCb cb)
Set interceptor for broker state change.
Definition: Interceptors.h:44
Interceptors & onThreadStart(ThreadStartCb cb)
Set interceptor for thread start.
Definition: Interceptors.h:34
Interceptors & onThreadExit(ThreadExitCb cb)
Set interceptor for thread exit.
Definition: Interceptors.h:39
BrokerStateChangeCb onBrokerStateChange() const
Get interceptor for broker state change.
Definition: Interceptors.h:59
ThreadExitCb onThreadExit() const
Get interceptor for thread exit.
Definition: Interceptors.h:54
std::function< void(int, const std::string &, const std::string &, int, const std::string &)> BrokerStateChangeCb
Callback type for broker-state-change interceptor.
Definition: Interceptors.h:29
bool empty() const
Check if there's no interceptor.
Definition: Interceptors.h:64
std::function< void(const std::string &, const std::string &)> ThreadStartCb
Callback type for thread-start interceptor.
Definition: Interceptors.h:19
ThreadStartCb onThreadStart() const
Get interceptor for thread start.
Definition: Interceptors.h:49