-
Notifications
You must be signed in to change notification settings - Fork 11
chore: adds data system configuration APIs #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/DataSystemBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| package com.launchdarkly.sdk.server.integrations; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import com.launchdarkly.sdk.server.subsystems.ComponentConfigurer; | ||
| import com.launchdarkly.sdk.server.subsystems.DataSource; | ||
| import com.launchdarkly.sdk.server.subsystems.DataStore; | ||
| import com.launchdarkly.sdk.server.subsystems.DataSystemConfiguration; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Configuration builder for the SDK's data acquisition and storage strategy. | ||
| * <p> | ||
| * This class is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. | ||
| * It is in early access. If you want access to this feature please join the EAP. https://launchdarkly.com/docs/sdk/features/data-saving-mode | ||
| * </p> | ||
| */ | ||
| public final class DataSystemBuilder { | ||
|
|
||
| private final List<ComponentConfigurer<DataSource>> initializers = new ArrayList<>(); | ||
| private final List<ComponentConfigurer<DataSource>> synchronizers = new ArrayList<>(); | ||
| private ComponentConfigurer<DataSource> fDv1FallbackSynchronizer; | ||
| private ComponentConfigurer<DataStore> persistentStore; | ||
| private DataSystemConfiguration.DataStoreMode persistentDataStoreMode; | ||
|
|
||
| /** | ||
| * Add one or more initializers to the builder. | ||
| * To replace initializers, please refer to {@link #replaceInitializers(ComponentConfigurer[])}. | ||
| * | ||
| * @param initializers the initializers to add | ||
| * @return a reference to the builder | ||
| */ | ||
| public DataSystemBuilder initializers(ComponentConfigurer<DataSource>... initializers) { | ||
| for (ComponentConfigurer<DataSource> initializer : initializers) { | ||
| this.initializers.add(initializer); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Replaces any existing initializers with the given initializers. | ||
| * To add initializers, please refer to {@link #initializers(ComponentConfigurer[])}. | ||
| * | ||
| * @param initializers the initializers to replace the current initializers with | ||
| * @return a reference to this builder | ||
| */ | ||
| public DataSystemBuilder replaceInitializers(ComponentConfigurer<DataSource>... initializers) { | ||
| this.initializers.clear(); | ||
| for (ComponentConfigurer<DataSource> initializer : initializers) { | ||
| this.initializers.add(initializer); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Add one or more synchronizers to the builder. | ||
| * To replace synchronizers, please refer to {@link #replaceSynchronizers(ComponentConfigurer[])}. | ||
| * | ||
| * @param synchronizers the synchronizers to add | ||
| * @return a reference to the builder | ||
| */ | ||
| public DataSystemBuilder synchronizers(ComponentConfigurer<DataSource>... synchronizers) { | ||
| for (ComponentConfigurer<DataSource> synchronizer : synchronizers) { | ||
| this.synchronizers.add(synchronizer); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Replaces any existing synchronizers with the given synchronizers. | ||
| * To add synchronizers, please refer to {@link #synchronizers(ComponentConfigurer[])}. | ||
| * | ||
| * @param synchronizers the synchronizers to replace the current synchronizers with | ||
| * @return a reference to this builder | ||
| */ | ||
| public DataSystemBuilder replaceSynchronizers(ComponentConfigurer<DataSource>... synchronizers) { | ||
| this.synchronizers.clear(); | ||
| for (ComponentConfigurer<DataSource> synchronizer : synchronizers) { | ||
| this.synchronizers.add(synchronizer); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Configure the FDv1 fallback synchronizer. | ||
| * <p> | ||
| * LaunchDarkly can instruct the SDK to fall back to this synchronizer. | ||
| * </p> | ||
| * | ||
| * @param fDv1FallbackSynchronizer the FDv1 fallback synchronizer | ||
| * @return a reference to the builder | ||
| */ | ||
| public DataSystemBuilder fDv1FallbackSynchronizer(ComponentConfigurer<DataSource> fDv1FallbackSynchronizer) { | ||
| this.fDv1FallbackSynchronizer = fDv1FallbackSynchronizer; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Configures the persistent data store. | ||
| * <p> | ||
| * The SDK will use the persistent data store to store feature flag data. | ||
| * </p> | ||
| * | ||
| * @param persistentStore the persistent data store | ||
| * @param mode the mode for the persistent data store | ||
| * @return a reference to the builder | ||
| * @see DataSystemConfiguration.DataStoreMode | ||
| */ | ||
| public DataSystemBuilder persistentStore(ComponentConfigurer<DataStore> persistentStore, DataSystemConfiguration.DataStoreMode mode) { | ||
| this.persistentStore = persistentStore; | ||
| this.persistentDataStoreMode = mode; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Build the data system configuration. | ||
| * <p> | ||
| * This method is internal and should not be called by application code. | ||
| * This function should remain internal. | ||
| * </p> | ||
| * | ||
| * @return the data system configuration | ||
| */ | ||
| public DataSystemConfiguration build() { | ||
| return new DataSystemConfiguration( | ||
| ImmutableList.copyOf(initializers), | ||
| ImmutableList.copyOf(synchronizers), | ||
| fDv1FallbackSynchronizer, | ||
| persistentStore, | ||
| persistentDataStoreMode); | ||
| } | ||
| } | ||
|
|
46 changes: 46 additions & 0 deletions
46
...k/server/src/main/java/com/launchdarkly/sdk/server/integrations/DataSystemComponents.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.launchdarkly.sdk.server.integrations; | ||
|
|
||
| import com.launchdarkly.sdk.server.Components; | ||
|
|
||
| /** | ||
| * Components for use with the data system. | ||
| * <p> | ||
| * This class is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. | ||
| * It is in early access. If you want access to this feature please join the EAP. https://launchdarkly.com/docs/sdk/features/data-saving-mode | ||
| * </p> | ||
| */ | ||
| public final class DataSystemComponents { | ||
|
|
||
| private DataSystemComponents() {} | ||
|
|
||
| /** | ||
| * Get a builder for a polling data source. | ||
| * | ||
| * @return the polling data source builder | ||
| */ | ||
| public static FDv2PollingDataSourceBuilder polling() { | ||
| return new FDv2PollingDataSourceBuilder(); | ||
| } | ||
|
|
||
| /** | ||
| * Get a builder for a streaming data source. | ||
| * | ||
| * @return the streaming data source builder | ||
| */ | ||
| public static FDv2StreamingDataSourceBuilder streaming() { | ||
| return new FDv2StreamingDataSourceBuilder(); | ||
| } | ||
|
|
||
| /** | ||
| * Get a builder for a FDv1 compatible polling data source. | ||
| * <p> | ||
| * This is intended for use as a fallback. | ||
| * </p> | ||
| * | ||
| * @return the FDv1 compatible polling data source builder | ||
| */ | ||
| public static PollingDataSourceBuilder fDv1Polling() { | ||
| return Components.pollingDataSource(); | ||
| } | ||
| } | ||
|
|
158 changes: 158 additions & 0 deletions
158
lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/DataSystemModes.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| package com.launchdarkly.sdk.server.integrations; | ||
|
|
||
| import com.launchdarkly.sdk.server.subsystems.ComponentConfigurer; | ||
| import com.launchdarkly.sdk.server.subsystems.DataStore; | ||
| import com.launchdarkly.sdk.server.subsystems.DataSystemConfiguration; | ||
|
|
||
| /** | ||
| * A set of different data system modes which provide pre-configured {@link DataSystemBuilder}s. | ||
| * <p> | ||
| * This class is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. | ||
| * It is in early access. If you want access to this feature please join the EAP. https://launchdarkly.com/docs/sdk/features/data-saving-mode | ||
| * </p> | ||
| * <p> | ||
| * This implementation is non-static to allow for easy usage with "Components". | ||
| * Where we can return an instance of this object, and the user can chain into their desired configuration. | ||
| * </p> | ||
| */ | ||
| public final class DataSystemModes { | ||
| // This implementation is non-static to allow for easy usage with "Components". | ||
| // Where we can return an instance of this object, and the user can chain into their desired configuration. | ||
|
|
||
| /** | ||
| * Configure's LaunchDarkly's recommended flag data acquisition strategy. | ||
| * <p> | ||
| * Currently, it operates a two-phase method for getting data: first, it requests data from LaunchDarkly's | ||
| * global CDN. Then, it initiates a streaming connection to LaunchDarkly's Flag Delivery services to receive | ||
| * real-time updates. If the streaming connection is interrupted for an extended period of time, the SDK will | ||
| * automatically fall back to polling the global CDN for updates. | ||
| * </p> | ||
| * <p> | ||
| * <b>Example:</b> | ||
| * </p> | ||
| * <pre><code> | ||
| * LDConfig config = new LDConfig.Builder("my-sdk-key") | ||
| * .dataSystem(Components.dataSystem().defaultMode()); | ||
| * </code></pre> | ||
| * | ||
| * @return a builder containing our default configuration | ||
| */ | ||
| public DataSystemBuilder defaultMode() { | ||
| return custom() | ||
| .initializers(DataSystemComponents.polling()) | ||
| .synchronizers(DataSystemComponents.streaming(), DataSystemComponents.polling()) | ||
| .fDv1FallbackSynchronizer(DataSystemComponents.fDv1Polling()); | ||
| } | ||
|
|
||
| /** | ||
| * Configures the SDK to stream data without polling for the initial payload. | ||
| * <p> | ||
| * This is not our recommended strategy, which is {@link #defaultMode()}, but it may be | ||
| * suitable for some situations. | ||
| * </p> | ||
| * <p> | ||
| * This configuration will not automatically fall back to polling, but it can be instructed by LaunchDarkly | ||
| * to fall back to polling in certain situations. | ||
| * </p> | ||
| * <p> | ||
| * <b>Example:</b> | ||
| * </p> | ||
| * <pre><code> | ||
| * LDConfig config = new LDConfig.Builder("my-sdk-key") | ||
| * .dataSystem(Components.dataSystem().streaming()); | ||
| * </code></pre> | ||
| * | ||
| * @return a builder containing a primarily streaming configuration | ||
| */ | ||
| public DataSystemBuilder streaming() { | ||
| return custom() | ||
| .synchronizers(DataSystemComponents.streaming()) | ||
| .fDv1FallbackSynchronizer(DataSystemComponents.fDv1Polling()); | ||
| } | ||
|
|
||
| /** | ||
| * Configure the SDK to poll data instead of receiving real-time updates via a stream. | ||
| * <p> | ||
| * This is not our recommended strategy, which is {@link #defaultMode()}, but it may be | ||
| * required for certain network configurations. | ||
| * </p> | ||
| * <p> | ||
| * <b>Example:</b> | ||
| * </p> | ||
| * <pre><code> | ||
| * LDConfig config = new LDConfig.Builder("my-sdk-key") | ||
| * .dataSystem(Components.dataSystem().polling()); | ||
| * </code></pre> | ||
| * | ||
| * @return a builder containing a polling-only configuration | ||
| */ | ||
| public DataSystemBuilder polling() { | ||
| return custom() | ||
| .synchronizers(DataSystemComponents.polling()) | ||
| .fDv1FallbackSynchronizer(DataSystemComponents.fDv1Polling()); | ||
| } | ||
|
|
||
| /** | ||
| * Configures the SDK to read from a persistent store integration that is populated by Relay Proxy | ||
| * or other SDKs. The SDK will not connect to LaunchDarkly. In this mode, the SDK never writes to the data | ||
| * store. | ||
| * <p> | ||
| * <b>Example:</b> | ||
| * </p> | ||
| * <pre><code> | ||
| * LDConfig config = new LDConfig.Builder("my-sdk-key") | ||
| * .dataSystem(Components.dataSystem().daemon(persistentStore)); | ||
| * </code></pre> | ||
| * | ||
| * @param persistentStore the persistent store configurer | ||
| * @return a builder which is configured for daemon mode | ||
| */ | ||
| public DataSystemBuilder daemon(ComponentConfigurer<DataStore> persistentStore) { | ||
| return custom() | ||
| .persistentStore(persistentStore, DataSystemConfiguration.DataStoreMode.READ_ONLY); | ||
| } | ||
|
|
||
| /** | ||
| * PersistentStore is similar to Default, with the addition of a persistent store integration. Before data has | ||
| * arrived from LaunchDarkly, the SDK is able to evaluate flags using data from the persistent store. | ||
| * Once fresh data is available, the SDK will no longer read from the persistent store, although it will keep | ||
| * it up to date. | ||
| * <p> | ||
| * <b>Example:</b> | ||
| * </p> | ||
| * <pre><code> | ||
| * LDConfig config = new LDConfig.Builder("my-sdk-key") | ||
| * .dataSystem(Components.dataSystem() | ||
| * .persistentStore(Components.persistentDataStore(SomeDatabaseName.dataStore()))); | ||
| * </code></pre> | ||
| * | ||
| * @param persistentStore the persistent store configurer | ||
| * @return a builder which is configured for persistent store mode | ||
| */ | ||
| public DataSystemBuilder persistentStore(ComponentConfigurer<DataStore> persistentStore) { | ||
| return defaultMode() | ||
| .persistentStore(persistentStore, DataSystemConfiguration.DataStoreMode.READ_WRITE); | ||
| } | ||
|
|
||
| /** | ||
| * Custom returns a builder suitable for creating a custom data acquisition strategy. You may configure | ||
| * how the SDK uses a Persistent Store, how the SDK obtains an initial set of data, and how the SDK keeps data | ||
| * up to date. | ||
| * <p> | ||
| * <b>Example:</b> | ||
| * </p> | ||
| * <pre><code> | ||
| * LDConfig config = new LDConfig.Builder("my-sdk-key") | ||
| * .dataSystem(Components.dataSystem().custom() | ||
| * .initializers(DataSystemComponents.polling()) | ||
| * .synchronizers(DataSystemComponents.streaming(), DataSystemComponents.polling()) | ||
| * .fDv1FallbackSynchronizer(DataSystemComponents.fDv1Polling())); | ||
| * </code></pre> | ||
| * | ||
| * @return a builder without any base configuration | ||
| */ | ||
| public DataSystemBuilder custom() { | ||
| return new DataSystemBuilder(); | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reviewers: Made public for
describeConfigurationin the data source builders.