hmbdc
simplify-high-performance-messaging-programming
StuckClientPurger.hpp
1 #include "hmbdc/Copyright.hpp"
2 #pragma once
3 #include "hmbdc/app/Client.hpp"
4 
5 #include <iostream>
6 #include <unistd.h>
7 
8 namespace hmbdc { namespace app {
9 
10 template <typename Buffer>
12 : Client<StuckClientPurger<Buffer>> {
13  StuckClientPurger(uint32_t secondsBewteenPurges
14  , Buffer& buffer)
15  : secondsBewteenPurges_(secondsBewteenPurges)
16  , secondsCurrent_(0)
17  , buffer_(buffer){
18  }
19 
20  void invokedCb(size_t) override {
21  using namespace std;
22  sleep(1);
23  secondsCurrent_++;
24  if (secondsBewteenPurges_ == secondsCurrent_) {
25  auto res = buffer_.purge();
26  if (res) {
27  cerr << "purgedMask=" << hex << res << dec << endl;
28  }
29  buffer_.tryPut(MessageWrap<Flush>());
30  secondsCurrent_ = 0;
31  }
32  }
33 
34  void stoppedCb(std::exception const& e) override {
35  using namespace std;
36  cerr << e.what() << endl;
37  };
38 
39  char const* hmbdcName() const {
40  return "purger";
41  }
42 
43  std::tuple<char const*, int> schedSpec() const {
44  return std::make_tuple("SCHED_IDLE", 0);
45  }
46 
47 private:
48  uint32_t secondsBewteenPurges_;
49  uint32_t secondsCurrent_;
50  Buffer& buffer_;
51 };
52 
53 }}
Definition: StuckClientPurger.hpp:11
Definition: Topic.hpp:44
void invokedCb(size_t) override
this callback is called all the time (frequently) - the exact timing is after a batch of messages are...
Definition: StuckClientPurger.hpp:20
Definition: Message.hpp:112
void stoppedCb(std::exception const &e) override
callback called when this Client is taken out of message dispatching
Definition: StuckClientPurger.hpp:34
A Client represents a thread of execution/a task. The execution is managed by a Context. a Client object could participate in message dispatching as the receiver of specifed message types.
Definition: Client.hpp:57
Definition: Base.hpp:13