Skip to content

Commit

Permalink
Merge pull request #40808 from gsmet/narayana-runtime-init
Browse files Browse the repository at this point in the history
Move allowUnsafeMultipleLastResources call to runtime init
  • Loading branch information
yrodiere authored May 23, 2024
2 parents 4edf7d0 + 0f23c24 commit a18c9d7
Showing 1 changed file with 37 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.narayana.jta.deployment;

import static io.quarkus.deployment.annotations.ExecutionTime.RUNTIME_INIT;
import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -101,8 +100,11 @@ public void build(NarayanaJtaRecorder recorder,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<RuntimeInitializedClassBuildItem> runtimeInit,
BuildProducer<FeatureBuildItem> feature,
BuildProducer<LogCleanupFilterBuildItem> logCleanupFilters,
BuildProducer<NativeImageFeatureBuildItem> nativeImageFeatures,
TransactionManagerConfiguration transactions, TransactionManagerBuildTimeConfig transactionManagerBuildTimeConfig,
ShutdownContextBuildItem shutdownContextBuildItem) {
ShutdownContextBuildItem shutdownContextBuildItem,
Capabilities capabilities) {
recorder.handleShutdown(shutdownContextBuildItem, transactions);
feature.produce(new FeatureBuildItem(Feature.NARAYANA_JTA));
additionalBeans.produce(new AdditionalBeanBuildItem(NarayanaJtaProducers.class));
Expand Down Expand Up @@ -163,44 +165,13 @@ public void build(NarayanaJtaRecorder recorder,
recorder.setDefaultProperties(defaultProperties);
// This must be done before setNodeName as the code in setNodeName will create a TSM based on the value of this property
recorder.disableTransactionStatusManager();
allowUnsafeMultipleLastResources(recorder, transactionManagerBuildTimeConfig, capabilities, logCleanupFilters,
nativeImageFeatures);
recorder.setNodeName(transactions);
recorder.setDefaultTimeout(transactions);
recorder.setConfig(transactions);
}

@BuildStep
@Record(STATIC_INIT)
public void allowUnsafeMultipleLastResources(NarayanaJtaRecorder recorder,
TransactionManagerBuildTimeConfig transactionManagerBuildTimeConfig,
Capabilities capabilities, BuildProducer<LogCleanupFilterBuildItem> logCleanupFilters,
BuildProducer<NativeImageFeatureBuildItem> nativeImageFeatures) {
switch (transactionManagerBuildTimeConfig.unsafeMultipleLastResources
.orElse(UnsafeMultipleLastResourcesMode.DEFAULT)) {
case ALLOW -> {
recorder.allowUnsafeMultipleLastResources(capabilities.isPresent(Capability.AGROAL), true);
// we will handle the warnings ourselves at runtime init when the option is set explicitly
logCleanupFilters.produce(
new LogCleanupFilterBuildItem("com.arjuna.ats.arjuna", "ARJUNA012139", "ARJUNA012141", "ARJUNA012142"));
}
case WARN_FIRST -> {
recorder.allowUnsafeMultipleLastResources(capabilities.isPresent(Capability.AGROAL), true);
// we will handle the warnings ourselves at runtime init when the option is set explicitly
// but we still want Narayana to produce a warning on the first offending transaction
logCleanupFilters.produce(
new LogCleanupFilterBuildItem("com.arjuna.ats.arjuna", "ARJUNA012139", "ARJUNA012142"));
}
case WARN_EACH -> {
recorder.allowUnsafeMultipleLastResources(capabilities.isPresent(Capability.AGROAL), false);
// we will handle the warnings ourselves at runtime init when the option is set explicitly
// but we still want Narayana to produce one warning per offending transaction
logCleanupFilters.produce(
new LogCleanupFilterBuildItem("com.arjuna.ats.arjuna", "ARJUNA012139", "ARJUNA012142"));
}
case FAIL -> { // No need to do anything, this is the default behavior of Narayana
}
}
}

@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class)
public void nativeImageFeature(TransactionManagerBuildTimeConfig transactionManagerBuildTimeConfig,
BuildProducer<NativeImageFeatureBuildItem> nativeImageFeatures) {
Expand Down Expand Up @@ -271,4 +242,35 @@ void unremovableBean(BuildProducer<UnremovableBeanBuildItem> unremovableBeans) {
void logCleanupFilters(BuildProducer<LogCleanupFilterBuildItem> logCleanupFilters) {
logCleanupFilters.produce(new LogCleanupFilterBuildItem("com.arjuna.ats.jbossatx", "ARJUNA032010:", "ARJUNA032013:"));
}

private void allowUnsafeMultipleLastResources(NarayanaJtaRecorder recorder,
TransactionManagerBuildTimeConfig transactionManagerBuildTimeConfig,
Capabilities capabilities, BuildProducer<LogCleanupFilterBuildItem> logCleanupFilters,
BuildProducer<NativeImageFeatureBuildItem> nativeImageFeatures) {
switch (transactionManagerBuildTimeConfig.unsafeMultipleLastResources
.orElse(UnsafeMultipleLastResourcesMode.DEFAULT)) {
case ALLOW -> {
recorder.allowUnsafeMultipleLastResources(capabilities.isPresent(Capability.AGROAL), true);
// we will handle the warnings ourselves at runtime init when the option is set explicitly
logCleanupFilters.produce(
new LogCleanupFilterBuildItem("com.arjuna.ats.arjuna", "ARJUNA012139", "ARJUNA012141", "ARJUNA012142"));
}
case WARN_FIRST -> {
recorder.allowUnsafeMultipleLastResources(capabilities.isPresent(Capability.AGROAL), true);
// we will handle the warnings ourselves at runtime init when the option is set explicitly
// but we still want Narayana to produce a warning on the first offending transaction
logCleanupFilters.produce(
new LogCleanupFilterBuildItem("com.arjuna.ats.arjuna", "ARJUNA012139", "ARJUNA012142"));
}
case WARN_EACH -> {
recorder.allowUnsafeMultipleLastResources(capabilities.isPresent(Capability.AGROAL), false);
// we will handle the warnings ourselves at runtime init when the option is set explicitly
// but we still want Narayana to produce one warning per offending transaction
logCleanupFilters.produce(
new LogCleanupFilterBuildItem("com.arjuna.ats.arjuna", "ARJUNA012139", "ARJUNA012142"));
}
case FAIL -> { // No need to do anything, this is the default behavior of Narayana
}
}
}
}

0 comments on commit a18c9d7

Please sign in to comment.