Skip to content

Commit

Permalink
fixup: update
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Schrottner <[email protected]>
  • Loading branch information
aepfli committed Oct 7, 2024
1 parent b3aba9f commit 891b5ae
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 71 deletions.
1 change: 1 addition & 0 deletions src/main/java/dev/openfeature/sdk/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public interface Client extends Features, EventBus<Client> {

/**
* Returns the current state of the associated provider.
*
* @return the provider state
*/
ProviderState getProviderState();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package dev.openfeature.sdk;

import dev.openfeature.sdk.exceptions.OpenFeatureError;
import lombok.Getter;

import java.util.concurrent.atomic.AtomicBoolean;
import lombok.Getter;

class FeatureProviderStateManager implements EventProviderListener {
private final FeatureProvider delegate;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfeature/sdk/FlagValueType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

@SuppressWarnings("checkstyle:MissingJavadocType")
public enum FlagValueType {
STRING, INTEGER, DOUBLE, OBJECT, BOOLEAN;
STRING, INTEGER, DOUBLE, OBJECT, BOOLEAN
}
2 changes: 1 addition & 1 deletion src/main/java/dev/openfeature/sdk/NoOpProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double default

@Override
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue,
EvaluationContext invocationContext) {
EvaluationContext invocationContext) {
return ProviderEvaluation.<Value>builder()
.value(defaultValue)
.variant(PASSED_IN_DEFAULT)
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/dev/openfeature/sdk/OpenFeatureAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import dev.openfeature.sdk.exceptions.OpenFeatureError;
import dev.openfeature.sdk.internal.AutoCloseableLock;
import dev.openfeature.sdk.internal.AutoCloseableReentrantReadWriteLock;
import lombok.extern.slf4j.Slf4j;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import lombok.extern.slf4j.Slf4j;

/**
* A global singleton which holds base configuration for the OpenFeature
Expand Down
43 changes: 25 additions & 18 deletions src/main/java/dev/openfeature/sdk/OpenFeatureClient.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package dev.openfeature.sdk;

import dev.openfeature.sdk.exceptions.*;
import dev.openfeature.sdk.exceptions.ExceptionUtils;
import dev.openfeature.sdk.exceptions.FatalError;
import dev.openfeature.sdk.exceptions.GeneralError;
import dev.openfeature.sdk.exceptions.OpenFeatureError;
import dev.openfeature.sdk.exceptions.ProviderNotReadyError;
import dev.openfeature.sdk.internal.AutoCloseableLock;
import dev.openfeature.sdk.internal.AutoCloseableReentrantReadWriteLock;
import dev.openfeature.sdk.internal.ObjectUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.*;
import java.util.function.Consumer;

/**
* OpenFeature Client implementation.
* You should not instantiate this or reference this class.
Expand Down Expand Up @@ -42,8 +49,8 @@ public class OpenFeatureClient implements Client {
* @param domain An identifier which logically binds clients with providers (used by observability tools).
* @param version Version of the client (used by observability tools).
* @deprecated Do not use this constructor. It's for internal use only.
* Clients created using it will not run event handlers.
* Use the OpenFeatureAPI's getClient factory method instead.
* Clients created using it will not run event handlers.
* Use the OpenFeatureAPI's getClient factory method instead.
*/
@Deprecated() // TODO: eventually we will make this non-public. See issue #872
public OpenFeatureClient(
Expand Down Expand Up @@ -106,7 +113,7 @@ public EvaluationContext getEvaluationContext() {
}

private <T> FlagEvaluationDetails<T> evaluateFlag(FlagValueType type, String key, T defaultValue,
EvaluationContext ctx, FlagEvaluationOptions options) {
EvaluationContext ctx, FlagEvaluationOptions options) {
FlagEvaluationOptions flagOptions = ObjectUtils.defaultIfNull(options,
() -> FlagEvaluationOptions.builder().build());
Map<String, Object> hints = Collections.unmodifiableMap(flagOptions.getHookHints());
Expand Down Expand Up @@ -230,7 +237,7 @@ public Boolean getBooleanValue(String key, Boolean defaultValue, EvaluationConte

@Override
public Boolean getBooleanValue(String key, Boolean defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
FlagEvaluationOptions options) {
return getBooleanDetails(key, defaultValue, ctx, options).getValue();
}

Expand All @@ -246,7 +253,7 @@ public FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defa

@Override
public FlagEvaluationDetails<Boolean> getBooleanDetails(String key, Boolean defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
FlagEvaluationOptions options) {
return this.evaluateFlag(FlagValueType.BOOLEAN, key, defaultValue, ctx, options);
}

Expand All @@ -262,7 +269,7 @@ public String getStringValue(String key, String defaultValue, EvaluationContext

@Override
public String getStringValue(String key, String defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
FlagEvaluationOptions options) {
return getStringDetails(key, defaultValue, ctx, options).getValue();
}

Expand All @@ -278,7 +285,7 @@ public FlagEvaluationDetails<String> getStringDetails(String key, String default

@Override
public FlagEvaluationDetails<String> getStringDetails(String key, String defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
FlagEvaluationOptions options) {
return this.evaluateFlag(FlagValueType.STRING, key, defaultValue, ctx, options);
}

Expand All @@ -294,7 +301,7 @@ public Integer getIntegerValue(String key, Integer defaultValue, EvaluationConte

@Override
public Integer getIntegerValue(String key, Integer defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
FlagEvaluationOptions options) {
return getIntegerDetails(key, defaultValue, ctx, options).getValue();
}

Expand All @@ -310,7 +317,7 @@ public FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defa

@Override
public FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
FlagEvaluationOptions options) {
return this.evaluateFlag(FlagValueType.INTEGER, key, defaultValue, ctx, options);
}

Expand All @@ -326,7 +333,7 @@ public Double getDoubleValue(String key, Double defaultValue, EvaluationContext

@Override
public Double getDoubleValue(String key, Double defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
FlagEvaluationOptions options) {
return this.evaluateFlag(FlagValueType.DOUBLE, key, defaultValue, ctx, options).getValue();
}

Expand All @@ -342,7 +349,7 @@ public FlagEvaluationDetails<Double> getDoubleDetails(String key, Double default

@Override
public FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
FlagEvaluationOptions options) {
return this.evaluateFlag(FlagValueType.DOUBLE, key, defaultValue, ctx, options);
}

Expand All @@ -358,7 +365,7 @@ public Value getObjectValue(String key, Value defaultValue, EvaluationContext ct

@Override
public Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
FlagEvaluationOptions options) {
return getObjectDetails(key, defaultValue, ctx, options).getValue();
}

Expand All @@ -369,13 +376,13 @@ public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultVa

@Override
public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue,
EvaluationContext ctx) {
EvaluationContext ctx) {
return getObjectDetails(key, defaultValue, ctx, FlagEvaluationOptions.builder().build());
}

@Override
public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
FlagEvaluationOptions options) {
return this.evaluateFlag(FlagValueType.OBJECT, key, defaultValue, ctx, options);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfeature/sdk/ProviderEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* Provider event types.
*/
public enum ProviderEvent {
PROVIDER_READY, PROVIDER_CONFIGURATION_CHANGED, PROVIDER_ERROR, PROVIDER_STALE;
PROVIDER_READY, PROVIDER_CONFIGURATION_CHANGED, PROVIDER_ERROR, PROVIDER_STALE
}
45 changes: 22 additions & 23 deletions src/main/java/dev/openfeature/sdk/ProviderRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import dev.openfeature.sdk.exceptions.GeneralError;
import dev.openfeature.sdk.exceptions.OpenFeatureError;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -16,6 +14,7 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;

@Slf4j
class ProviderRepository {
Expand Down Expand Up @@ -111,11 +110,11 @@ public boolean isDefaultProvider(FeatureProvider provider) {
* Set the default provider.
*/
public void setProvider(FeatureProvider provider,
Consumer<FeatureProvider> afterSet,
Consumer<FeatureProvider> afterInit,
Consumer<FeatureProvider> afterShutdown,
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
boolean waitForInit) {
Consumer<FeatureProvider> afterSet,
Consumer<FeatureProvider> afterInit,
Consumer<FeatureProvider> afterShutdown,
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
boolean waitForInit) {
if (provider == null) {
throw new IllegalArgumentException("Provider cannot be null");
}
Expand All @@ -131,12 +130,12 @@ public void setProvider(FeatureProvider provider,
* Otherwise, initialization happens in the background.
*/
public void setProvider(String domain,
FeatureProvider provider,
Consumer<FeatureProvider> afterSet,
Consumer<FeatureProvider> afterInit,
Consumer<FeatureProvider> afterShutdown,
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
boolean waitForInit) {
FeatureProvider provider,
Consumer<FeatureProvider> afterSet,
Consumer<FeatureProvider> afterInit,
Consumer<FeatureProvider> afterShutdown,
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
boolean waitForInit) {
if (provider == null) {
throw new IllegalArgumentException("Provider cannot be null");
}
Expand All @@ -147,12 +146,12 @@ public void setProvider(String domain,
}

private void prepareAndInitializeProvider(String domain,
FeatureProvider newProvider,
Consumer<FeatureProvider> afterSet,
Consumer<FeatureProvider> afterInit,
Consumer<FeatureProvider> afterShutdown,
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
boolean waitForInit) {
FeatureProvider newProvider,
Consumer<FeatureProvider> afterSet,
Consumer<FeatureProvider> afterInit,
Consumer<FeatureProvider> afterShutdown,
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
boolean waitForInit) {
final FeatureProviderStateManager newStateManager;
final FeatureProviderStateManager oldStateManager;

Expand Down Expand Up @@ -196,10 +195,10 @@ private FeatureProviderStateManager getExistingStateManagerForProvider(FeaturePr
}

private void initializeProvider(FeatureProviderStateManager newManager,
Consumer<FeatureProvider> afterInit,
Consumer<FeatureProvider> afterShutdown,
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
FeatureProviderStateManager oldManager) {
Consumer<FeatureProvider> afterInit,
Consumer<FeatureProvider> afterShutdown,
BiConsumer<FeatureProvider, OpenFeatureError> afterError,
FeatureProviderStateManager oldManager) {
try {
if (ProviderState.NOT_READY.equals(newManager.getState())) {
newManager.initialize(OpenFeatureAPI.getInstance().getEvaluationContext());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package dev.openfeature.sdk.internal;

import lombok.experimental.UtilityClass;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import lombok.experimental.UtilityClass;

@SuppressWarnings("checkstyle:MissingJavadocType")
@UtilityClass
Expand Down
Loading

0 comments on commit 891b5ae

Please sign in to comment.