欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

atomikos 使用说明

程序员文章站 2022-05-23 11:29:52
...

atomikos 使用说明

 

**********************************

引入jar包

 

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jta-atomikos</artifactId>
    <version>2.2.2.RELEASE</version>
</dependency>

 

**********************************

自动配置类

 

JtaAutoConfiguration:jta自动配置类

@Configuration(
    proxyBeanMethods = false
)
@ConditionalOnClass({Transaction.class})
@ConditionalOnProperty(
    prefix = "spring.jta",
    value = {"enabled"},
    matchIfMissing = true
)
@AutoConfigureBefore({XADataSourceAutoConfiguration.class, ActiveMQAutoConfiguration.class, ArtemisAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
@Import({JndiJtaConfiguration.class, BitronixJtaConfiguration.class, AtomikosJtaConfiguration.class})
public class JtaAutoConfiguration {
    public JtaAutoConfiguration() {
    }
}

 

AtomikosJtaConfiguration:atomikos自动配置类

@Configuration(
    proxyBeanMethods = false
)
@EnableConfigurationProperties({AtomikosProperties.class, JtaProperties.class})
@ConditionalOnClass({JtaTransactionManager.class, UserTransactionManager.class})
@ConditionalOnMissingBean({PlatformTransactionManager.class})
class AtomikosJtaConfiguration {
    AtomikosJtaConfiguration() {
    }

    @Bean(
        initMethod = "init",
        destroyMethod = "close"
    )
    @ConditionalOnMissingBean({TransactionManager.class})
    UserTransactionManager atomikosTransactionManager(UserTransactionService userTransactionService) throws Exception {
        UserTransactionManager manager = new UserTransactionManager();
        manager.setStartupTransactionService(false);
        manager.setForceShutdown(true);
        return manager;
    }//transactionmanager不存在则创建userTransactionManager实例

    @Bean
    JtaTransactionManager transactionManager(UserTransaction userTransaction, TransactionManager transactionManager, ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) {
        JtaTransactionManager jtaTransactionManager = new JtaTransactionManager(userTransaction, transactionManager);
        transactionManagerCustomizers.ifAvailable((customizers) -> {
            customizers.customize(jtaTransactionManager);
        });
        return jtaTransactionManager;
    }//platformTransactionManager实例不存在则创建jtaTransactionManager实例

    。。。。
}

 

**********************************

配置类

 

AtomikosProperties:atomikos属性配置参数

@ConfigurationProperties(
    prefix = "spring.jta.atomikos.properties"
)
public class AtomikosProperties {
    private String service;
    private Duration maxTimeout = Duration.ofMillis(300000L);
    private Duration defaultJtaTimeout = Duration.ofMillis(10000L);
    private int maxActives = 50;
    private boolean enableLogging = true;
    private String transactionManagerUniqueName;
    private boolean serialJtaTransactions = true;
    private boolean allowSubTransactions = true;
    private boolean forceShutdownOnVmExit;
    private long defaultMaxWaitTimeOnShutdown = 9223372036854775807L;
    private String logBaseName = "tmlog";
    private String logBaseDir;
    private long checkpointInterval = 500L;
    private boolean threadedTwoPhaseCommit;
    private final AtomikosProperties.Recovery recovery = new AtomikosProperties.Recovery();

    public AtomikosProperties() {
    }

 

AtomikosDataSourceBean :数据源配置参数

@ConfigurationProperties(
    prefix = "spring.jta.atomikos.datasource"
)
public class AtomikosDataSourceBean extends com.atomikos.jdbc.AtomikosDataSourceBean implements BeanNameAware, InitializingBean, DisposableBean {


public class AtomikosDataSourceBean extends AbstractDataSourceBean {


***********************************
基础类AbstractDataSourceBean


public abstract class AbstractDataSourceBean implements DataSource, ConnectionPoolProperties, Referenceable, Serializable {
    private static final Logger LOGGER = LoggerFactory.createLogger(AbstractDataSourceBean.class);
    static final int DEFAULT_ISOLATION_LEVEL_UNSET = -1;
    private static final int DEFAULT_POOL_SIZE = 1;
    private int minPoolSize = 1;
    private int maxPoolSize = 1;
    private int borrowConnectionTimeout = 30;
    private int reapTimeout = 0;
    private int maxIdleTime = 60;
    private String testQuery;
    private int maintenanceInterval = 60;
    private int loginTimeout;
    private transient ConnectionPool connectionPool;
    private transient PrintWriter logWriter;
    private String resourceName;
    private int defaultIsolationLevel = -1;
    private int maxLifetime;
    private boolean enableConcurrentConnectionValidation = true;

 

AtomikosConnectionFactoryBean:连接工厂配置参数

@ConfigurationProperties(
    prefix = "spring.jta.atomikos.connectionfactory"
)
public class AtomikosConnectionFactoryBean extends com.atomikos.jms.AtomikosConnectionFactoryBean implements BeanNameAware, InitializingBean, DisposableBean {
    private String beanName;

    public AtomikosConnectionFactoryBean() {
    }

****************************************
AtomikosConnectionFactoryBean:基础类

public class AtomikosConnectionFactoryBean implements ConnectionFactory, ConnectionPoolProperties, Referenceable, Serializable {
    private static final Logger LOGGER = LoggerFactory.createLogger(AtomikosConnectionFactoryBean.class);
    private static final long serialVersionUID = 1L;
    private String uniqueResourceName;
    private int maxPoolSize = 1;
    private int minPoolSize = 1;
    private String xaConnectionFactoryClassName;
    private int borrowConnectionTimeout = 30;
    private Properties xaProperties = null;
    private transient ConnectionPool connectionPool;
    private transient XAConnectionFactory xaConnectionFactory;
    private int maintenanceInterval = 60;
    private int maxIdleTime = 60;
    private int reapTimeout = 0;
    private boolean localTransactionMode;
    private int maxLifetime;
    private boolean ignoreSessionTransactedFlag = true;

    public AtomikosConnectionFactoryBean() {
        this.xaProperties = new Properties();
    }