-
Notifications
You must be signed in to change notification settings - Fork 50
feat: add hook data support #1620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chrfwow
merged 23 commits into
open-feature:main
from
open-feature-forking:feat/hook-data-support
Oct 6, 2025
Merged
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
269dfe4
feat: add hook data support
alexandraoberaigner 3b113c1
feat: gemini suggestions
alexandraoberaigner 5fb278b
feat: hook executor impl (WIP)
alexandraoberaigner ceedffd
Use shared hook context
guidobrei 2843298
Split HookData interface and implementation
guidobrei 235abba
Atopted tests
guidobrei e0935f3
Remove obsolete test
guidobrei dbfcab6
HookSupport improvements: rename back to old name, move code from sta…
alexandraoberaigner a3ed93e
PR suggestion: use concrete hooks
alexandraoberaigner 3ea9894
PR suggestions: DefaultHookData access modifier, no star imports
alexandraoberaigner 27f3e2a
feat: separate hook support data from logic, PR suggestions
alexandraoberaigner 4ab14bf
Update DefaultHookDataTest.java spotless
alexandraoberaigner 1d8f758
fix tests, spotless apply
alexandraoberaigner 8a9738f
exclude lombok generated functions from codecov
alexandraoberaigner b6cd0e2
replace init function with setters
alexandraoberaigner 1a7e5af
pr suggestion: replace Generated annotation with more descriptive Exc…
alexandraoberaigner 7fe0675
PR suggestion: make HookSupportData a real POJO
alexandraoberaigner 92b6dc4
gemini suggestions
alexandraoberaigner 0e897f2
PR suggestion: call hooks as early as possible
alexandraoberaigner 8b6aba9
PR suggestions: integration test hook data usage in client, set pair …
alexandraoberaigner 3417827
add hook data spec test
alexandraoberaigner db6cc86
Merge branch 'main' into feat/hook-data-support
alexandraoberaigner 519c303
Merge branch 'main' into feat/hook-data-support
chrfwow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package dev.openfeature.sdk; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Hook data provides a way for hooks to maintain state across their execution stages. | ||
* Each hook instance gets its own isolated data store that persists only for the duration | ||
* of a single flag evaluation. | ||
*/ | ||
public interface HookData { | ||
|
||
/** | ||
* Sets a value for the given key. | ||
* | ||
* @param key the key to store the value under | ||
* @param value the value to store | ||
*/ | ||
void set(String key, Object value); | ||
|
||
/** | ||
* Gets the value for the given key. | ||
* | ||
* @param key the key to retrieve the value for | ||
* @return the value, or null if not found | ||
*/ | ||
Object get(String key); | ||
|
||
/** | ||
* Gets the value for the given key, cast to the specified type. | ||
* | ||
* @param <T> the type to cast to | ||
* @param key the key to retrieve the value for | ||
* @param type the class to cast to | ||
* @return the value cast to the specified type, or null if not found | ||
* @throws ClassCastException if the value cannot be cast to the specified type | ||
*/ | ||
<T> T get(String key, Class<T> type); | ||
|
||
/** | ||
* Default implementation uses a HashMap. | ||
*/ | ||
static HookData create() { | ||
return new DefaultHookData(); | ||
} | ||
|
||
/** | ||
* Default implementation of HookData. | ||
*/ | ||
class DefaultHookData implements HookData { | ||
private Map<String, Object> data; | ||
|
||
@Override | ||
public void set(String key, Object value) { | ||
if (data == null) { | ||
data = new HashMap<>(); | ||
} | ||
data.put(key, value); | ||
} | ||
|
||
@Override | ||
public Object get(String key) { | ||
if (data == null) { | ||
return null; | ||
} | ||
return data.get(key); | ||
} | ||
|
||
@Override | ||
public <T> T get(String key, Class<T> type) { | ||
Object value = get(key); | ||
if (value == null) { | ||
return null; | ||
} | ||
if (!type.isInstance(value)) { | ||
throw new ClassCastException("Value for key '" + key + "' is not of type " + type.getName()); | ||
} | ||
return type.cast(value); | ||
} | ||
chrfwow marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.