Search in sources :

Example 1 with TransactionSynchronizationRegistryWrapper

use of org.jboss.as.txn.service.internal.tsr.TransactionSynchronizationRegistryWrapper in project wildfly by wildfly.

the class TestWildFlyTSR method test.

@Test
public void test() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
    jtaPropertyManager.getJTAEnvironmentBean().setTransactionManagerClassName("com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple");
    final TransactionSynchronizationRegistry tsr = new TransactionSynchronizationRegistryWrapper(new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple());
    TransactionManager transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
    transactionManager.begin();
    tsr.registerInterposedSynchronization(new Synchronization() {

        @Override
        public void beforeCompletion() {
            tsr.registerInterposedSynchronization(new Synchronization() {

                @Override
                public void beforeCompletion() {
                    innerSyncCalled = true;
                }

                @Override
                public void afterCompletion(int status) {
                }
            });
        }

        @Override
        public void afterCompletion(int status) {
        }
    });
    transactionManager.commit();
    assertTrue(innerSyncCalled);
}
Also used : TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) TransactionManager(javax.transaction.TransactionManager) Synchronization(javax.transaction.Synchronization) TransactionSynchronizationRegistryWrapper(org.jboss.as.txn.service.internal.tsr.TransactionSynchronizationRegistryWrapper) Test(org.junit.Test)

Example 2 with TransactionSynchronizationRegistryWrapper

use of org.jboss.as.txn.service.internal.tsr.TransactionSynchronizationRegistryWrapper in project wildfly by wildfly.

the class ArjunaTransactionManagerService method start.

@Override
public synchronized void start(final StartContext context) throws StartException {
    final CoordinatorEnvironmentBean coordinatorEnvironmentBean = arjPropertyManager.getCoordinatorEnvironmentBean();
    coordinatorEnvironmentBean.setEnableStatistics(coordinatorEnableStatistics);
    coordinatorEnvironmentBean.setDefaultTimeout(coordinatorDefaultTimeout);
    coordinatorEnvironmentBean.setTransactionStatusManagerEnable(transactionStatusManagerEnable);
    // Object Store Browser bean
    Map<String, String> objStoreBrowserTypes = new HashMap<String, String>();
    objStoreBrowser = new ObjStoreBrowser();
    objStoreBrowserTypes.put("StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction", "com.arjuna.ats.internal.jta.tools.osb.mbean.jta.JTAActionBean");
    objStoreBrowserTypes.put("StateManager/AbstractRecord/ConnectableResourceRecord", "com.arjuna.ats.internal.jta.tools.osb.mbean.jta.ConnectableResourceRecordBean");
    if (!jts) {
        // No IIOP, stick with JTA mode.
        jtaEnvironmentBean.getValue().setTransactionManagerClassName(com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate.class.getName());
        final com.arjuna.ats.jbossatx.jta.TransactionManagerService service = new com.arjuna.ats.jbossatx.jta.TransactionManagerService();
        final LocalUserTransaction userTransaction = LocalUserTransaction.getInstance();
        jtaEnvironmentBean.getValue().setUserTransaction(userTransaction);
        service.setJbossXATerminator(xaTerminatorInjector.getValue());
        service.setTransactionSynchronizationRegistry(new TransactionSynchronizationRegistryWrapper(ContextTransactionSynchronizationRegistry.getInstance()));
        try {
            service.create();
        } catch (Exception e) {
            throw TransactionLogger.ROOT_LOGGER.managerStartFailure(e, "Transaction");
        }
        service.start();
        value = service;
    } else {
        final ORB orb = orbInjector.getValue();
        new PostInitLoader(PostInitLoader.generateORBPropertyName("com.arjuna.orbportability.orb"), orb);
        // IIOP is enabled, so fire up JTS mode.
        jtaEnvironmentBean.getValue().setTransactionManagerClassName(com.arjuna.ats.jbossatx.jts.TransactionManagerDelegate.class.getName());
        final com.arjuna.ats.jbossatx.jts.TransactionManagerService service = new com.arjuna.ats.jbossatx.jts.TransactionManagerService();
        final LocalUserTransaction userTransaction = LocalUserTransaction.getInstance();
        jtaEnvironmentBean.getValue().setUserTransaction(userTransaction);
        service.setJbossXATerminator(xaTerminatorInjector.getValue());
        service.setTransactionSynchronizationRegistry(new TransactionSynchronizationRegistryWrapper(ContextTransactionSynchronizationRegistry.getInstance()));
        service.setPropagateFullContext(true);
        // this is not great, but it's the only way presently to influence the behavior of com.arjuna.ats.internal.jbossatx.jts.InboundTransactionCurrentImple
        try {
            final Field field = TransactionManagerLocator.class.getDeclaredField("tm");
            field.setAccessible(true);
            field.set(TransactionManagerLocator.getInstance(), jtaEnvironmentBean.getValue().getTransactionManager());
        } catch (IllegalAccessException e) {
            throw new IllegalAccessError(e.getMessage());
        } catch (NoSuchFieldException e) {
            throw new NoSuchFieldError(e.getMessage());
        }
        objStoreBrowserTypes.put("StateManager/BasicAction/TwoPhaseCoordinator/ArjunaTransactionImple", "com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean");
        try {
            service.create();
        } catch (Exception e) {
            throw TransactionLogger.ROOT_LOGGER.createFailed(e);
        }
        try {
            service.start(orb);
        } catch (Exception e) {
            throw TransactionLogger.ROOT_LOGGER.startFailure(e);
        }
        value = service;
    }
    try {
        objStoreBrowser.start();
    } catch (Exception e) {
        throw TransactionLogger.ROOT_LOGGER.objectStoreStartFailure(e);
    }
}
Also used : HashMap(java.util.HashMap) ObjStoreBrowser(com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser) TransactionSynchronizationRegistryWrapper(org.jboss.as.txn.service.internal.tsr.TransactionSynchronizationRegistryWrapper) Field(java.lang.reflect.Field) LocalUserTransaction(org.wildfly.transaction.client.LocalUserTransaction) CoordinatorEnvironmentBean(com.arjuna.ats.arjuna.common.CoordinatorEnvironmentBean) PostInitLoader(com.arjuna.orbportability.internal.utils.PostInitLoader) StartException(org.jboss.msc.service.StartException) ORB(org.omg.CORBA.ORB)

Aggregations

TransactionSynchronizationRegistryWrapper (org.jboss.as.txn.service.internal.tsr.TransactionSynchronizationRegistryWrapper)2 CoordinatorEnvironmentBean (com.arjuna.ats.arjuna.common.CoordinatorEnvironmentBean)1 ObjStoreBrowser (com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser)1 PostInitLoader (com.arjuna.orbportability.internal.utils.PostInitLoader)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 Synchronization (javax.transaction.Synchronization)1 TransactionManager (javax.transaction.TransactionManager)1 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)1 StartException (org.jboss.msc.service.StartException)1 Test (org.junit.Test)1 ORB (org.omg.CORBA.ORB)1 LocalUserTransaction (org.wildfly.transaction.client.LocalUserTransaction)1