diff --git a/libs/server-sdk/include/launchdarkly/server_side/config/builders/data_system/lazy_load_builder.hpp b/libs/server-sdk/include/launchdarkly/server_side/config/builders/data_system/lazy_load_builder.hpp index abe68288c..b6945a770 100644 --- a/libs/server-sdk/include/launchdarkly/server_side/config/builders/data_system/lazy_load_builder.hpp +++ b/libs/server-sdk/include/launchdarkly/server_side/config/builders/data_system/lazy_load_builder.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include @@ -25,8 +25,7 @@ namespace launchdarkly::server_side::config::builders { * another SDK) is necessary. */ struct LazyLoadBuilder { - using SourcePtr = - std::shared_ptr; + using SourcePtr = std::shared_ptr; using EvictionPolicy = built::LazyLoadConfig::EvictionPolicy; /** * \brief Constructs a new LazyLoadBuilder. @@ -35,7 +34,7 @@ struct LazyLoadBuilder { /** * \brief Specify the source of the data. - * \param source Component implementing ISerializedDataPullSource. + * \param source Component implementing ISerializedDataReader. * \return Reference to this. */ LazyLoadBuilder& Source(SourcePtr source); diff --git a/libs/server-sdk/include/launchdarkly/server_side/config/built/data_system/lazy_load_config.hpp b/libs/server-sdk/include/launchdarkly/server_side/config/built/data_system/lazy_load_config.hpp index e4517def4..855ff2c51 100644 --- a/libs/server-sdk/include/launchdarkly/server_side/config/built/data_system/lazy_load_config.hpp +++ b/libs/server-sdk/include/launchdarkly/server_side/config/built/data_system/lazy_load_config.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -19,7 +19,6 @@ struct LazyLoadConfig { EvictionPolicy eviction_policy; std::chrono::milliseconds eviction_ttl; - std::shared_ptr - source; + std::shared_ptr source; }; } // namespace launchdarkly::server_side::config::built diff --git a/libs/server-sdk/include/launchdarkly/server_side/data_interfaces/sources/iserialized_pull_source.hpp b/libs/server-sdk/include/launchdarkly/server_side/data_interfaces/sources/iserialized_data_reader.hpp similarity index 82% rename from libs/server-sdk/include/launchdarkly/server_side/data_interfaces/sources/iserialized_pull_source.hpp rename to libs/server-sdk/include/launchdarkly/server_side/data_interfaces/sources/iserialized_data_reader.hpp index 7d7280fd4..ad6f98197 100644 --- a/libs/server-sdk/include/launchdarkly/server_side/data_interfaces/sources/iserialized_pull_source.hpp +++ b/libs/server-sdk/include/launchdarkly/server_side/data_interfaces/sources/iserialized_data_reader.hpp @@ -10,7 +10,7 @@ namespace launchdarkly::server_side::data_interfaces { /** - * Interface for a data source that provides feature flags and related data in a + * Interface for a data reader that provides feature flags and related data in a * serialized form. * * This interface should be used for database integrations, or any other data @@ -26,14 +26,14 @@ namespace launchdarkly::server_side::data_interfaces { * * Implementations must be thread-safe. */ -class ISerializedDataPullSource { +class ISerializedDataReader { public: - virtual ~ISerializedDataPullSource() = default; - ISerializedDataPullSource(ISerializedDataPullSource const& item) = delete; - ISerializedDataPullSource(ISerializedDataPullSource&& item) = delete; - ISerializedDataPullSource& operator=(ISerializedDataPullSource const&) = + virtual ~ISerializedDataReader() = default; + ISerializedDataReader(ISerializedDataReader const& item) = delete; + ISerializedDataReader(ISerializedDataReader&& item) = delete; + ISerializedDataReader& operator=(ISerializedDataReader const&) = delete; - ISerializedDataPullSource& operator=(ISerializedDataPullSource&&) = delete; + ISerializedDataReader& operator=(ISerializedDataReader&&) = delete; struct Error { std::string message; @@ -74,6 +74,6 @@ class ISerializedDataPullSource { virtual bool Initialized() const = 0; protected: - ISerializedDataPullSource() = default; + ISerializedDataReader() = default; }; } // namespace launchdarkly::server_side::data_interfaces diff --git a/libs/server-sdk/src/CMakeLists.txt b/libs/server-sdk/src/CMakeLists.txt index 9b2bb6fc9..fbbb2c910 100644 --- a/libs/server-sdk/src/CMakeLists.txt +++ b/libs/server-sdk/src/CMakeLists.txt @@ -32,6 +32,8 @@ target_sources(${LIBNAME} data_components/expiration_tracker/expiration_tracker.cpp data_components/memory_store/memory_store.hpp data_components/memory_store/memory_store.cpp + data_components/serialization_adapters/json_data_reader.hpp + data_components/serialization_adapters/json_data_reader.cpp data_systems/background_sync/sources/noop/null_data_source.hpp data_systems/background_sync/sources/noop/null_data_source.cpp data_systems/background_sync/sources/polling/polling_data_source.hpp diff --git a/libs/server-sdk/src/data_components/serialization_adapters/json_data_reader.cpp b/libs/server-sdk/src/data_components/serialization_adapters/json_data_reader.cpp new file mode 100644 index 000000000..4c14a1672 --- /dev/null +++ b/libs/server-sdk/src/data_components/serialization_adapters/json_data_reader.cpp @@ -0,0 +1,39 @@ +#include "json_data_reader.hpp" + +#include +#include + +#include + +#include + +namespace launchdarkly::server_side::data_components { + +JsonDataReader::JsonDataReader(data_interfaces::ISerializedDataReader& reader) + : flag_kind_(), segment_kind_(), reader_(reader) {} + +data_interfaces::IDataReader::Single +JsonDataReader::GetFlag(std::string const& key) const { + return Deserialize(flag_kind_, key); +} + +data_interfaces::IDataReader::Single +JsonDataReader::GetSegment(std::string const& key) const { + return Deserialize(segment_kind_, key); +} + +data_interfaces::IDataReader::Collection +JsonDataReader::AllFlags() const { + // TODO: deserialize then return +} + +data_interfaces::IDataReader::Collection +JsonDataReader::AllSegments() const { + // TODO: deserialize then return +} + +std::string const& JsonDataReader::Identity() const { + return reader_.Identity(); +} + +} // namespace launchdarkly::server_side::data_components diff --git a/libs/server-sdk/src/data_components/serialization_adapters/json_pull_source.hpp b/libs/server-sdk/src/data_components/serialization_adapters/json_data_reader.hpp similarity index 85% rename from libs/server-sdk/src/data_components/serialization_adapters/json_pull_source.hpp rename to libs/server-sdk/src/data_components/serialization_adapters/json_data_reader.hpp index ade66da82..3d3f69558 100644 --- a/libs/server-sdk/src/data_components/serialization_adapters/json_pull_source.hpp +++ b/libs/server-sdk/src/data_components/serialization_adapters/json_data_reader.hpp @@ -1,16 +1,15 @@ #pragma once -#include "../../data_interfaces/source/ipull_source.hpp" +#include "../../data_interfaces/source/idata_reader.hpp" #include "../kinds/kinds.hpp" -#include +#include namespace launchdarkly::server_side::data_components { -class JsonSource final : public data_interfaces::IPullSource { +class JsonDataReader final : public data_interfaces::IDataReader { public: - explicit JsonSource( - data_interfaces::ISerializedDataPullSource& json_source); + explicit JsonDataReader(data_interfaces::ISerializedDataReader& reader); [[nodiscard]] Single GetFlag( std::string const& key) const override; @@ -31,7 +30,7 @@ class JsonSource final : public data_interfaces::IPullSource { Single> Deserialize( DataKind const& kind, std::string const& key) const { - auto result = source_.Get(kind, key); + auto result = reader_.Get(kind, key); if (!result) { /* the actual fetch failed */ @@ -66,7 +65,7 @@ class JsonSource final : public data_interfaces::IPullSource { FlagKind const flag_kind_; FlagKind const segment_kind_; - data_interfaces::ISerializedDataPullSource& source_; + data_interfaces::ISerializedDataReader& reader_; }; } // namespace launchdarkly::server_side::data_components diff --git a/libs/server-sdk/src/data_components/serialization_adapters/json_pull_source.cpp b/libs/server-sdk/src/data_components/serialization_adapters/json_pull_source.cpp deleted file mode 100644 index 9a854148e..000000000 --- a/libs/server-sdk/src/data_components/serialization_adapters/json_pull_source.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "json_pull_source.hpp" - -#include -#include - -#include - -#include - -namespace launchdarkly::server_side::data_components { - -JsonSource::JsonSource(data_interfaces::ISerializedDataPullSource& json_source) - : flag_kind_(), segment_kind_(), source_(json_source) {} - - -data_interfaces::IPullSource::ItemResult -JsonSource::GetFlag(std::string const& key) const { - return Deserialize(flag_kind_, key); -} - -data_interfaces::IPullSource::ItemResult -JsonSource::GetSegment(std::string const& key) const { - return Deserialize(segment_kind_, key); -} - -data_interfaces::IPullSource::AllResult -JsonSource::AllFlags() const { - // TODO: deserialize then return - -} - -data_interfaces::IPullSource::AllResult -JsonSource::AllSegments() const { - // TODO: deserialize then return -} - -std::string const& JsonSource::Identity() const { - return source_.Identity(); -} - -bool JsonSource::Initialized() const { - return source_.Initialized(); -} - -} // namespace launchdarkly::server_side::data_components diff --git a/libs/server-sdk/src/data_interfaces.cpp b/libs/server-sdk/src/data_interfaces.cpp index 48f6e36ac..030e9b2c5 100644 --- a/libs/server-sdk/src/data_interfaces.cpp +++ b/libs/server-sdk/src/data_interfaces.cpp @@ -1,7 +1,7 @@ #include "data_interfaces/destination/idestination.hpp" #include "data_interfaces/destination/iserialized_destination.hpp" -#include "data_interfaces/source/ipull_source.hpp" -#include "data_interfaces/source/ipush_source.hpp" +#include "data_interfaces/source/idata_reader.hpp" +#include "data_interfaces/source/idata_synchronizer.hpp" #include "data_interfaces/store/istore.hpp" #include "data_interfaces/system/idata_system.hpp" diff --git a/libs/server-sdk/src/data_interfaces/source/ipull_source.hpp b/libs/server-sdk/src/data_interfaces/source/idata_reader.hpp similarity index 83% rename from libs/server-sdk/src/data_interfaces/source/ipull_source.hpp rename to libs/server-sdk/src/data_interfaces/source/idata_reader.hpp index d6fd142c6..8829daddb 100644 --- a/libs/server-sdk/src/data_interfaces/source/ipull_source.hpp +++ b/libs/server-sdk/src/data_interfaces/source/idata_reader.hpp @@ -11,14 +11,14 @@ namespace launchdarkly::server_side::data_interfaces { /** - * \brief IPullSource obtains data on-demand. Calls to obtain data may fail, so + * \brief IDataReader obtains data on-demand. Calls to obtain data may fail, so * the getter methods use tl::expected in order to propagate error codes. * - * The IPullSource does not perform caching, so parent components must be + * The IDataReader does not perform caching, so parent components must be * careful to avoid repeatedly fetching data (i.e. use a cache.) * */ -class IPullSource { +class IDataReader { public: using Error = std::string; @@ -67,14 +67,14 @@ class IPullSource { */ [[nodiscard]] virtual std::string const& Identity() const = 0; - virtual ~IPullSource() = default; - IPullSource(IPullSource const& item) = delete; - IPullSource(IPullSource&& item) = delete; - IPullSource& operator=(IPullSource const&) = delete; - IPullSource& operator=(IPullSource&&) = delete; + virtual ~IDataReader() = default; + IDataReader(IDataReader const& item) = delete; + IDataReader(IDataReader&& item) = delete; + IDataReader& operator=(IDataReader const&) = delete; + IDataReader& operator=(IDataReader&&) = delete; protected: - IPullSource() = default; + IDataReader() = default; }; } // namespace launchdarkly::server_side::data_interfaces diff --git a/libs/server-sdk/src/data_interfaces/source/ipush_source.hpp b/libs/server-sdk/src/data_interfaces/source/idata_synchronizer.hpp similarity index 71% rename from libs/server-sdk/src/data_interfaces/source/ipush_source.hpp rename to libs/server-sdk/src/data_interfaces/source/idata_synchronizer.hpp index fd24538c5..ea2facf25 100644 --- a/libs/server-sdk/src/data_interfaces/source/ipush_source.hpp +++ b/libs/server-sdk/src/data_interfaces/source/idata_synchronizer.hpp @@ -9,10 +9,10 @@ namespace launchdarkly::server_side::data_interfaces { /** - * \brief IPushSource obtains data via a push synchronization mechanism, - * updating a local cache whenever changes are made upstream. + * \brief IDataSynchronizer obtains data via a background synchronization + * mechanism, updating a local cache whenever changes are made upstream. */ -class IPushSource { +class IDataSynchronizer { public: /** * \brief Initialize the source, optionally with an initial data set. Init @@ -41,14 +41,14 @@ class IPushSource { */ [[nodiscard]] virtual std::string const& Identity() const = 0; - virtual ~IPushSource() = default; - IPushSource(IPushSource const& item) = delete; - IPushSource(IPushSource&& item) = delete; - IPushSource& operator=(IPushSource const&) = delete; - IPushSource& operator=(IPushSource&&) = delete; + virtual ~IDataSynchronizer() = default; + IDataSynchronizer(IDataSynchronizer const& item) = delete; + IDataSynchronizer(IDataSynchronizer&& item) = delete; + IDataSynchronizer& operator=(IDataSynchronizer const&) = delete; + IDataSynchronizer& operator=(IDataSynchronizer&&) = delete; protected: - IPushSource() = default; + IDataSynchronizer() = default; }; } // namespace launchdarkly::server_side::data_interfaces diff --git a/libs/server-sdk/src/data_systems/background_sync/background_sync_system.hpp b/libs/server-sdk/src/data_systems/background_sync/background_sync_system.hpp index 7c551573f..0403a7845 100644 --- a/libs/server-sdk/src/data_systems/background_sync/background_sync_system.hpp +++ b/libs/server-sdk/src/data_systems/background_sync/background_sync_system.hpp @@ -3,7 +3,7 @@ #include "../../data_components/change_notifier/change_notifier.hpp" #include "../../data_components/memory_store/memory_store.hpp" #include "../../data_components/status_notifications/data_source_status_manager.hpp" -#include "../../data_interfaces/source/ipush_source.hpp" +#include "../../data_interfaces/source/idata_synchronizer.hpp" #include "../../data_interfaces/system/idata_system.hpp" #include @@ -64,6 +64,6 @@ class BackgroundSync final : public data_interfaces::IDataSystem { data_components::ChangeNotifier change_notifier_; // Needs to be shared to that the source can keep itself alive through // async operations. - std::shared_ptr synchronizer_; + std::shared_ptr synchronizer_; }; } // namespace launchdarkly::server_side::data_systems diff --git a/libs/server-sdk/src/data_systems/background_sync/sources/noop/null_data_source.hpp b/libs/server-sdk/src/data_systems/background_sync/sources/noop/null_data_source.hpp index cd4619928..695eb7198 100644 --- a/libs/server-sdk/src/data_systems/background_sync/sources/noop/null_data_source.hpp +++ b/libs/server-sdk/src/data_systems/background_sync/sources/noop/null_data_source.hpp @@ -1,13 +1,13 @@ #pragma once #include "../../../../data_components/status_notifications/data_source_status_manager.hpp" -#include "../../../../data_interfaces/source/ipush_source.hpp" +#include "../../../../data_interfaces/source/idata_synchronizer.hpp" #include namespace launchdarkly::server_side::data_systems { -class NullDataSource : public data_interfaces::IPushSource { +class NullDataSource : public data_interfaces::IDataSynchronizer { public: explicit NullDataSource( boost::asio::any_io_executor exec, diff --git a/libs/server-sdk/src/data_systems/background_sync/sources/polling/polling_data_source.hpp b/libs/server-sdk/src/data_systems/background_sync/sources/polling/polling_data_source.hpp index 0b87706ae..5dd668cb5 100644 --- a/libs/server-sdk/src/data_systems/background_sync/sources/polling/polling_data_source.hpp +++ b/libs/server-sdk/src/data_systems/background_sync/sources/polling/polling_data_source.hpp @@ -2,7 +2,7 @@ #include "../../../../data_components/status_notifications/data_source_status_manager.hpp" #include "../../../../data_interfaces/destination/idestination.hpp" -#include "../../../../data_interfaces/source/ipush_source.hpp" +#include "../../../../data_interfaces/source/idata_synchronizer.hpp" #include @@ -16,7 +16,7 @@ namespace launchdarkly::server_side::data_systems { class PollingDataSource - : public data_interfaces::IPushSource, + : public data_interfaces::IDataSynchronizer, public std::enable_shared_from_this { public: PollingDataSource(config::built::ServiceEndpoints const& endpoints, diff --git a/libs/server-sdk/src/data_systems/background_sync/sources/streaming/streaming_data_source.hpp b/libs/server-sdk/src/data_systems/background_sync/sources/streaming/streaming_data_source.hpp index f16861ff0..1a455b66e 100644 --- a/libs/server-sdk/src/data_systems/background_sync/sources/streaming/streaming_data_source.hpp +++ b/libs/server-sdk/src/data_systems/background_sync/sources/streaming/streaming_data_source.hpp @@ -4,7 +4,7 @@ #include "../../../../data_components/status_notifications/data_source_status_manager.hpp" #include "../../../../data_interfaces/destination/idestination.hpp" -#include "../../../../data_interfaces/source/ipush_source.hpp" +#include "../../../../data_interfaces/source/idata_synchronizer.hpp" #include #include @@ -24,7 +24,7 @@ using namespace std::chrono_literals; namespace launchdarkly::server_side::data_systems { class StreamingDataSource final - : public data_interfaces::IPushSource, + : public data_interfaces::IDataSynchronizer, public std::enable_shared_from_this { public: StreamingDataSource( diff --git a/libs/server-sdk/src/data_systems/lazy_load/lazy_load_system.hpp b/libs/server-sdk/src/data_systems/lazy_load/lazy_load_system.hpp index 49db2573d..697b77b8e 100644 --- a/libs/server-sdk/src/data_systems/lazy_load/lazy_load_system.hpp +++ b/libs/server-sdk/src/data_systems/lazy_load/lazy_load_system.hpp @@ -80,8 +80,8 @@ class LazyLoad : public data_interfaces::IDataSystem { } mutable data_components::MemoryStore cache_; - std::shared_ptr raw_source_; - data_components::JsonSource source_; + std::shared_ptr raw_source_; + data_components::JsonDataReader source_; mutable data_components::ExpirationTracker tracker_; std::function()> time_;