@@ -18,7 +18,7 @@ public class ConfigurationRequestor {
18
18
private final boolean supportBandits ;
19
19
20
20
private CompletableFuture <Void > remoteFetchFuture = null ;
21
- private CompletableFuture <Void > configurationFuture = null ;
21
+ private CompletableFuture <Boolean > configurationFuture = null ;
22
22
private boolean initialConfigSet = false ;
23
23
24
24
public ConfigurationRequestor (
@@ -42,38 +42,43 @@ public void setInitialConfiguration(@NotNull Configuration configuration) {
42
42
configurationStore .saveConfiguration (configuration ).thenApply (v -> true ).join ();
43
43
}
44
44
45
- // Asynchronously sets the initial configuration.
46
- public CompletableFuture <Void > setInitialConfiguration (
45
+ /**
46
+ * Asynchronously sets the initial configuration. Resolves to `true` if the initial configuration
47
+ * was used, false if not (due to being empty, a fetched config taking precedence, etc.)
48
+ */
49
+ public CompletableFuture <Boolean > setInitialConfiguration (
47
50
@ NotNull CompletableFuture <Configuration > configurationFuture ) {
48
51
if (initialConfigSet || this .configurationFuture != null ) {
49
52
throw new IllegalStateException ("Configuration future has already been set" );
50
53
}
51
54
this .configurationFuture =
52
55
configurationFuture
53
- .thenAccept (
56
+ .thenApply (
54
57
(config ) -> {
55
58
synchronized (configurationStore ) {
56
59
if (config == null || config .isEmpty ()) {
57
60
log .debug ("Initial configuration future returned empty/null" );
61
+ return false ;
58
62
} else if (remoteFetchFuture != null
59
63
&& remoteFetchFuture .isDone ()
60
64
&& !remoteFetchFuture .isCompletedExceptionally ()) {
61
65
// Don't clobber a successful fetch.
62
66
log .debug ("Fetch has completed; ignoring initial config load." );
67
+ return false ;
63
68
} else {
64
- log .debug ("saving initial configuration" );
65
69
initialConfigSet =
66
70
configurationStore
67
71
.saveConfiguration (config )
68
72
.thenApply ((s ) -> true )
69
73
.join ();
74
+ return true ;
70
75
}
71
76
}
72
77
})
73
78
.exceptionally (
74
79
(e ) -> {
75
80
log .error ("Error setting initial config" , e );
76
- return null ;
81
+ return false ;
77
82
});
78
83
return this .configurationFuture ;
79
84
}
0 commit comments