Skip to content

Commit 1e71a6b

Browse files
Merge pull request open-feature#17 from open-feature/mocked-logger
Add javadoc to interfaces and tidy them up.
2 parents 2b3ae81 + d2e61eb commit 1e71a6b

11 files changed

+82
-9
lines changed

lib/src/main/java/dev/openfeature/javasdk/BaseEvaluation.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package dev.openfeature.javasdk;
22

3+
/**
4+
* We differ between the evaluation results that providers return and what is given to the end users. This is a common interface between them.
5+
* @param <T> The type of flag being evaluated.
6+
*/
37
public interface BaseEvaluation<T> {
48
/**
59
* Returns the resolved value of the evaluation.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
package dev.openfeature.javasdk;
22

3-
public interface Client extends FlagEvaluationLifecycle, Features {
3+
import java.util.List;
4+
5+
/**
6+
* Interface used to resolve flags of varying types.
7+
*/
8+
public interface Client extends Features {
49
Metadata getMetadata();
10+
11+
/**
12+
* Adds hooks for evaluation.
13+
*
14+
* Hooks are run in the order they're added in the before stage. They are run in reverse order for all other stages.
15+
*
16+
* @param hooks The hook to add.
17+
*/
18+
void addHooks(Hook... hooks);
19+
20+
/**
21+
* Fetch the hooks associated to this client.
22+
* @return A list of {@link Hook}s.
23+
*/
24+
List<Hook> getClientHooks();
525
}

lib/src/main/java/dev/openfeature/javasdk/FeatureProvider.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package dev.openfeature.javasdk;
22

3+
/**
4+
* The interface implemented by upstream flag providers to resolve flags for their service.
5+
*/
36
public interface FeatureProvider {
47
Metadata getMetadata();
58
ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);

lib/src/main/java/dev/openfeature/javasdk/Features.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package dev.openfeature.javasdk;
22

3+
/**
4+
* An API for the type-specific fetch methods we offer end users.
5+
*/
36
public interface Features {
47

58
Boolean getBooleanValue(String key, Boolean defaultValue);

lib/src/main/java/dev/openfeature/javasdk/FlagEvaluationDetails.java

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
import javax.annotation.Nullable;
77

8+
/**
9+
* Contains information about how the evaluation happened, including any resolved values.
10+
* @param <T> the type of the flag being evaluated.
11+
*/
812
@Data @Builder
913
public class FlagEvaluationDetails<T> implements BaseEvaluation<T> {
1014
String flagKey;

lib/src/main/java/dev/openfeature/javasdk/FlagEvaluationLifecycle.java

-8
This file was deleted.

lib/src/main/java/dev/openfeature/javasdk/Hook.java

+31
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,42 @@
44

55
import java.util.Optional;
66

7+
/**
8+
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
9+
* to the lifecycle of flag evaluation.
10+
* @param <T> The type of the flag being evaluated.
11+
*/
712
public interface Hook<T> {
13+
/**
14+
* Runs before flag is resolved.
15+
* @param ctx Information about the particular flag evaluation
16+
* @param hints An immutable mapping of data for users to communicate to the hooks.
17+
* @return An optional {@link EvaluationContext}. If returned, it will be merged with the EvaluationContext instances from other hooks, the client and API.
18+
*/
819
default Optional<EvaluationContext> before(HookContext<T> ctx, ImmutableMap<String, Object> hints) {
920
return Optional.empty();
1021
}
22+
23+
/**
24+
* Runs after a flag is resolved.
25+
* @param ctx Information about the particular flag evaluation
26+
* @param details Information about how the flag was resolved, including any resolved values.
27+
* @param hints An immutable mapping of data for users to communicate to the hooks.
28+
*/
1129
default void after(HookContext<T> ctx, FlagEvaluationDetails<T> details, ImmutableMap<String, Object> hints) {}
30+
31+
/**
32+
* Run when evaluation encounters an error. This will always run. Errors thrown will be swallowed.
33+
* @param ctx Information about the particular flag evaluation
34+
* @param error The exception that was thrown.
35+
* @param hints An immutable mapping of data for users to communicate to the hooks.
36+
*/
1237
default void error(HookContext<T> ctx, Exception error, ImmutableMap<String, Object> hints) {}
38+
39+
/**
40+
* Run after flag evaluation, including any error processing. This will always run. Errors will be swallowed.
41+
* @param ctx Information about the particular flag evaluation
42+
* @param hints An immutable mapping of data for users to communicate to the hooks.
43+
*/
1344
default void finallyAfter(HookContext<T> ctx, ImmutableMap<String, Object> hints) {}
1445
}

lib/src/main/java/dev/openfeature/javasdk/HookContext.java

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
import lombok.Value;
66
import lombok.With;
77

8+
/**
9+
* A data class to hold immutable context that {@link Hook} instances use.
10+
*
11+
* @param <T> the type for the flag being evaluated
12+
*/
813
@Value @Builder @With
914
public class HookContext<T> {
1015
@NonNull String flagKey;
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package dev.openfeature.javasdk;
22

3+
/**
4+
* Holds identifying information about a given entity
5+
*/
36
public interface Metadata {
47
public String getName();
58
}

lib/src/main/java/dev/openfeature/javasdk/NoOpProvider.java

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import lombok.Getter;
44

5+
/**
6+
* A {@link FeatureProvider} that simply returns the default values passed to it.
7+
*/
58
public class NoOpProvider implements FeatureProvider {
69
public static final String PASSED_IN_DEFAULT = "Passed in default";
710
@Getter

lib/src/main/java/dev/openfeature/javasdk/OpenFeatureAPI.java

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
import java.util.Arrays;
99
import java.util.List;
1010

11+
/**
12+
* A global singleton which holds base configuration for the OpenFeature library.
13+
*
14+
* Configuration here will be shared across all {@link Client}s.
15+
*/
1116
public class OpenFeatureAPI {
1217
@Getter @Setter private FeatureProvider provider;
1318
private static OpenFeatureAPI api;

0 commit comments

Comments
 (0)