GPUdb C++ API  Version 7.2.3.0
FailbackPollerService.hpp
Go to the documentation of this file.
1 #ifndef __FAILBACKPOLLERSERVICE_HPP__
2 #define __FAILBACKPOLLERSERVICE_HPP__
3 
4 #include "gpudb/GPUdb.hpp"
5 
6 #include <iostream>
7 #include <thread>
8 #include <atomic>
9 #include <mutex>
10 #include <memory>
11 #include <vector>
12 #include <chrono>
13 
14 
15 namespace gpudb {
17  public:
18  static constexpr int DEFAULT_START_DELAY = 0;
19  static constexpr int DEFAULT_POLLING_INTERVAL = 5; // seconds
20 
21  private:
22 
23  const gpudb::GPUdb& db;
24  std::string primaryUrl;
25  long pollingInterval;
26  std::atomic<bool> is_running;
27  std::mutex service_mutex;
28  std::unique_ptr<std::thread> scheduler;
29 
30  void polling_task();
31 
32  bool poll();
33 
34  void reset_cluster_pointers();
35 
36  public:
37  FailbackPollerService(const gpudb::GPUdb& db, long pollingInterval)
38  : db(db),
39  primaryUrl(db.getPrimaryURL()),
40  pollingInterval(pollingInterval),
41  is_running(false)
42  {}
43 
44  // Delete copy constructor and assignment operator
47 
48  virtual ~FailbackPollerService();
49 
53  bool isRunning();
54 
58  void start();
59 
63  void stop();
64 
65  void restart();
66  };
67 
68 }
69 
70 #endif
FailbackPollerService(const gpudb::GPUdb &db, long pollingInterval)
static constexpr int DEFAULT_POLLING_INTERVAL
static constexpr int DEFAULT_START_DELAY
FailbackPollerService & operator=(const FailbackPollerService &)=delete
void start()
Starts the poller service.
bool isRunning()
Checks whether the poller is running and returns true or false.
void stop()
Stops the poller service.