C++ Server-Side SDK
LaunchDarkly SDK
polling_data_source.hpp
1 #pragma once
2 
3 #include "../../../../data_components/status_notifications/data_source_status_manager.hpp"
4 #include "../../../../data_interfaces/destination/idestination.hpp"
5 #include "../../../../data_interfaces/source/idata_synchronizer.hpp"
6 
7 #include <launchdarkly/server_side/config/built/all_built.hpp>
8 
9 #include <launchdarkly/logging/logger.hpp>
10 #include <launchdarkly/network/asio_requester.hpp>
11 
12 #include <boost/asio/any_io_executor.hpp>
13 
14 #include <chrono>
15 
16 namespace launchdarkly::server_side::data_systems {
17 
20  public std::enable_shared_from_this<PollingDataSource> {
21  public:
22  PollingDataSource(boost::asio::any_io_executor const& ioc,
23  Logger const& logger,
25  config::built::ServiceEndpoints const& endpoints,
27  data_source_config,
28  config::built::HttpProperties const& http_properties);
29 
31  data_model::SDKDataSet const* bootstrap_data) override;
32 
33  void ShutdownAsync(std::function<void()> completion) override;
34 
35  [[nodiscard]] std::string const& Identity() const override;
36 
37  private:
38  void DoPoll();
39  void HandlePollResult(network::HttpResult const& res);
40 
41  Logger const& logger_;
42 
43  // Status manager is used to report the status of the data source. It must
44  // outlive the source. This source performs asynchronous
45  // operations, so a completion handler might invoke the status manager after
46  // it has been destroyed.
48 
49  // Responsible for performing HTTP requests using boost::asio.
50  network::AsioRequester requester_;
51 
52  // How long to wait beteween individual polling requests.
53  std::chrono::seconds polling_interval_;
54 
55  // Cached request arguments used in the polling request.
56  network::HttpRequest request_;
57 
58  // Etag can be sent in HTTP request to save bandwidth if the server knows
59  // the response is unchanged.
60  std::optional<std::string> etag_;
61 
62  // Used with polling_interval to schedule polling requests.
63  boost::asio::steady_timer timer_;
64 
65  // The last time the polling HTTP request is initiated.
66  std::chrono::time_point<std::chrono::system_clock> last_poll_start_;
67 
68  // Destination for all data obtained via polling.
70 
71  void StartPollingTimer();
72 };
73 
74 } // namespace launchdarkly::server_side::data_systems
Definition: http_properties.hpp:26
Definition: service_endpoints.hpp:11
Definition: data_source_status_manager.hpp:16
IDataSynchronizer obtains data via a background synchronization mechanism, updating an IDestination w...
Definition: idata_synchronizer.hpp:17
IDestination represents a sink for data received by the SDK. A destination may be a database,...
Definition: idestination.hpp:14
std::string const & Identity() const override
Definition: polling_data_source.cpp:60
void ShutdownAsync(std::function< void()> completion) override
Stops the synchronization mechanism. Stop will be called only once after StartAsync....
Definition: polling_data_source.cpp:250
void StartAsync(data_interfaces::IDestination *dest, data_model::SDKDataSet const *bootstrap_data) override
Starts synchronizing data into the given IDestination.
Definition: polling_data_source.cpp:228
Definition: data_source_config.hpp:36