-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ArC - introduce the ContextReferenceFactory abstraction
- this API allows quarkus to supply an optimized backend for any non-shared context of a normal scope - currently it's only used by the request context - an extension can provide a custom factory via ContextReferenceFactoryBuildItem
- Loading branch information
Showing
11 changed files
with
181 additions
and
39 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
22 changes: 22 additions & 0 deletions
22
.../deployment/src/main/java/io/quarkus/arc/deployment/ContextReferenceFactoryBuildItem.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,22 @@ | ||
package io.quarkus.arc.deployment; | ||
|
||
import io.quarkus.arc.ContextReferenceFactory; | ||
import io.quarkus.builder.item.SimpleBuildItem; | ||
import io.quarkus.runtime.RuntimeValue; | ||
|
||
/** | ||
* An extension can provide a custom {@link ContextReferenceFactory}. | ||
*/ | ||
public final class ContextReferenceFactoryBuildItem extends SimpleBuildItem { | ||
|
||
private final RuntimeValue<ContextReferenceFactory> factory; | ||
|
||
public ContextReferenceFactoryBuildItem(RuntimeValue<ContextReferenceFactory> factory) { | ||
this.factory = factory; | ||
} | ||
|
||
public RuntimeValue<ContextReferenceFactory> getFactory() { | ||
return factory; | ||
} | ||
|
||
} |
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
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
31 changes: 31 additions & 0 deletions
31
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/ContextReference.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,31 @@ | ||
package io.quarkus.arc; | ||
|
||
import io.quarkus.arc.InjectableContext.ContextState; | ||
|
||
/** | ||
* Represents the current context of a normal scope. | ||
* | ||
* @param <T> | ||
* @see ContextReferenceFactory | ||
*/ | ||
public interface ContextReference<T extends ContextState> { | ||
|
||
/** | ||
* | ||
* @return the current state | ||
*/ | ||
T get(); | ||
|
||
/** | ||
* Sets the current state. | ||
* | ||
* @param state | ||
*/ | ||
void set(T state); | ||
|
||
/** | ||
* Removes the current state. | ||
*/ | ||
void remove(); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
independent-projects/arc/runtime/src/main/java/io/quarkus/arc/ContextReferenceFactory.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,15 @@ | ||
package io.quarkus.arc; | ||
|
||
import io.quarkus.arc.InjectableContext.ContextState; | ||
|
||
/** | ||
* This factory is used to create a new {@link ContextReference} for a non-shared context of a normal scope, e.g. the request | ||
* context. | ||
* | ||
* @param <T> | ||
*/ | ||
public interface ContextReferenceFactory { | ||
|
||
<T extends ContextState> ContextReference<T> create(); | ||
|
||
} |
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
30 changes: 30 additions & 0 deletions
30
...t-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ThreadLocalContextReference.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,30 @@ | ||
package io.quarkus.arc.impl; | ||
|
||
import io.quarkus.arc.ContextReference; | ||
import io.quarkus.arc.InjectableContext.ContextState; | ||
|
||
/** | ||
* {@link ThreadLocal} implementation of {@link ContextReference}. | ||
* | ||
* @param <T> | ||
*/ | ||
final class ThreadLocalContextReference<T extends ContextState> implements ContextReference<T> { | ||
|
||
private final ThreadLocal<T> currentContext = new ThreadLocal<>(); | ||
|
||
@Override | ||
public T get() { | ||
return currentContext.get(); | ||
} | ||
|
||
@Override | ||
public void set(T state) { | ||
currentContext.set(state); | ||
} | ||
|
||
@Override | ||
public void remove() { | ||
currentContext.remove(); | ||
} | ||
|
||
} |
Oops, something went wrong.