Skip to content

Commit

Permalink
Arc: support storage for SR-CP
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage committed Jan 19, 2021
1 parent 7afdbc0 commit 372c229
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.LiveReloadBuildItem;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.deployment.builditem.StorageReadyBuildItem;
import io.quarkus.deployment.builditem.TestClassPredicateBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveFieldBuildItem;
Expand Down Expand Up @@ -432,6 +433,7 @@ public ValidationPhaseBuildItem validate(ObserverRegistrationPhaseBuildItem obse
@Record(STATIC_INIT)
public BeanContainerBuildItem generateResources(ArcConfig config, ArcRecorder recorder, ShutdownContextBuildItem shutdown,
ValidationPhaseBuildItem validationPhase,
StorageReadyBuildItem storageReady,
List<ValidationPhaseBuildItem.ValidationErrorBuildItem> validationErrors,
List<BeanContainerListenerBuildItem> beanContainerListenerBuildItems,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkus.arc.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;

public class ArcStorageProcessor {
@BuildStep
public IndexDependencyBuildItem scanForStorage() {
return new IndexDependencyBuildItem("io.quarkus.arc", "arc");
}
}
4 changes: 4 additions & 0 deletions extensions/arc/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<groupId>org.eclipse.microprofile.context-propagation</groupId>
<artifactId>microprofile-context-propagation-api</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-context-propagation</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@

import org.eclipse.microprofile.context.ThreadContext;
import org.eclipse.microprofile.context.spi.ThreadContextController;
import org.eclipse.microprofile.context.spi.ThreadContextProvider;
import org.eclipse.microprofile.context.spi.ThreadContextSnapshot;

import io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;
import io.quarkus.arc.InjectableContext;
import io.quarkus.arc.InjectableContext.ContextState;
import io.quarkus.arc.ManagedContext;
import io.quarkus.arc.impl.RequestContextStorageDeclaration;
import io.smallrye.context.FastStorageThreadContextProvider;

/**
* Context propagation for Arc
* Only handles Request context as that's currently the only one in Arc that needs propagation.
*/
public class ArcContextProvider implements ThreadContextProvider {
public class ArcContextProvider implements FastStorageThreadContextProvider<RequestContextStorageDeclaration> {

protected static final ThreadContextController NOOP_CONTROLLER = new ThreadContextController() {
@Override
Expand Down Expand Up @@ -179,4 +180,14 @@ public void endContext() throws IllegalStateException {
}

}

@Override
public Object clearedValue(Map<String, String> props) {
return null;
}

@Override
public Class<RequestContextStorageDeclaration> getStorageDeclaration() {
return RequestContextStorageDeclaration.class;
}
}
7 changes: 7 additions & 0 deletions independent-projects/arc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<version.jakarta-annotation>1.3.5</version.jakarta-annotation>
<version.gizmo>1.0.6.Final</version.gizmo>
<version.jpa>2.2.3</version.jpa>
<version.sr.cp.storage>1.1.0</version.sr.cp.storage>

<version.surefire.plugin>3.0.0-M5</version.surefire.plugin>
<nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version>
Expand Down Expand Up @@ -147,6 +148,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-context-propagation-storage</artifactId>
<version>${version.sr.cp.storage}</version>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions independent-projects/arc/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<artifactId>jboss-logging</artifactId>
</dependency>

<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-context-propagation-storage</artifactId>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.quarkus.arc.InjectableBean;
import io.quarkus.arc.ManagedContext;
import io.quarkus.arc.impl.EventImpl.Notifier;
import io.smallrye.context.storage.spi.StorageManager;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.HashSet;
Expand Down Expand Up @@ -33,7 +34,8 @@ class RequestContext implements ManagedContext {
private static final Logger LOGGER = Logger.getLogger(RequestContext.class.getPackage().getName());

// It's a normal scope so there may be no more than one mapped instance per contextual type per thread
private final ThreadLocal<ConcurrentMap<Contextual<?>, ContextInstanceHandle<?>>> currentContext = new ThreadLocal<>();
private final ThreadLocal<ConcurrentMap<Contextual<?>, ContextInstanceHandle<?>>> currentContext = StorageManager
.threadLocal(RequestContextStorageDeclaration.class);

private final LazyValue<Notifier<Object>> initializedNotifier;
private final LazyValue<Notifier<Object>> beforeDestroyedNotifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkus.arc.impl;

import io.quarkus.arc.ContextInstanceHandle;
import io.smallrye.context.storage.spi.StorageDeclaration;
import java.util.concurrent.ConcurrentMap;
import javax.enterprise.context.spi.Contextual;

public class RequestContextStorageDeclaration
implements StorageDeclaration<ConcurrentMap<Contextual<?>, ContextInstanceHandle<?>>> {

}

0 comments on commit 372c229

Please sign in to comment.