|
5 | 5 | import com.launchdarkly.sdk.server.datasources.Initializer; |
6 | 6 | import com.launchdarkly.sdk.server.integrations.FileDataSourceBuilder.SourceInfo; |
7 | 7 |
|
| 8 | +import java.io.IOException; |
8 | 9 | import java.util.List; |
9 | 10 | import java.util.concurrent.CompletableFuture; |
10 | 11 |
|
|
14 | 15 | * This implements the {@link Initializer} interface, loading files once and returning |
15 | 16 | * the result. If loading fails, it returns a terminal error since an initializer |
16 | 17 | * cannot retry. |
| 18 | + * <p> |
| 19 | + * Internally delegates to {@link FileSynchronizer} with auto-update disabled. |
17 | 20 | */ |
18 | | -final class FileInitializer extends FileDataSourceBase implements Initializer { |
19 | | - private final CompletableFuture<FDv2SourceResult> shutdownFuture = new CompletableFuture<>(); |
| 21 | +final class FileInitializer implements Initializer { |
| 22 | + private final FileSynchronizer synchronizer; |
20 | 23 |
|
21 | 24 | FileInitializer( |
22 | 25 | List<SourceInfo> sources, |
23 | 26 | FileData.DuplicateKeysHandling duplicateKeysHandling, |
24 | 27 | LDLogger logger, |
25 | 28 | boolean persist |
26 | 29 | ) { |
27 | | - super(sources, duplicateKeysHandling, logger, persist); |
| 30 | + // Use FileSynchronizer with autoUpdate=false for the actual file loading |
| 31 | + this.synchronizer = new FileSynchronizer(sources, false, duplicateKeysHandling, logger, persist); |
28 | 32 | } |
29 | 33 |
|
30 | 34 | @Override |
31 | 35 | public CompletableFuture<FDv2SourceResult> run() { |
32 | | - CompletableFuture<FDv2SourceResult> loadResult = CompletableFuture.supplyAsync(() -> loadData(true)); |
33 | | - return CompletableFuture.anyOf(shutdownFuture, loadResult) |
34 | | - .thenApply(result -> (FDv2SourceResult) result); |
| 36 | + return synchronizer.next().thenApply(result -> { |
| 37 | + // Convert INTERRUPTED to TERMINAL_ERROR for initializer semantics |
| 38 | + // (initializers can't retry, so all errors are terminal) |
| 39 | + if (result.getResultType() == FDv2SourceResult.ResultType.STATUS && |
| 40 | + result.getStatus().getState() == FDv2SourceResult.State.INTERRUPTED) { |
| 41 | + return FDv2SourceResult.terminalError( |
| 42 | + result.getStatus().getErrorInfo(), |
| 43 | + result.isFdv1Fallback() |
| 44 | + ); |
| 45 | + } |
| 46 | + return result; |
| 47 | + }); |
35 | 48 | } |
36 | 49 |
|
37 | 50 | @Override |
38 | | - public void close() { |
39 | | - shutdownFuture.complete(FDv2SourceResult.shutdown()); |
| 51 | + public void close() throws IOException { |
| 52 | + synchronizer.close(); |
40 | 53 | } |
41 | 54 | } |
0 commit comments