Skip to content

Commit

Permalink
Set the transaction node name at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Feb 12, 2019
1 parent 44f96a3 commit 799ef38
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.jboss.shamrock.narayana.jta;

import static org.jboss.shamrock.deployment.annotations.ExecutionTime.RUNTIME_INIT;
import static org.jboss.shamrock.deployment.annotations.ExecutionTime.STATIC_INIT;

import java.util.Properties;
Expand Down Expand Up @@ -64,7 +65,7 @@ class NarayanaJtaProcessor {
NarayanaJtaConfiguration transactions;

@BuildStep(providesCapabilities = Capabilities.TRANSACTIONS)
@Record(STATIC_INIT)
@Record(RUNTIME_INIT)
public void build(NarayanaJtaTemplate tt, BuildProducer<FeatureBuildItem> feature) {
feature.produce(new FeatureBuildItem(FeatureBuildItem.NARAYANA_JTA));
additionalBeans.produce(new AdditionalBeanBuildItem(NarayanaJtaProducers.class));
Expand All @@ -85,7 +86,7 @@ public void build(NarayanaJtaTemplate tt, BuildProducer<FeatureBuildItem> featur
//we want to force Arjuna to init at static init time
Properties defaultProperties = PropertiesFactory.getDefaultProperties();
tt.setDefaultProperties(defaultProperties);
tt.initialize(transactions);
tt.setNodeName(transactions);

}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package org.jboss.shamrock.narayana.jta.runtime;

import java.util.Optional;

import org.jboss.shamrock.runtime.annotations.ConfigItem;
import org.jboss.shamrock.runtime.annotations.ConfigPhase;
import org.jboss.shamrock.runtime.annotations.ConfigRoot;

/**
*
*/
@ConfigRoot(phase = ConfigPhase.RUN_TIME_STATIC)
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public final class NarayanaJtaConfiguration {
/**
* The node name used by the transaction manager
*/
@ConfigItem(defaultValue = "shamrock")
public String nodeName;

/**
* The XA node name used by the transaction manager
*/
@ConfigItem()
public Optional<String> xaNodeName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public class NarayanaJtaTemplate {

private static final Logger log = Logger.getLogger(NarayanaJtaTemplate.class);

public void setNodeName(String name) {
public void setNodeName(final NarayanaJtaConfiguration transactions) {

try {
arjPropertyManager.getCoreEnvironmentBean().setNodeIdentifier(name);
TxControl.setXANodeName("shamrock");
arjPropertyManager.getCoreEnvironmentBean().setNodeIdentifier(transactions.nodeName);
TxControl.setXANodeName(transactions.xaNodeName.orElse(transactions.nodeName));
} catch (CoreEnvironmentBeanException e) {
e.printStackTrace();
}
Expand All @@ -62,8 +62,4 @@ public void setDefaultProperties(Properties properties) {
public static Properties getDefaultProperties() {
return defaultProperties;
}

public void initialize(final NarayanaJtaConfiguration transactions) {
setNodeName(transactions.nodeName);
}
}

0 comments on commit 799ef38

Please sign in to comment.