-
Notifications
You must be signed in to change notification settings - Fork 54
feat: support isolated API instances #1928
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
Open
marcozabel
wants to merge
16
commits into
open-feature:main
Choose a base branch
from
marcozabel:feat/isolated-api-instances
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c46a3e6
feat: support isolated API instances
marcozabel a4b1d9b
fix(tests): separate singleton tests
marcozabel 3074e71
fix: spotless formatting and arch test compliance
marcozabel 554f20b
refactor(test): inject lock via constructor instead of field mutation
marcozabel 3a597f0
refactor: make OpenFeatureAPI lock field final
marcozabel 315b1a4
refactor: move OpenFeatureAPIFactory to sdk package and remove create…
marcozabel c13b616
refactor: bundle EventProvider onEmit and lock into atomic attachment
marcozabel e9692eb
feat: move factory to isolated package and warn on multi-instance pro…
marcozabel fceed2a
docs: add experimental @apiNote to OpenFeatureAPIFactory
marcozabel 94c9af7
test: add reverse-direction singleton isolation test
marcozabel 85b17d9
test: add delay before negative assertion in event isolation test
marcozabel a6d8cb0
test: use direct constructor in isolated tests
marcozabel 3e6758a
refactor: remove OpenFeatureAPIFactory class
marcozabel 8e17da5
fix: replace @apiNote with prose to satisfy javadoc plugin
marcozabel a9e5b96
fix: use AtomicReference with CAS in EventProvider.attach
marcozabel 91b8351
feat: restore OpenFeatureAPIFactory with package-private constructor
marcozabel 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
Empty file.
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
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
54 changes: 54 additions & 0 deletions
54
src/main/java/dev/openfeature/sdk/isolated/OpenFeatureAPIFactory.java
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,54 @@ | ||
| package dev.openfeature.sdk.isolated; | ||
|
|
||
| import dev.openfeature.sdk.OpenFeatureAPI; | ||
|
|
||
| /** | ||
| * Factory for creating isolated OpenFeature API instances. | ||
| * | ||
| * <p>Each instance returned by {@link #createAPI()} maintains its own state, | ||
| * including providers, evaluation context, hooks, event handlers, and | ||
| * transaction context propagators. Instances do not share state with the | ||
| * global singleton ({@link OpenFeatureAPI#getInstance()}) or with each other. | ||
| * | ||
| * <p>This class lives in a distinct package ({@code dev.openfeature.sdk.isolated}) | ||
| * to make isolated instances intentionally less discoverable than the global | ||
| * singleton, reducing the chance of accidental use when the singleton would be | ||
| * appropriate. | ||
| * | ||
| * <p>This is useful for dependency injection frameworks, testing scenarios, | ||
| * and applications composed of multiple submodules requiring distinct providers. | ||
| * | ||
| * <p><strong>Spec references:</strong> | ||
| * <ul> | ||
| * <li>Requirement 1.8.1 — factory function for isolated instances</li> | ||
| * <li>Requirement 1.8.3 — factory in a distinct package/module</li> | ||
| * </ul> | ||
| * | ||
| * @apiNote This API is experimental and subject to change. | ||
| * @see <a href="https://openfeature.dev/specification/sections/flag-evaluation#18-isolated-api-instances"> | ||
| * Spec §1.8 — Isolated API Instances</a> | ||
| */ | ||
| public final class OpenFeatureAPIFactory { | ||
|
|
||
| private OpenFeatureAPIFactory() { | ||
| // utility class | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new, independent {@link OpenFeatureAPI} instance with fully | ||
| * isolated state. | ||
| * | ||
| * <p>Usage: | ||
| * <pre>{@code | ||
| * OpenFeatureAPI api = OpenFeatureAPIFactory.createAPI(); | ||
| * api.setProvider(new MyProvider()); | ||
| * Client client = api.getClient(); | ||
| * }</pre> | ||
| * | ||
| * @apiNote This API is experimental and subject to change. | ||
| * @return a new API instance | ||
| */ | ||
| public static OpenFeatureAPI createAPI() { | ||
| return OpenFeatureAPI.createIsolated(); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we simplify all of this with
we expect the existing attachement to be
null, every other case is exceptional, and we wouldn't retry anyway