|
33 | 33 | import com.launchdarkly.sdk.server.integrations.FDv2PollingSynchronizerBuilder; |
34 | 34 | import com.launchdarkly.sdk.server.integrations.FDv2StreamingSynchronizerBuilder; |
35 | 35 | import com.launchdarkly.sdk.server.interfaces.BigSegmentStoreStatusProvider; |
36 | | -import com.launchdarkly.sdk.server.subsystems.ComponentConfigurer; |
37 | | -import com.launchdarkly.sdk.server.subsystems.DataSource; |
38 | 36 | import com.launchdarkly.sdk.server.subsystems.DataSourceBuilder; |
39 | 37 | import com.launchdarkly.sdk.server.datasources.Initializer; |
40 | 38 | import com.launchdarkly.sdk.server.datasources.Synchronizer; |
@@ -570,20 +568,23 @@ private LDConfig buildSdkConfig(SdkConfigParams params, String tag) { |
570 | 568 | } |
571 | 569 | } |
572 | 570 |
|
573 | | - // Configure FDv1 fallback synchronizer (pick first polling, else first synchronizer) |
574 | | - SdkConfigSynchronizerParams fallbackSynchronizer = |
575 | | - selectFallbackSynchronizer(params.dataSystem.synchronizers); |
576 | | - if (fallbackSynchronizer != null) { |
577 | | - // Set global polling endpoints if the fallback synchronizer has polling with custom base URI |
578 | | - if (fallbackSynchronizer.polling != null && |
579 | | - fallbackSynchronizer.polling.baseUri != null) { |
580 | | - endpoints.polling(fallbackSynchronizer.polling.baseUri); |
| 571 | + // Configure the FDv1 fallback synchronizer. This is engaged only when the server returns |
| 572 | + // the X-LD-FD-Fallback directive; it lives outside the FDv2 Primary/Fallback synchronizer |
| 573 | + // chain configured above. The test harness sends this as a dedicated top-level field -- |
| 574 | + // do not infer it from the FDv2 synchronizer list. |
| 575 | + if (params.dataSystem.fdv1Fallback != null) { |
| 576 | + SdkConfigPollingParams fdv1Params = params.dataSystem.fdv1Fallback; |
| 577 | + if (fdv1Params.baseUri != null) { |
| 578 | + endpoints.polling(fdv1Params.baseUri); |
581 | 579 | } |
582 | | - |
583 | | - // Create and configure FDv1 fallback |
584 | | - ComponentConfigurer<DataSource> fdv1Fallback = |
585 | | - createFDv1FallbackSynchronizer(fallbackSynchronizer); |
586 | | - dataSystemBuilder.fDv1FallbackSynchronizer(fdv1Fallback); |
| 580 | + PollingDataSourceBuilder fdv1Polling = Components.pollingDataSource(); |
| 581 | + if (fdv1Params.pollIntervalMs != null) { |
| 582 | + fdv1Polling.pollInterval(Duration.ofMillis(fdv1Params.pollIntervalMs)); |
| 583 | + } |
| 584 | + if (params.dataSystem.payloadFilter != null && !params.dataSystem.payloadFilter.isEmpty()) { |
| 585 | + fdv1Polling.payloadFilter(params.dataSystem.payloadFilter); |
| 586 | + } |
| 587 | + dataSystemBuilder.fDv1FallbackSynchronizer(fdv1Polling); |
587 | 588 | } |
588 | 589 |
|
589 | 590 | builder.dataSystem(dataSystemBuilder); |
@@ -625,47 +626,4 @@ private DataSourceBuilder<Synchronizer> createSynchronizer( |
625 | 626 | return null; |
626 | 627 | } |
627 | 628 |
|
628 | | - /** |
629 | | - * Selects the best synchronizer configuration to use for FDv1 fallback. |
630 | | - * Prefers the first polling synchronizer in the list, otherwise the first synchronizer. |
631 | | - */ |
632 | | - private static SdkConfigSynchronizerParams selectFallbackSynchronizer( |
633 | | - SdkConfigSynchronizerParams[] synchronizers) { |
634 | | - if (synchronizers == null || synchronizers.length == 0) { |
635 | | - return null; |
636 | | - } |
637 | | - // Prefer first polling synchronizer (FDv1 fallback is polling-based) |
638 | | - for (SdkConfigSynchronizerParams sync : synchronizers) { |
639 | | - if (sync.polling != null) { |
640 | | - return sync; |
641 | | - } |
642 | | - } |
643 | | - // Otherwise use first synchronizer (streaming; FDv1 will use default polling config) |
644 | | - return synchronizers[0]; |
645 | | - } |
646 | | - |
647 | | - /** |
648 | | - * Creates the FDv1 fallback synchronizer based on the selected synchronizer config. |
649 | | - * FDv1 fallback is always polling-based and uses the global service endpoints configuration. |
650 | | - */ |
651 | | - private static ComponentConfigurer<DataSource> createFDv1FallbackSynchronizer( |
652 | | - SdkConfigSynchronizerParams synchronizer) { |
653 | | - |
654 | | - // FDv1 fallback is always polling-based |
655 | | - PollingDataSourceBuilder fdv1Polling = Components.pollingDataSource(); |
656 | | - |
657 | | - // Configure polling interval if the synchronizer has polling configuration |
658 | | - if (synchronizer.polling != null) { |
659 | | - if (synchronizer.polling.pollIntervalMs != null) { |
660 | | - fdv1Polling.pollInterval(Duration.ofMillis(synchronizer.polling.pollIntervalMs)); |
661 | | - } |
662 | | - // Note: FDv1 polling doesn't support per-source service endpoints override, |
663 | | - // so it will use the global service endpoints configuration (which is set |
664 | | - // by the caller before this method is invoked) |
665 | | - } |
666 | | - // If streaming synchronizer, use default polling interval |
667 | | - // (no additional configuration needed) |
668 | | - |
669 | | - return fdv1Polling; |
670 | | - } |
671 | 629 | } |
0 commit comments