Skip to content

Commit a3ed93e

Browse files
PR suggestion: use concrete hooks
Signed-off-by: Alexandra Oberaigner <[email protected]>
1 parent dbfcab6 commit a3ed93e

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package dev.openfeature.sdk;
2+
3+
/**
4+
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
5+
* to the lifecycle of flag evaluation.
6+
*
7+
* @see Hook
8+
*/
9+
public interface ObjectHook extends Hook<Object> {
10+
11+
@Override
12+
default boolean supportsFlagValueType(FlagValueType flagValueType) {
13+
return FlagValueType.OBJECT == flagValueType;
14+
}
15+
}

src/test/java/dev/openfeature/sdk/benchmark/AllocationBenchmark.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
import static dev.openfeature.sdk.testutils.TestFlagsUtils.OBJECT_FLAG_KEY;
77
import static dev.openfeature.sdk.testutils.TestFlagsUtils.STRING_FLAG_KEY;
88

9+
import dev.openfeature.sdk.BooleanHook;
910
import dev.openfeature.sdk.Client;
11+
import dev.openfeature.sdk.DoubleHook;
1012
import dev.openfeature.sdk.EvaluationContext;
11-
import dev.openfeature.sdk.Hook;
1213
import dev.openfeature.sdk.HookContext;
1314
import dev.openfeature.sdk.ImmutableContext;
1415
import dev.openfeature.sdk.ImmutableStructure;
16+
import dev.openfeature.sdk.IntegerHook;
1517
import dev.openfeature.sdk.NoOpProvider;
18+
import dev.openfeature.sdk.ObjectHook;
1619
import dev.openfeature.sdk.OpenFeatureAPI;
20+
import dev.openfeature.sdk.StringHook;
1721
import dev.openfeature.sdk.Value;
1822
import java.util.HashMap;
1923
import java.util.Map;
@@ -25,7 +29,7 @@
2529

2630
/**
2731
* Runs a large volume of flag evaluations on a VM with 1G memory and GC
28-
* completely disabled so we can take a heap-dump.
32+
* completely disabled, so we can take a heap-dump.
2933
*/
3034
public class AllocationBenchmark {
3135

@@ -48,31 +52,31 @@ public void run() {
4852
Map<String, Value> clientAttrs = new HashMap<>();
4953
clientAttrs.put("client", new Value(2));
5054
client.setEvaluationContext(new ImmutableContext(clientAttrs));
51-
client.addHooks(new Hook<Object>() {
55+
client.addHooks(new ObjectHook() {
5256
@Override
5357
public Optional<EvaluationContext> before(HookContext<Object> ctx, Map<String, Object> hints) {
5458
return Optional.ofNullable(new ImmutableContext());
5559
}
5660
});
57-
client.addHooks(new Hook<String>() {
61+
client.addHooks(new StringHook() {
5862
@Override
5963
public Optional<EvaluationContext> before(HookContext<String> ctx, Map<String, Object> hints) {
6064
return Optional.ofNullable(new ImmutableContext());
6165
}
6266
});
63-
client.addHooks(new Hook<Boolean>() {
67+
client.addHooks(new BooleanHook() {
6468
@Override
6569
public Optional<EvaluationContext> before(HookContext<Boolean> ctx, Map<String, Object> hints) {
6670
return Optional.ofNullable(new ImmutableContext());
6771
}
6872
});
69-
client.addHooks(new Hook<Integer>() {
73+
client.addHooks(new IntegerHook() {
7074
@Override
7175
public Optional<EvaluationContext> before(HookContext<Integer> ctx, Map<String, Object> hints) {
7276
return Optional.ofNullable(new ImmutableContext());
7377
}
7478
});
75-
client.addHooks(new Hook<Double>() {
79+
client.addHooks(new DoubleHook() {
7680
@Override
7781
public Optional<EvaluationContext> before(HookContext<Double> ctx, Map<String, Object> hints) {
7882
return Optional.ofNullable(new ImmutableContext());

0 commit comments

Comments
 (0)