|
11 | 11 | import com.launchdarkly.sdk.server.FlagsStateOption; |
12 | 12 | import com.launchdarkly.sdk.server.LDClient; |
13 | 13 | import com.launchdarkly.sdk.server.LDConfig; |
| 14 | +import com.launchdarkly.sdk.server.interfaces.ServiceEndpoints; |
14 | 15 | import com.launchdarkly.sdk.server.migrations.Migration; |
15 | 16 | import com.launchdarkly.sdk.server.migrations.MigrationBuilder; |
16 | 17 | import com.launchdarkly.sdk.server.migrations.MigrationExecution; |
|
25 | 26 | import com.launchdarkly.sdk.server.integrations.HooksConfigurationBuilder; |
26 | 27 | import com.launchdarkly.sdk.server.integrations.ServiceEndpointsBuilder; |
27 | 28 | import com.launchdarkly.sdk.server.integrations.StreamingDataSourceBuilder; |
| 29 | +import com.launchdarkly.sdk.server.integrations.PollingDataSourceBuilder; |
28 | 30 | import com.launchdarkly.sdk.server.integrations.DataSystemBuilder; |
29 | 31 | import com.launchdarkly.sdk.server.DataSystemComponents; |
30 | 32 | import com.launchdarkly.sdk.server.integrations.FDv2PollingInitializerBuilder; |
31 | 33 | import com.launchdarkly.sdk.server.integrations.FDv2PollingSynchronizerBuilder; |
32 | 34 | import com.launchdarkly.sdk.server.integrations.FDv2StreamingSynchronizerBuilder; |
33 | 35 | import com.launchdarkly.sdk.server.interfaces.BigSegmentStoreStatusProvider; |
| 36 | +import com.launchdarkly.sdk.server.subsystems.ComponentConfigurer; |
| 37 | +import com.launchdarkly.sdk.server.subsystems.DataSource; |
34 | 38 | import com.launchdarkly.sdk.server.subsystems.DataSourceBuilder; |
35 | 39 | import com.launchdarkly.sdk.server.datasources.Initializer; |
36 | 40 | import com.launchdarkly.sdk.server.datasources.Synchronizer; |
@@ -563,6 +567,22 @@ private LDConfig buildSdkConfig(SdkConfigParams params, String tag) { |
563 | 567 | } |
564 | 568 | } |
565 | 569 |
|
| 570 | + // Configure FDv1 fallback synchronizer |
| 571 | + SdkConfigSynchronizerParams fallbackSynchronizer = |
| 572 | + selectFallbackSynchronizer(params.dataSystem); |
| 573 | + if (fallbackSynchronizer != null) { |
| 574 | + // Set global polling endpoints if the fallback synchronizer has polling with custom base URI |
| 575 | + if (fallbackSynchronizer.polling != null && |
| 576 | + fallbackSynchronizer.polling.baseUri != null) { |
| 577 | + endpoints.polling(fallbackSynchronizer.polling.baseUri); |
| 578 | + } |
| 579 | + |
| 580 | + // Create and configure FDv1 fallback |
| 581 | + ComponentConfigurer<DataSource> fdv1Fallback = |
| 582 | + createFDv1FallbackSynchronizer(fallbackSynchronizer, endpoints); |
| 583 | + dataSystemBuilder.fDv1FallbackSynchronizer(fdv1Fallback); |
| 584 | + } |
| 585 | + |
566 | 586 | builder.dataSystem(dataSystemBuilder); |
567 | 587 | } |
568 | 588 |
|
@@ -601,4 +621,59 @@ private DataSourceBuilder<Synchronizer> createSynchronizer( |
601 | 621 | } |
602 | 622 | return null; |
603 | 623 | } |
| 624 | + |
| 625 | + /** |
| 626 | + * Selects the best synchronizer configuration to use for FDv1 fallback. |
| 627 | + * Prefers polling synchronizers, falls back to primary synchronizer. |
| 628 | + */ |
| 629 | + private static SdkConfigSynchronizerParams selectFallbackSynchronizer( |
| 630 | + SdkConfigDataSystemParams dataSystemParams) { |
| 631 | + |
| 632 | + // Prefer secondary polling synchronizer |
| 633 | + if (dataSystemParams.synchronizers != null && |
| 634 | + dataSystemParams.synchronizers.secondary != null && |
| 635 | + dataSystemParams.synchronizers.secondary.polling != null) { |
| 636 | + return dataSystemParams.synchronizers.secondary; |
| 637 | + } |
| 638 | + |
| 639 | + // Fall back to primary polling synchronizer |
| 640 | + if (dataSystemParams.synchronizers != null && |
| 641 | + dataSystemParams.synchronizers.primary != null && |
| 642 | + dataSystemParams.synchronizers.primary.polling != null) { |
| 643 | + return dataSystemParams.synchronizers.primary; |
| 644 | + } |
| 645 | + |
| 646 | + // Fall back to primary synchronizer (even if streaming) |
| 647 | + if (dataSystemParams.synchronizers != null && |
| 648 | + dataSystemParams.synchronizers.primary != null) { |
| 649 | + return dataSystemParams.synchronizers.primary; |
| 650 | + } |
| 651 | + |
| 652 | + return null; |
| 653 | + } |
| 654 | + |
| 655 | + /** |
| 656 | + * Creates the FDv1 fallback synchronizer based on the selected synchronizer config. |
| 657 | + * FDv1 fallback is always polling-based. |
| 658 | + */ |
| 659 | + private static ComponentConfigurer<DataSource> createFDv1FallbackSynchronizer( |
| 660 | + SdkConfigSynchronizerParams synchronizer, |
| 661 | + ServiceEndpointsBuilder endpoints) { |
| 662 | + |
| 663 | + // FDv1 fallback is always polling-based |
| 664 | + PollingDataSourceBuilder fdv1Polling = Components.pollingDataSource(); |
| 665 | + |
| 666 | + // Configure polling interval if the synchronizer has polling configuration |
| 667 | + if (synchronizer.polling != null) { |
| 668 | + if (synchronizer.polling.pollIntervalMs != null) { |
| 669 | + fdv1Polling.pollInterval(Duration.ofMillis(synchronizer.polling.pollIntervalMs)); |
| 670 | + } |
| 671 | + // Note: FDv1 polling doesn't support per-source service endpoints override, |
| 672 | + // so it will use the global service endpoints configuration |
| 673 | + } |
| 674 | + // If streaming synchronizer, use default polling interval |
| 675 | + // (no additional configuration needed) |
| 676 | + |
| 677 | + return fdv1Polling; |
| 678 | + } |
604 | 679 | } |
0 commit comments