Skip to content

Commit 3008deb

Browse files
committed
fixup: some cleanup
Signed-off-by: Todd Baert <[email protected]>
1 parent 9519a9e commit 3008deb

File tree

12 files changed

+94
-85
lines changed

12 files changed

+94
-85
lines changed

providers/flagd/lombok.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file is needed to avoid errors throw by findbugs when working with lombok.
2+
lombok.addSuppressWarnings = true
3+
lombok.addLombokGeneratedAnnotation = true
4+
config.stopBubbling = true
5+
lombok.extern.findbugs.addSuppressFBWarnings = true

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/FlagdProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import dev.openfeature.contrib.providers.flagd.resolver.grpc.GrpcResolver;
55
import dev.openfeature.contrib.providers.flagd.resolver.grpc.cache.Cache;
66
import dev.openfeature.contrib.providers.flagd.resolver.process.InProcessResolver;
7-
import dev.openfeature.contrib.providers.flagd.resolver.process.model.FeatureFlag;
87
import dev.openfeature.sdk.EvaluationContext;
98
import dev.openfeature.sdk.EventProvider;
109
import dev.openfeature.sdk.FeatureProvider;

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/grpc/GrpcConnector.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public class GrpcConnector {
5353
* @param cache cache to use.
5454
* @param stateConsumer lambda to call for setting the state.
5555
*/
56-
public GrpcConnector(final FlagdOptions options, final Cache cache, BiConsumer<ProviderState, List<String>> stateConsumer) {
56+
public GrpcConnector(final FlagdOptions options, final Cache cache,
57+
BiConsumer<ProviderState, List<String>> stateConsumer) {
5758
this.channel = ChannelBuilder.nettyChannel(options);
5859
this.serviceStub = ServiceGrpc.newStub(channel);
5960
this.serviceBlockingStub = ServiceGrpc.newBlockingStub(channel);
@@ -81,7 +82,8 @@ public void initialize() throws Exception {
8182
/**
8283
* Shuts down all gRPC resources.
8384
*
84-
* @throws Exception is something goes wrong while terminating the communication.
85+
* @throws Exception is something goes wrong while terminating the
86+
* communication.
8587
*/
8688
public void shutdown() throws Exception {
8789
// first shutdown the event listener
@@ -115,21 +117,24 @@ public ServiceGrpc.ServiceBlockingStub getResolver() {
115117
}
116118

117119
/**
118-
* Event stream observer logic. This contains blocking mechanisms, hence must be run in a dedicated thread.
120+
* Event stream observer logic. This contains blocking mechanisms, hence must be
121+
* run in a dedicated thread.
119122
*/
120123
private void observeEventStream() {
121124
while (this.eventStreamAttempt <= this.maxEventStreamRetries) {
122-
final StreamObserver<EventStreamResponse> responseObserver =
123-
new EventStreamObserver(sync, this.cache, this::grpcStateConsumer);
125+
final StreamObserver<EventStreamResponse> responseObserver = new EventStreamObserver(sync, this.cache,
126+
this::grpcStateConsumer);
124127
this.serviceStub.eventStream(EventStreamRequest.getDefaultInstance(), responseObserver);
125128

126129
try {
127130
synchronized (sync) {
128131
sync.wait();
129132
}
130133
} catch (InterruptedException e) {
131-
// Interruptions are considered end calls for this observer, hence log and return
132-
// Note - this is the most common interruption when shutdown, hence the log level debug
134+
// Interruptions are considered end calls for this observer, hence log and
135+
// return
136+
// Note - this is the most common interruption when shutdown, hence the log
137+
// level debug
133138
log.debug("interruption while waiting for condition", e);
134139
Thread.currentThread().interrupt();
135140
}
@@ -141,7 +146,8 @@ private void observeEventStream() {
141146
try {
142147
Thread.sleep(this.eventStreamRetryBackoff);
143148
} catch (InterruptedException e) {
144-
// Interruptions are considered end calls for this observer, hence log and return
149+
// Interruptions are considered end calls for this observer, hence log and
150+
// return
145151
log.warn("interrupted while restarting gRPC Event Stream");
146152
Thread.currentThread().interrupt();
147153
}

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/grpc/GrpcResolver.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.List;
77
import java.util.Map;
88
import java.util.function.BiConsumer;
9-
import java.util.function.Consumer;
109
import java.util.function.Function;
1110
import java.util.function.Supplier;
1211
import java.util.stream.Collectors;

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/InProcessResolver.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import dev.openfeature.contrib.providers.flagd.resolver.process.model.FeatureFlag;
77
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.FlagStore;
88
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.Storage;
9-
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.StorageStateDTO;
9+
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.StorageStateChange;
1010
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.connector.Connector;
1111
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.connector.file.FileConnector;
1212
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.connector.grpc.GrpcStreamConnector;
@@ -26,8 +26,6 @@
2626
import java.util.List;
2727
import java.util.concurrent.atomic.AtomicBoolean;
2828
import java.util.function.BiConsumer;
29-
import java.util.stream.Collectors;
30-
3129

3230
import static dev.openfeature.contrib.providers.flagd.resolver.process.model.FeatureFlag.EMPTY_TARGETING_STRING;
3331

@@ -53,8 +51,8 @@ public InProcessResolver(FlagdOptions options, BiConsumer<ProviderState, List<St
5351
this.deadline = options.getDeadline();
5452
this.stateConsumer = stateConsumer;
5553
this.operator = new Operator();
56-
this.metadata = options.getSelector() == null ? null :
57-
ImmutableMetadata.builder()
54+
this.metadata = options.getSelector() == null ? null
55+
: ImmutableMetadata.builder()
5856
.addString("scope", options.getSelector())
5957
.build();
6058
}
@@ -67,20 +65,21 @@ public void init() throws Exception {
6765
final Thread stateWatcher = new Thread(() -> {
6866
try {
6967
while (true) {
70-
final StorageStateDTO storageStateDTO = flagStore.getStateQueue().take();
68+
final StorageStateChange storageStateDTO = flagStore.getStateQueue().take();
7169
switch (storageStateDTO.getStorageState()) {
7270
case OK:
7371
stateConsumer.accept(ProviderState.READY, storageStateDTO.getChangedFlagsKeys());
7472
this.connected.set(true);
7573
break;
7674
case ERROR:
77-
stateConsumer.accept(ProviderState.ERROR,null);
75+
stateConsumer.accept(ProviderState.ERROR, null);
7876
this.connected.set(false);
7977
break;
8078
case STALE:
8179
// todo set stale state
8280
default:
83-
log.info(String.format("Storage emitted unhandled status: %s", storageStateDTO.getStorageState()));
81+
log.info(String.format("Storage emitted unhandled status: %s",
82+
storageStateDTO.getStorageState()));
8483
}
8584
}
8685
} catch (InterruptedException e) {
@@ -103,14 +102,14 @@ public void init() throws Exception {
103102
public void shutdown() throws InterruptedException {
104103
flagStore.shutdown();
105104
this.connected.set(false);
106-
stateConsumer.accept(ProviderState.NOT_READY,null);
105+
stateConsumer.accept(ProviderState.NOT_READY, null);
107106
}
108107

109108
/**
110109
* Resolve a boolean flag.
111110
*/
112111
public ProviderEvaluation<Boolean> booleanEvaluation(String key, Boolean defaultValue,
113-
EvaluationContext ctx) {
112+
EvaluationContext ctx) {
114113
return resolve(Boolean.class, key, ctx);
115114
}
116115

@@ -221,7 +220,7 @@ private <T> ProviderEvaluation<T> resolve(Class<T> type, String key, EvaluationC
221220
.variant(resolvedVariant)
222221
.reason(reason);
223222

224-
return this.metadata == null ? evaluationBuilder.build() :
225-
evaluationBuilder.flagMetadata(this.metadata).build();
223+
return this.metadata == null ? evaluationBuilder.build()
224+
: evaluationBuilder.flagMetadata(this.metadata).build();
226225
}
227226
}

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/storage/FlagStore.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
* Feature flag storage.
2222
*/
2323
@Slf4j
24-
@SuppressFBWarnings(value = {"EI_EXPOSE_REP"},
25-
justification = "Feature flag comes as a Json configuration, hence they must be exposed")
24+
@SuppressFBWarnings(value = {
25+
"EI_EXPOSE_REP" }, justification = "Feature flag comes as a Json configuration, hence they must be exposed")
2626
public class FlagStore implements Storage {
2727
private final ReentrantReadWriteLock sync = new ReentrantReadWriteLock();
2828
private final ReadLock readLock = sync.readLock();
2929
private final WriteLock writeLock = sync.writeLock();
3030

3131
private final AtomicBoolean shutdown = new AtomicBoolean(false);
32-
private final BlockingQueue<StorageStateDTO> stateBlockingQueue = new LinkedBlockingQueue<>(1);
32+
private final BlockingQueue<StorageStateChange> stateBlockingQueue = new LinkedBlockingQueue<>(1);
3333
private final Map<String, FeatureFlag> flags = new HashMap<>();
3434

3535
private final Connector connector;
@@ -89,7 +89,7 @@ public FeatureFlag getFlag(final String key) {
8989
/**
9090
* Retrieve blocking queue to check storage status.
9191
*/
92-
public BlockingQueue<StorageStateDTO> getStateQueue() {
92+
public BlockingQueue<StorageStateChange> getStateQueue() {
9393
return stateBlockingQueue;
9494
}
9595

@@ -111,19 +111,19 @@ private void streamerListener(final Connector connector) throws InterruptedExcep
111111
} finally {
112112
writeLock.unlock();
113113
}
114-
if (!stateBlockingQueue.offer(new StorageStateDTO(StorageState.OK, changedFlagsKeys))) {
114+
if (!stateBlockingQueue.offer(new StorageStateChange(StorageState.OK, changedFlagsKeys))) {
115115
log.warn("Failed to convey OK satus, queue is full");
116116
}
117117
} catch (Throwable e) {
118118
// catch all exceptions and avoid stream listener interruptions
119119
log.warn("Invalid flag sync payload from connector", e);
120-
if (!stateBlockingQueue.offer(new StorageStateDTO(StorageState.STALE))) {
120+
if (!stateBlockingQueue.offer(new StorageStateChange(StorageState.STALE))) {
121121
log.warn("Failed to convey STALE satus, queue is full");
122122
}
123123
}
124124
break;
125125
case ERROR:
126-
if (!stateBlockingQueue.offer(new StorageStateDTO(StorageState.ERROR))) {
126+
if (!stateBlockingQueue.offer(new StorageStateChange(StorageState.ERROR))) {
127127
log.warn("Failed to convey ERROR satus, queue is full");
128128
}
129129
break;
@@ -147,8 +147,8 @@ private List<String> getChangedFlagsKeys(Map<String, FeatureFlag> newFlags) {
147147
updatedFeatureFlags.put(key, value);
148148
}
149149
});
150-
flags.forEach((key,value) -> {
151-
if(!newFlags.containsKey(key)) {
150+
flags.forEach((key, value) -> {
151+
if (!newFlags.containsKey(key)) {
152152
removedFeatureFlags.put(key, value);
153153
}
154154
});

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/storage/Storage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ public interface Storage {
1414

1515
FeatureFlag getFlag(final String key);
1616

17-
BlockingQueue<StorageStateDTO> getStateQueue();
17+
BlockingQueue<StorageStateChange> getStateQueue();
1818
}
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
package dev.openfeature.contrib.providers.flagd.resolver.process.storage;
22

3-
43
import lombok.EqualsAndHashCode;
54
import lombok.Getter;
65
import lombok.ToString;
76

7+
import java.util.ArrayList;
88
import java.util.Collections;
99
import java.util.List;
1010

11+
/**
12+
* Represents a change in the stored flags.
13+
*/
1114
@Getter
1215
@ToString
1316
@EqualsAndHashCode
14-
public class StorageStateDTO {
17+
public class StorageStateChange {
1518
private final StorageState storageState;
1619
private final List<String> changedFlagsKeys;
1720

18-
public StorageStateDTO(StorageState storageState, List<String> changedFlagsKeys) {
21+
public StorageStateChange(StorageState storageState, List<String> changedFlagsKeys) {
1922
this.storageState = storageState;
20-
this.changedFlagsKeys = changedFlagsKeys;
23+
this.changedFlagsKeys = new ArrayList<>(changedFlagsKeys);
2124
}
2225

23-
public StorageStateDTO(StorageState storageState) {
26+
public StorageStateChange(StorageState storageState) {
2427
this.storageState = storageState;
2528
this.changedFlagsKeys = Collections.emptyList();
2629
}

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/FlagdProviderTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
import java.lang.reflect.Field;
1919
import java.util.ArrayList;
2020
import java.util.Arrays;
21-
import java.util.Collections;
2221
import java.util.HashMap;
2322
import java.util.List;
2423
import java.util.Map;
2524
import java.util.concurrent.TimeUnit;
2625
import java.util.function.Supplier;
2726
import java.util.concurrent.LinkedBlockingQueue;
2827

29-
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.StorageStateDTO;
28+
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.StorageStateChange;
3029
import org.junit.jupiter.api.BeforeAll;
3130
import org.junit.jupiter.api.Test;
3231
import org.mockito.MockedStatic;
@@ -919,8 +918,8 @@ private FlagdProvider createInProcessProvider() {
919918
.build();
920919
final FlagdProvider provider = new FlagdProvider(flagdOptions);
921920
final MockStorage mockStorage = new MockStorage(new HashMap<String, FeatureFlag>(),
922-
new LinkedBlockingQueue<StorageStateDTO>(Arrays.asList(new
923-
StorageStateDTO(StorageState.OK))));
921+
new LinkedBlockingQueue<StorageStateChange>(Arrays.asList(new
922+
StorageStateChange(StorageState.OK))));
924923

925924
try {
926925
final Field flagResolver = FlagdProvider.class.getDeclaredField("flagResolver");

0 commit comments

Comments
 (0)