Skip to content

Commit 38f8e89

Browse files
author
Bernd Warmuth
committed
chore: spotless apply
Signed-off-by: Bernd Warmuth <[email protected]>
1 parent ab0db5b commit 38f8e89

16 files changed

+402
-399
lines changed

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

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package dev.openfeature.contrib.providers.flagd;
22

3+
import static dev.openfeature.contrib.providers.flagd.Config.fallBackToEnvOrDefault;
4+
import static dev.openfeature.contrib.providers.flagd.Config.fromValueProvider;
5+
36
import dev.openfeature.contrib.providers.flagd.resolver.process.storage.connector.Connector;
47
import dev.openfeature.sdk.EvaluationContext;
58
import dev.openfeature.sdk.ImmutableContext;
69
import dev.openfeature.sdk.Structure;
710
import io.opentelemetry.api.GlobalOpenTelemetry;
811
import io.opentelemetry.api.OpenTelemetry;
12+
import java.util.function.Function;
913
import lombok.Builder;
1014
import lombok.Getter;
1115

12-
import java.util.function.Function;
13-
14-
import static dev.openfeature.contrib.providers.flagd.Config.fallBackToEnvOrDefault;
15-
import static dev.openfeature.contrib.providers.flagd.Config.fromValueProvider;
16-
1716
/**
1817
* FlagdOptions is a builder to build flagd provider options.
1918
*/
@@ -66,15 +65,15 @@ public class FlagdOptions {
6665
* Max cache size.
6766
*/
6867
@Builder.Default
69-
private int maxCacheSize = fallBackToEnvOrDefault(Config.MAX_CACHE_SIZE_ENV_VAR_NAME,
70-
Config.DEFAULT_MAX_CACHE_SIZE);
68+
private int maxCacheSize =
69+
fallBackToEnvOrDefault(Config.MAX_CACHE_SIZE_ENV_VAR_NAME, Config.DEFAULT_MAX_CACHE_SIZE);
7170

7271
/**
7372
* Backoff interval in milliseconds.
7473
*/
7574
@Builder.Default
76-
private int retryBackoffMs = fallBackToEnvOrDefault(Config.BASE_EVENT_STREAM_RETRY_BACKOFF_MS_ENV_VAR_NAME,
77-
Config.BASE_EVENT_STREAM_RETRY_BACKOFF_MS);
75+
private int retryBackoffMs = fallBackToEnvOrDefault(
76+
Config.BASE_EVENT_STREAM_RETRY_BACKOFF_MS_ENV_VAR_NAME, Config.BASE_EVENT_STREAM_RETRY_BACKOFF_MS);
7877

7978
/**
8079
* Connection deadline in milliseconds.
@@ -91,16 +90,16 @@ public class FlagdOptions {
9190
* Defaults to 600000 (10 minutes); recommended to prevent infrastructure from killing idle connections.
9291
*/
9392
@Builder.Default
94-
private int streamDeadlineMs = fallBackToEnvOrDefault(Config.STREAM_DEADLINE_MS_ENV_VAR_NAME,
95-
Config.DEFAULT_STREAM_DEADLINE_MS);
93+
private int streamDeadlineMs =
94+
fallBackToEnvOrDefault(Config.STREAM_DEADLINE_MS_ENV_VAR_NAME, Config.DEFAULT_STREAM_DEADLINE_MS);
9695

9796
/**
9897
* Grace time period in milliseconds before provider moves from STALE to ERROR.
9998
* Defaults to 50_000
10099
*/
101100
@Builder.Default
102-
private int streamRetryGracePeriod = fallBackToEnvOrDefault(Config.STREAM_RETRY_GRACE_PERIOD,
103-
Config.DEFAULT_STREAM_RETRY_GRACE_PERIOD);
101+
private int streamRetryGracePeriod =
102+
fallBackToEnvOrDefault(Config.STREAM_RETRY_GRACE_PERIOD, Config.DEFAULT_STREAM_RETRY_GRACE_PERIOD);
104103
/**
105104
* Selector to be used with flag sync gRPC contract.
106105
**/
@@ -112,7 +111,8 @@ public class FlagdOptions {
112111
* Defaults to 0 (disabled).
113112
**/
114113
@Builder.Default
115-
private long keepAlive = fallBackToEnvOrDefault(Config.KEEP_ALIVE_MS_ENV_VAR_NAME,
114+
private long keepAlive = fallBackToEnvOrDefault(
115+
Config.KEEP_ALIVE_MS_ENV_VAR_NAME,
116116
fallBackToEnvOrDefault(Config.KEEP_ALIVE_MS_ENV_VAR_NAME_OLD, Config.DEFAULT_KEEP_ALIVE));
117117

118118
/**
@@ -122,7 +122,6 @@ public class FlagdOptions {
122122
@Builder.Default
123123
private String offlineFlagSourcePath = fallBackToEnvOrDefault(Config.OFFLINE_SOURCE_PATH, null);
124124

125-
126125
/**
127126
* gRPC custom target string.
128127
*
@@ -133,7 +132,6 @@ public class FlagdOptions {
133132
@Builder.Default
134133
private String targetUri = fallBackToEnvOrDefault(Config.TARGET_URI_ENV_VAR_NAME, null);
135134

136-
137135
/**
138136
* Function providing an EvaluationContext to mix into every evaluations.
139137
* The sync-metadata response
@@ -144,8 +142,8 @@ public class FlagdOptions {
144142
* By default, the entire sync response (converted to a Structure) is used.
145143
*/
146144
@Builder.Default
147-
private Function<Structure, EvaluationContext> contextEnricher = (syncMetadata) -> new ImmutableContext(
148-
syncMetadata.asMap());
145+
private Function<Structure, EvaluationContext> contextEnricher =
146+
(syncMetadata) -> new ImmutableContext(syncMetadata.asMap());
149147

150148
/**
151149
* Inject a Custom Connector for fetching flags.
@@ -196,8 +194,8 @@ void prebuild() {
196194
}
197195

198196
if (port == 0) {
199-
port = Integer
200-
.parseInt(fallBackToEnvOrDefault(Config.PORT_ENV_VAR_NAME, determineDefaultPortForResolver()));
197+
port = Integer.parseInt(
198+
fallBackToEnvOrDefault(Config.PORT_ENV_VAR_NAME, determineDefaultPortForResolver()));
201199
}
202200
}
203201

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

+11-13
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
import dev.openfeature.sdk.ProviderEventDetails;
1616
import dev.openfeature.sdk.Structure;
1717
import dev.openfeature.sdk.Value;
18-
import lombok.extern.slf4j.Slf4j;
19-
2018
import java.util.ArrayList;
2119
import java.util.Collections;
2220
import java.util.List;
2321
import java.util.function.Function;
22+
import lombok.extern.slf4j.Slf4j;
2423

2524
/**
2625
* OpenFeature provider for flagd.
@@ -56,13 +55,11 @@ public FlagdProvider() {
5655
public FlagdProvider(final FlagdOptions options) {
5756
switch (options.getResolverType().asString()) {
5857
case Config.RESOLVER_IN_PROCESS:
59-
this.flagResolver = new InProcessResolver(options, this::isConnected,
60-
this::onConnectionEvent);
58+
this.flagResolver = new InProcessResolver(options, this::isConnected, this::onConnectionEvent);
6159
break;
6260
case Config.RESOLVER_RPC:
63-
this.flagResolver = new GrpcResolver(options,
64-
new Cache(options.getCacheType(), options.getMaxCacheSize()),
65-
this::onConnectionEvent);
61+
this.flagResolver = new GrpcResolver(
62+
options, new Cache(options.getCacheType(), options.getMaxCacheSize()), this::onConnectionEvent);
6663
break;
6764
default:
6865
throw new IllegalStateException(
@@ -159,7 +156,7 @@ private boolean isConnected() {
159156
}
160157

161158
private void onConnectionEvent(ConnectionEvent connectionEvent) {
162-
final boolean wasConnected = connected;// WHY the F*** is this false? wasconnected is false ,hence no change
159+
final boolean wasConnected = connected; // WHY the F*** is this false? wasconnected is false ,hence no change
163160
// event will be sent. why is was connected false? not updated via event?
164161
final boolean isConnected = connected = connectionEvent.isConnected();
165162

@@ -189,12 +186,13 @@ private void onConnectionEvent(ConnectionEvent connectionEvent) {
189186
}
190187

191188
if (connectionEvent.isStale()) {
192-
this.emitProviderStale(ProviderEventDetails.builder().message("there has been an error").build());
189+
this.emitProviderStale(ProviderEventDetails.builder()
190+
.message("there has been an error")
191+
.build());
193192
} else {
194-
this.emitProviderError(ProviderEventDetails.builder().message("there has been an error").build());
193+
this.emitProviderError(ProviderEventDetails.builder()
194+
.message("there has been an error")
195+
.build());
195196
}
196197
}
197198
}
198-
199-
200-

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/common/ChannelMonitor.java

+40-34
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,20 @@
33
import dev.openfeature.sdk.exceptions.GeneralError;
44
import io.grpc.ConnectivityState;
55
import io.grpc.ManagedChannel;
6-
import lombok.extern.slf4j.Slf4j;
7-
86
import java.util.concurrent.CountDownLatch;
97
import java.util.concurrent.ScheduledExecutorService;
108
import java.util.concurrent.ScheduledFuture;
119
import java.util.concurrent.TimeUnit;
1210
import java.util.concurrent.atomic.AtomicReference;
13-
11+
import lombok.extern.slf4j.Slf4j;
1412

1513
/**
1614
* A utility class to monitor and manage the connectivity state of a gRPC ManagedChannel.
1715
*/
1816
@Slf4j
1917
public class ChannelMonitor {
2018

21-
22-
private ChannelMonitor() {
23-
24-
}
19+
private ChannelMonitor() {}
2520

2621
/**
2722
* Monitors the state of a gRPC channel and triggers the specified callbacks based on state changes.
@@ -31,8 +26,11 @@ private ChannelMonitor() {
3126
* @param onConnectionReady callback invoked when the channel transitions to a READY state.
3227
* @param onConnectionLost callback invoked when the channel transitions to a FAILURE or SHUTDOWN state.
3328
*/
34-
public static void monitorChannelState(ConnectivityState expectedState, ManagedChannel channel,
35-
Runnable onConnectionReady, Runnable onConnectionLost) {
29+
public static void monitorChannelState(
30+
ConnectivityState expectedState,
31+
ManagedChannel channel,
32+
Runnable onConnectionReady,
33+
Runnable onConnectionLost) {
3634
channel.notifyWhenStateChanged(expectedState, () -> {
3735
ConnectivityState currentState = channel.getState(true);
3836
log.info("Channel state changed to: {}", currentState);
@@ -47,7 +45,6 @@ public static void monitorChannelState(ConnectivityState expectedState, ManagedC
4745
});
4846
}
4947

50-
5148
/**
5249
* Waits for the channel to reach a desired state within a specified timeout period.
5350
*
@@ -58,21 +55,24 @@ public static void monitorChannelState(ConnectivityState expectedState, ManagedC
5855
* @param unit the time unit of the timeout.
5956
* @throws InterruptedException if the current thread is interrupted while waiting.
6057
*/
61-
public static void waitForDesiredState(ManagedChannel channel,
62-
ConnectivityState desiredState,
63-
Runnable connectCallback,
64-
long timeout,
65-
TimeUnit unit) throws InterruptedException {
58+
public static void waitForDesiredState(
59+
ManagedChannel channel,
60+
ConnectivityState desiredState,
61+
Runnable connectCallback,
62+
long timeout,
63+
TimeUnit unit)
64+
throws InterruptedException {
6665
waitForDesiredState(channel, desiredState, connectCallback, new CountDownLatch(1), timeout, unit);
6766
}
6867

69-
70-
private static void waitForDesiredState(ManagedChannel channel,
71-
ConnectivityState desiredState,
72-
Runnable connectCallback,
73-
CountDownLatch latch,
74-
long timeout,
75-
TimeUnit unit) throws InterruptedException {
68+
private static void waitForDesiredState(
69+
ManagedChannel channel,
70+
ConnectivityState desiredState,
71+
Runnable connectCallback,
72+
CountDownLatch latch,
73+
long timeout,
74+
TimeUnit unit)
75+
throws InterruptedException {
7676
channel.notifyWhenStateChanged(ConnectivityState.SHUTDOWN, () -> {
7777
try {
7878
ConnectivityState state = channel.getState(true);
@@ -94,12 +94,11 @@ private static void waitForDesiredState(ManagedChannel channel,
9494

9595
// Await the latch or timeout for the state change
9696
if (!latch.await(timeout, unit)) {
97-
throw new GeneralError(String.format("Deadline exceeded. Condition did not complete within the %d "
98-
+ "deadline", timeout));
97+
throw new GeneralError(String.format(
98+
"Deadline exceeded. Condition did not complete within the %d " + "deadline", timeout));
9999
}
100100
}
101101

102-
103102
/**
104103
* Polls the state of a gRPC channel at regular intervals and triggers callbacks upon state changes.
105104
*
@@ -109,9 +108,12 @@ private static void waitForDesiredState(ManagedChannel channel,
109108
* @param onConnectionLost callback invoked when the channel transitions to a FAILURE or SHUTDOWN state.
110109
* @param pollIntervalMs the polling interval in milliseconds.
111110
*/
112-
public static void pollChannelState(ScheduledExecutorService executor, ManagedChannel channel,
113-
Runnable onConnectionReady,
114-
Runnable onConnectionLost, long pollIntervalMs) {
111+
public static void pollChannelState(
112+
ScheduledExecutorService executor,
113+
ManagedChannel channel,
114+
Runnable onConnectionReady,
115+
Runnable onConnectionLost,
116+
long pollIntervalMs) {
115117

116118
AtomicReference<ConnectivityState> lastState = new AtomicReference<>(ConnectivityState.READY);
117119

@@ -132,7 +134,6 @@ public static void pollChannelState(ScheduledExecutorService executor, ManagedCh
132134
executor.scheduleAtFixedRate(pollTask, 0, pollIntervalMs, TimeUnit.MILLISECONDS);
133135
}
134136

135-
136137
/**
137138
* Polls the channel state at fixed intervals and waits for the channel to reach a desired state within a timeout
138139
* period.
@@ -146,9 +147,14 @@ public static void pollChannelState(ScheduledExecutorService executor, ManagedCh
146147
* @return {@code true} if the desired state was reached within the timeout period, {@code false} otherwise.
147148
* @throws InterruptedException if the current thread is interrupted while waiting.
148149
*/
149-
public static boolean pollForDesiredState(ScheduledExecutorService executor, ManagedChannel channel,
150-
ConnectivityState desiredState, Runnable connectCallback, long timeout,
151-
TimeUnit unit) throws InterruptedException {
150+
public static boolean pollForDesiredState(
151+
ScheduledExecutorService executor,
152+
ManagedChannel channel,
153+
ConnectivityState desiredState,
154+
Runnable connectCallback,
155+
long timeout,
156+
TimeUnit unit)
157+
throws InterruptedException {
152158
CountDownLatch latch = new CountDownLatch(1);
153159

154160
Runnable waitForStateTask = () -> {
@@ -159,8 +165,8 @@ public static boolean pollForDesiredState(ScheduledExecutorService executor, Man
159165
}
160166
};
161167

162-
ScheduledFuture<?> scheduledFuture = executor.scheduleWithFixedDelay(waitForStateTask, 0, 100,
163-
TimeUnit.MILLISECONDS);
168+
ScheduledFuture<?> scheduledFuture =
169+
executor.scheduleWithFixedDelay(waitForStateTask, 0, 100, TimeUnit.MILLISECONDS);
164170

165171
boolean success = latch.await(timeout, unit);
166172
scheduledFuture.cancel(true);

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/common/ConnectionEvent.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import dev.openfeature.sdk.ImmutableStructure;
44
import dev.openfeature.sdk.Structure;
5-
65
import java.util.Collections;
76
import java.util.List;
87

@@ -35,7 +34,9 @@ public class ConnectionEvent {
3534
* @param connected {@code true} if the connection is established, otherwise {@code false}.
3635
*/
3736
public ConnectionEvent(boolean connected) {
38-
this(connected ? ConnectionState.CONNECTED : ConnectionState.DISCONNECTED, Collections.emptyList(),
37+
this(
38+
connected ? ConnectionState.CONNECTED : ConnectionState.DISCONNECTED,
39+
Collections.emptyList(),
3940
new ImmutableStructure());
4041
}
4142

@@ -78,9 +79,10 @@ public ConnectionEvent(ConnectionState connected, Structure syncMetadata) {
7879
*/
7980
public ConnectionEvent(ConnectionState connectionState, List<String> flagsChanged, Structure syncMetadata) {
8081
this.connected = connectionState;
81-
this.flagsChanged = flagsChanged != null ? flagsChanged : Collections.emptyList(); // Ensure non-null list
82-
this.syncMetadata = syncMetadata != null ? new ImmutableStructure(syncMetadata.asMap()) :
83-
new ImmutableStructure(); // Ensure valid syncMetadata
82+
this.flagsChanged = flagsChanged != null ? flagsChanged : Collections.emptyList(); // Ensure non-null list
83+
this.syncMetadata = syncMetadata != null
84+
? new ImmutableStructure(syncMetadata.asMap())
85+
: new ImmutableStructure(); // Ensure valid syncMetadata
8486
}
8587

8688
/**

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/common/ConnectionState.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ public enum ConnectionState {
2424
* The connection has encountered an error and cannot function correctly.
2525
*/
2626
ERROR,
27-
}
27+
}

0 commit comments

Comments
 (0)