Skip to content

Commit 382246d

Browse files
committed
PR Feedback.
1 parent 10cab33 commit 382246d

3 files changed

Lines changed: 21 additions & 24 deletions

File tree

lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/FDv2DataSource.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class FDv2DataSource implements DataSource {
2525
/**
2626
* Default fallback timeout of 2 minutes. The timeout is only configurable for testing.
2727
*/
28-
private static final int defaultFallbackTimeout = 2 * 60;
28+
private static final int defaultFallbackTimeoutSeconds = 2 * 60;
2929

3030
/**
3131
* Default recovery timeout of 5 minutes. The timeout is only configurable for testing.
@@ -64,7 +64,7 @@ public FDv2DataSource(
6464
threadPriority,
6565
logger,
6666
sharedExecutor,
67-
defaultFallbackTimeout,
67+
defaultFallbackTimeoutSeconds,
6868
defaultRecoveryTimeout
6969
);
7070
}
@@ -217,6 +217,10 @@ private boolean runSynchronizers() {
217217
break;
218218
}
219219

220+
if(!(res instanceof FDv2SourceResult)) {
221+
logger.error("Unexpected result type from synchronizer: {}", res.getClass().getName());
222+
continue;
223+
}
220224

221225
FDv2SourceResult result = (FDv2SourceResult) res;
222226
conditions.inform(result);

lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/FDv2DataSourceConditions.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ public FallbackCondition(ScheduledExecutorService sharedExecutor, long timeoutSe
120120

121121
@Override
122122
public void inform(FDv2SourceResult sourceResult) {
123-
if (sourceResult == null) {
124-
return;
125-
}
126123
if (sourceResult.getResultType() == FDv2SourceResult.ResultType.CHANGE_SET) {
127124
if (timerFuture != null) {
128125
timerFuture.cancel(false);

lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/SynchronizerStateManager.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,24 @@ public SynchronizerFactoryWithState getNextAvailableSynchronizer() {
5252
synchronized (activeSourceLock) {
5353
SynchronizerFactoryWithState factory = null;
5454

55-
// There is at least one available factory.
56-
if(synchronizers.stream().anyMatch(s -> s.getState() == SynchronizerFactoryWithState.State.Available)) {
55+
int visited = 0;
56+
while(visited < synchronizers.size()) {
5757
// Look for the next synchronizer starting at the position after the current one. (avoiding just re-using the same synchronizer.)
58-
while(factory == null) {
59-
sourceIndex++;
60-
// We aren't using module here because we want to keep the stored index within range instead
61-
// of increasing indefinitely.
62-
if(sourceIndex >= synchronizers.size()) {
63-
sourceIndex = 0;
64-
}
65-
SynchronizerFactoryWithState candidate = synchronizers.get(sourceIndex);
66-
if (candidate.getState() == SynchronizerFactoryWithState.State.Available) {
67-
factory = candidate;
68-
}
58+
sourceIndex++;
6959

60+
// We aren't using module here because we want to keep the stored index within range instead
61+
// of increasing indefinitely.
62+
if(sourceIndex >= synchronizers.size()) {
63+
sourceIndex = 0;
7064
}
71-
}
7265

66+
SynchronizerFactoryWithState candidate = synchronizers.get(sourceIndex);
67+
if (candidate.getState() == SynchronizerFactoryWithState.State.Available) {
68+
factory = candidate;
69+
break;
70+
}
71+
visited++;
72+
}
7373
return factory;
7474
}
7575
}
@@ -80,15 +80,11 @@ public SynchronizerFactoryWithState getNextAvailableSynchronizer() {
8080
*/
8181
public boolean isPrimeSynchronizer() {
8282
synchronized (activeSourceLock) {
83-
boolean firstAvailableSynchronizer = true;
8483
for (int index = 0; index < synchronizers.size(); index++) {
8584
if (synchronizers.get(index).getState() == SynchronizerFactoryWithState.State.Available) {
86-
if (firstAvailableSynchronizer && sourceIndex == index) {
87-
// This is the first synchronizer that is available, and it also is the current one.
85+
if (sourceIndex == index) {
8886
return true;
8987
}
90-
// Subsequently encountered synchronizers that are available are not the first one.
91-
firstAvailableSynchronizer = false;
9288
}
9389
}
9490
}

0 commit comments

Comments
 (0)