Skip to content
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

Batch custom scopes activation #123

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import jakarta.enterprise.inject.AmbiguousResolutionException;
import jakarta.inject.Named;

import org.jberet.cdi.JobScoped;
import org.jberet.cdi.PartitionScoped;
import org.jberet.cdi.StepScoped;
import org.jberet.creation.ArchiveXmlLoader;
import org.jberet.creation.BatchBeanProducer;
import org.jberet.job.model.BatchArtifacts;
Expand Down Expand Up @@ -62,12 +65,17 @@
import io.quarkiverse.jberet.runtime.JBeretRecorder;
import io.quarkiverse.jberet.runtime.JobsProducer;
import io.quarkiverse.jberet.runtime.QuarkusJobScheduler;
import io.quarkiverse.jberet.runtime.scope.QuarkusJobScopedContextImpl;
import io.quarkiverse.jberet.runtime.scope.QuarkusPartitionScopedContextImpl;
import io.quarkiverse.jberet.runtime.scope.QuarkusStepScopedContextImpl;
import io.quarkus.agroal.spi.JdbcDataSourceBuildItem;
import io.quarkus.arc.Unremovable;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.arc.deployment.BeanDiscoveryFinishedBuildItem;
import io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem;
import io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem.ContextConfiguratorBuildItem;
import io.quarkus.arc.deployment.ValidationPhaseBuildItem;
import io.quarkus.arc.deployment.ValidationPhaseBuildItem.ValidationErrorBuildItem;
import io.quarkus.arc.processor.AnnotationsTransformer;
Expand Down Expand Up @@ -112,6 +120,14 @@ public RuntimeInitializedClassBuildItem runtimeInitializedDefaultHolder() {
return new RuntimeInitializedClassBuildItem("org.jberet.spi.JobOperatorContext$DefaultHolder");
}

@BuildStep
public void batchScopes(ContextRegistrationPhaseBuildItem c, BuildProducer<ContextConfiguratorBuildItem> v) {
v.produce(new ContextConfiguratorBuildItem(
c.getContext().configure(JobScoped.class).contextClass(QuarkusJobScopedContextImpl.class),
c.getContext().configure(StepScoped.class).contextClass(QuarkusStepScopedContextImpl.class),
c.getContext().configure(PartitionScoped.class).contextClass(QuarkusPartitionScopedContextImpl.class)));
}

@BuildStep
public void config(BuildProducer<RunTimeConfigBuilderBuildItem> runTimeConfigBuilder) {
runTimeConfigBuilder.produce(new RunTimeConfigBuilderBuildItem(JBeretConfigSourceFactoryBuilder.class.getName()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.quarkiverse.jberet.runtime.scope;

import java.lang.annotation.Annotation;

import jakarta.enterprise.context.spi.Contextual;
import jakarta.enterprise.context.spi.CreationalContext;

import org.jberet.cdi.JobScoped;
import org.jberet.creation.JobScopedContextImpl;

import io.quarkus.arc.InjectableContext;

public class QuarkusJobScopedContextImpl implements InjectableContext {
private final JobScopedContextImpl impl;

public QuarkusJobScopedContextImpl() {
this.impl = JobScopedContextImpl.getInstance();
}

@Override
public void destroy(Contextual<?> contextual) {
this.impl.destroy(contextual);
}

@Override
public Class<? extends Annotation> getScope() {
return JobScoped.class;
}

@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
return impl.get(contextual, creationalContext);
}

@Override
public <T> T get(Contextual<T> contextual) {
return impl.get(contextual);
}

@Override
public boolean isActive() {
return impl.isActive();
}

@Override
public void destroy() {
this.impl.destroy(null);
}

@Override
public ContextState getState() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.quarkiverse.jberet.runtime.scope;

import java.lang.annotation.Annotation;

import jakarta.enterprise.context.spi.Contextual;
import jakarta.enterprise.context.spi.CreationalContext;

import org.jberet.cdi.PartitionScoped;
import org.jberet.creation.PartitionScopedContextImpl;

import io.quarkus.arc.InjectableContext;

public class QuarkusPartitionScopedContextImpl implements InjectableContext {
private final PartitionScopedContextImpl impl;

public QuarkusPartitionScopedContextImpl() {
this.impl = PartitionScopedContextImpl.getInstance();
}

@Override
public void destroy(Contextual<?> contextual) {
this.impl.destroy(contextual);
}

@Override
public Class<? extends Annotation> getScope() {
return PartitionScoped.class;
}

@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
return impl.get(contextual, creationalContext);
}

@Override
public <T> T get(Contextual<T> contextual) {
return impl.get(contextual);
}

@Override
public boolean isActive() {
return impl.isActive();
}

@Override
public void destroy() {
this.impl.destroy(null);
}

@Override
public ContextState getState() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.quarkiverse.jberet.runtime.scope;

import java.lang.annotation.Annotation;

import jakarta.enterprise.context.spi.Contextual;
import jakarta.enterprise.context.spi.CreationalContext;

import org.jberet.cdi.StepScoped;
import org.jberet.creation.StepScopedContextImpl;

import io.quarkus.arc.InjectableContext;

public class QuarkusStepScopedContextImpl implements InjectableContext {
private final StepScopedContextImpl impl;

public QuarkusStepScopedContextImpl() {
this.impl = StepScopedContextImpl.getInstance();
}

@Override
public void destroy(Contextual<?> contextual) {
this.impl.destroy(contextual);
}

@Override
public Class<? extends Annotation> getScope() {
return StepScoped.class;
}

@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
return impl.get(contextual, creationalContext);
}

@Override
public <T> T get(Contextual<T> contextual) {
return impl.get(contextual);
}

@Override
public boolean isActive() {
return impl.isActive();
}

@Override
public void destroy() {
this.impl.destroy(null);
}

@Override
public ContextState getState() {
return null;
}
}
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<module>programmatic</module>
<module>client</module>
<module>scripting</module>
<module>scopes</module>
<module>tck</module>
</modules>

Expand Down
33 changes: 33 additions & 0 deletions integration-tests/scopes/common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkiverse.jberet</groupId>
<artifactId>quarkus-jberet-integration-tests</artifactId>
<version>2.2.1-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>quarkus-jberet-integration-tests-scopes-commons</artifactId>
<name>Quarkus - JBeret - Integrations Tests - Scopes - Common</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
</dependency>
<dependency>
<groupId>org.jberet.test-apps</groupId>
<version>${jberet.version}</version>
<artifactId>cdiScopes-commons</artifactId>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkiverse.jberet.it.cdiscopes;

import jakarta.inject.Inject;

import org.jberet.testapps.common.AbstractIT;
import org.junit.jupiter.api.BeforeEach;

import io.quarkiverse.jberet.runtime.QuarkusJobOperator;

/**
* Quarkus version of JBeret {@link AbstractIT}
*/
public abstract class AbstractQuarkusIT extends AbstractIT {
@Inject
QuarkusJobOperator quarkusJobOperator;

@BeforeEach
@Override
public void before() throws Exception {
super.jobOperator = new JobOperatorImplQuarkusDelegate(quarkusJobOperator);
}
}
Loading
Loading