From c91407f42d10888c50762e296d870a6ab6f35d8c Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Sat, 2 May 2020 16:58:42 +0300 Subject: [PATCH] Get rid of volatile configuration fields for Scheduler --- .../quartz/deployment/QuartzProcessor.java | 18 ++++++++++++------ .../quarkus/quartz/runtime/QuartzRecorder.java | 13 ++++++++----- .../quarkus/quartz/runtime/QuartzSupport.java | 17 +++++++++-------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/extensions/quartz/deployment/src/main/java/io/quarkus/quartz/deployment/QuartzProcessor.java b/extensions/quartz/deployment/src/main/java/io/quarkus/quartz/deployment/QuartzProcessor.java index e5d8c482ea6362..a1772513c592ee 100644 --- a/extensions/quartz/deployment/src/main/java/io/quarkus/quartz/deployment/QuartzProcessor.java +++ b/extensions/quartz/deployment/src/main/java/io/quarkus/quartz/deployment/QuartzProcessor.java @@ -7,6 +7,8 @@ import java.util.List; import java.util.Optional; +import javax.inject.Singleton; + import org.quartz.core.QuartzSchedulerThread; import org.quartz.core.SchedulerSignalerImpl; import org.quartz.impl.StdSchedulerFactory; @@ -25,7 +27,7 @@ import io.quarkus.agroal.deployment.JdbcDataSourceBuildItem; import io.quarkus.agroal.deployment.JdbcDataSourceSchemaReadyBuildItem; import io.quarkus.arc.deployment.AdditionalBeanBuildItem; -import io.quarkus.arc.deployment.BeanContainerBuildItem; +import io.quarkus.arc.deployment.SyntheticBeanBuildItem; import io.quarkus.datasource.common.runtime.DatabaseKind; import io.quarkus.deployment.Capabilities; import io.quarkus.deployment.annotations.BuildProducer; @@ -40,7 +42,6 @@ import io.quarkus.quartz.runtime.QuarkusQuartzConnectionPoolProvider; import io.quarkus.quartz.runtime.QuartzBuildTimeConfig; import io.quarkus.quartz.runtime.QuartzRecorder; -import io.quarkus.quartz.runtime.QuartzRuntimeConfig; import io.quarkus.quartz.runtime.QuartzScheduler; import io.quarkus.quartz.runtime.QuartzSupport; @@ -55,7 +56,7 @@ CapabilityBuildItem capability() { @BuildStep AdditionalBeanBuildItem beans() { - return new AdditionalBeanBuildItem(QuartzScheduler.class, QuartzSupport.class); + return new AdditionalBeanBuildItem(QuartzScheduler.class); } @BuildStep @@ -169,11 +170,16 @@ public List logCleanup(QuartzBuildTimeConfig config) @BuildStep @Record(RUNTIME_INIT) - public void build(QuartzRuntimeConfig runtimeConfig, QuartzBuildTimeConfig buildTimeConfig, QuartzRecorder recorder, - BeanContainerBuildItem beanContainer, + public void build(QuartzRecorder recorder, + BuildProducer syntheticBeanBuildItemBuildProducer, BuildProducer serviceStart, QuartzJDBCDriverDialectBuildItem driverDialect, List schemaReadyBuildItem) { - recorder.initialize(runtimeConfig, buildTimeConfig, beanContainer.getValue(), driverDialect.getDriver()); + + syntheticBeanBuildItemBuildProducer.produce(SyntheticBeanBuildItem.configure(QuartzSupport.class) + .scope(Singleton.class) + .setRuntimeInit() + .supplier(recorder.quartzSupportSupplier(driverDialect.getDriver())).done()); + // Make sure that StartupEvent is fired after the init serviceStart.produce(new ServiceStartBuildItem("quartz")); } diff --git a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzRecorder.java b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzRecorder.java index cbbd0b4892d2ed..f491833740ba94 100644 --- a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzRecorder.java +++ b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzRecorder.java @@ -1,17 +1,20 @@ package io.quarkus.quartz.runtime; import java.util.Optional; +import java.util.function.Supplier; -import io.quarkus.arc.runtime.BeanContainer; import io.quarkus.runtime.annotations.Recorder; @Recorder public class QuartzRecorder { - public void initialize(QuartzRuntimeConfig runTimeConfig, QuartzBuildTimeConfig buildTimeConfig, BeanContainer container, - Optional driverDialect) { - QuartzSupport support = container.instance(QuartzSupport.class); - support.initialize(runTimeConfig, buildTimeConfig, driverDialect); + public Supplier quartzSupportSupplier(Optional driverDialect) { + return new Supplier() { + @Override + public QuartzSupport get() { + return new QuartzSupport(driverDialect); + } + }; } } diff --git a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzSupport.java b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzSupport.java index 7894d7371ae627..034fc3357b8404 100644 --- a/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzSupport.java +++ b/extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/QuartzSupport.java @@ -2,18 +2,19 @@ import java.util.Optional; -import javax.inject.Singleton; +import javax.inject.Inject; -@Singleton public class QuartzSupport { - private volatile QuartzRuntimeConfig runtimeConfig; - private volatile QuartzBuildTimeConfig buildTimeConfig; - private volatile Optional driverDialect; + @Inject + QuartzRuntimeConfig runtimeConfig; - void initialize(QuartzRuntimeConfig runTimeConfig, QuartzBuildTimeConfig buildTimeConfig, Optional driverDialect) { - this.runtimeConfig = runTimeConfig; - this.buildTimeConfig = buildTimeConfig; + @Inject + QuartzBuildTimeConfig buildTimeConfig; + + private final Optional driverDialect; + + public QuartzSupport(Optional driverDialect) { this.driverDialect = driverDialect; }