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  sleep(1);
22  secondsCurrent_++;
23  if (secondsBewteenPurges_ == secondsCurrent_) {
24  auto res = buffer_.purge();
25  if (res) {
26  std::cerr << "purgedMask=" << std::hex << res << std::dec << std::endl;
27  }
28  buffer_.tryPut(MessageWrap<Flush>());
29  secondsCurrent_ = 0;
30  }
31  }
32 
33  void stoppedCb(std::exception const& e) override {
34  std::cerr << e.what() << std::endl;
35  };
36 
37  char const* hmbdcName() const {
38  return "purger";
39  }
40 
41  std::tuple<char const*, int> schedSpec() const {
42  return std::make_tuple("SCHED_IDLE", 0);
43  }
44 
45 private:
46  uint32_t secondsBewteenPurges_;
47  uint32_t secondsCurrent_;
48  Buffer& buffer_;
49 };
50 
51 }}
Definition: StuckClientPurger.hpp:11
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:263
void stoppedCb(std::exception const &e) override
callback called when this Client is taken out of message dispatching
Definition: StuckClientPurger.hpp:33
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:128
Definition: Base.hpp:12