-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sviatoslav Sharaev <[email protected]>
- Loading branch information
Showing
11 changed files
with
342 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
24 changes: 24 additions & 0 deletions
24
src/main/java/dev/openfeature/sdk/NoOpTransactionContextPropagator.java
This file contains 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,24 @@ | ||
package dev.openfeature.sdk; | ||
|
||
/** | ||
* A {@link TransactionContextPropagator} that simply returns null. | ||
*/ | ||
public class NoOpTransactionContextPropagator implements TransactionContextPropagator { | ||
|
||
/** | ||
* {@inheritDoc} | ||
* @return null | ||
*/ | ||
@Override | ||
public EvaluationContext getTransactionContext() { | ||
return null; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void setTransactionContext(EvaluationContext evaluationContext) { | ||
|
||
} | ||
} |
This file contains 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 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
28 changes: 28 additions & 0 deletions
28
src/main/java/dev/openfeature/sdk/ThreadLocalTransactionContextPropagator.java
This file contains 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,28 @@ | ||
package dev.openfeature.sdk; | ||
|
||
/** | ||
* A {@link ThreadLocalTransactionContextPropagator} is a transactional context propagator | ||
* that uses a ThreadLocal to persist a transactional context for the duration of a single thread. | ||
* | ||
* @see TransactionContextPropagator | ||
*/ | ||
public class ThreadLocalTransactionContextPropagator implements TransactionContextPropagator { | ||
|
||
private final ThreadLocal<EvaluationContext> evaluationContextThreadLocal = new ThreadLocal<>(); | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public EvaluationContext getTransactionContext() { | ||
return this.evaluationContextThreadLocal.get(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void setTransactionContext(EvaluationContext evaluationContext) { | ||
this.evaluationContextThreadLocal.set(evaluationContext); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/dev/openfeature/sdk/TransactionContextPropagator.java
This file contains 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,27 @@ | ||
package dev.openfeature.sdk; | ||
|
||
/** | ||
* {@link TransactionContextPropagator} is responsible for persisting a transactional context | ||
* for the duration of a single transaction. | ||
* Examples of potential transaction specific context include: a user id, user agent, IP. | ||
* Transaction context is merged with evaluation context prior to flag evaluation. | ||
* <p> | ||
* The precedence of merging context can be seen in | ||
* <a href=https://openfeature.dev/specification/sections/evaluation-context#requirement-323>the specification</a>. | ||
* </p> | ||
*/ | ||
public interface TransactionContextPropagator { | ||
|
||
/** | ||
* Returns the currently defined transaction context using the registered transaction | ||
* context propagator. | ||
* | ||
* @return {@link EvaluationContext} The current transaction context | ||
*/ | ||
EvaluationContext getTransactionContext(); | ||
|
||
/** | ||
* Sets the transaction context. | ||
*/ | ||
void setTransactionContext(EvaluationContext evaluationContext); | ||
} |
Oops, something went wrong.