Search in sources :

Example 11 with RecoveryModule

use of com.arjuna.ats.arjuna.recovery.RecoveryModule in project narayana by jbosstm.

the class XAResourceRecord method getNewXAResource.

/**
 * This routine finds the new XAResource for the transaction that used the
 * old resource we couldn't serialize. It does this by looking up the
 * XARecoveryModule in the recovery manager and asking it for the
 * XAResource. The recovery manager will then look through its list of
 * registered XARecoveryResource implementations for the appropriate
 * instance. If the XARecoveryModule hasn't been initialised yet then this
 * routine will fail, but on the next scan it should work.
 */
private final XAResource getNewXAResource() {
    RecoveryManager recMan = RecoveryManager.manager();
    Vector recoveryModules = recMan.getModules();
    if (recoveryModules != null) {
        Enumeration modules = recoveryModules.elements();
        while (modules.hasMoreElements()) {
            RecoveryModule m = (RecoveryModule) modules.nextElement();
            if (m instanceof XARecoveryModule) {
                return ((XARecoveryModule) m).getNewXAResource(this);
            }
        }
    }
    return null;
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) Enumeration(java.util.Enumeration) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) Vector(java.util.Vector) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)

Example 12 with RecoveryModule

use of com.arjuna.ats.arjuna.recovery.RecoveryModule in project narayana by jbosstm.

the class UnserializableSerializableXAResourceTest method test.

@Test
public void test() throws Exception {
    XAResource res1 = new XAResource() {

        @Override
        public void start(Xid xid, int flags) throws XAException {
        // TODO Auto-generated method stub
        }

        @Override
        public void end(Xid xid, int flags) throws XAException {
        // TODO Auto-generated method stub
        }

        @Override
        public int prepare(Xid xid) throws XAException {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public void commit(Xid xid, boolean onePhase) throws XAException {
        // TODO Auto-generated method stub
        }

        @Override
        public void rollback(Xid xid) throws XAException {
        // TODO Auto-generated method stub
        }

        @Override
        public void forget(Xid xid) throws XAException {
        // TODO Auto-generated method stub
        }

        @Override
        public Xid[] recover(int flag) throws XAException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public boolean isSameRM(XAResource xaRes) throws XAException {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public int getTransactionTimeout() throws XAException {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public boolean setTransactionTimeout(int seconds) throws XAException {
            // TODO Auto-generated method stub
            return false;
        }
    };
    UnserializableSerializableXAResource res2 = new UnserializableSerializableXAResource(true);
    final javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    tm.getStatus();
    tm.begin();
    javax.transaction.Transaction theTransaction = tm.getTransaction();
    assertTrue(theTransaction.enlistResource(res1));
    assertTrue(theTransaction.enlistResource(res2));
    tm.commit();
    XARecoveryModule xaRecoveryModule = null;
    for (RecoveryModule recoveryModule : ((Vector<RecoveryModule>) recoveryManager.getModules())) {
        if (recoveryModule instanceof XARecoveryModule) {
            xaRecoveryModule = (XARecoveryModule) recoveryModule;
            break;
        }
    }
    final Xid xid = res2.getXid();
    xaRecoveryModule.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

        @Override
        public boolean initialise(String p) throws Exception {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public XAResource[] getXAResources() throws Exception {
            return new XAResource[] { new XAResource() {

                @Override
                public void start(Xid xid, int flags) throws XAException {
                // TODO Auto-generated method stub
                }

                @Override
                public void end(Xid xid, int flags) throws XAException {
                // TODO Auto-generated method stub
                }

                @Override
                public int prepare(Xid xid) throws XAException {
                    // TODO Auto-generated method stub
                    return 0;
                }

                @Override
                public void commit(Xid xid, boolean onePhase) throws XAException {
                    committed = true;
                }

                @Override
                public void rollback(Xid xid) throws XAException {
                // TODO Auto-generated method stub
                }

                @Override
                public void forget(Xid xid) throws XAException {
                // TODO Auto-generated method stub
                }

                @Override
                public Xid[] recover(int flag) throws XAException {
                    if (committed) {
                        return null;
                    } else {
                        return new Xid[] { xid };
                    }
                }

                @Override
                public boolean isSameRM(XAResource xaRes) throws XAException {
                    // TODO Auto-generated method stub
                    return false;
                }

                @Override
                public int getTransactionTimeout() throws XAException {
                    // TODO Auto-generated method stub
                    return 0;
                }

                @Override
                public boolean setTransactionTimeout(int seconds) throws XAException {
                    // TODO Auto-generated method stub
                    return false;
                }
            } };
        }
    });
    recoveryManager.scan();
    assertTrue(committed);
}
Also used : XAException(javax.transaction.xa.XAException) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) SystemException(org.omg.CORBA.SystemException) XAException(javax.transaction.xa.XAException) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule) Test(org.junit.Test)

Example 13 with RecoveryModule

use of com.arjuna.ats.arjuna.recovery.RecoveryModule in project wildfly by wildfly.

the class InboundBridgeService method addDeserializerAndOrphanFilter.

private void addDeserializerAndOrphanFilter() {
    final RecoveryManager recoveryManager = RecoveryManager.manager();
    for (RecoveryModule recoveryModule : recoveryManager.getModules()) {
        if (recoveryModule instanceof XARecoveryModule) {
            orphanFilter = new InboundBridgeOrphanFilter();
            ((XARecoveryModule) recoveryModule).addXAResourceOrphanFilter(orphanFilter);
            ((XARecoveryModule) recoveryModule).addSerializableXAResourceDeserializer(new InboundBridge());
        }
    }
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) InboundBridge(org.jboss.narayana.rest.bridge.inbound.InboundBridge) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) InboundBridgeRecoveryModule(org.jboss.narayana.rest.bridge.inbound.InboundBridgeRecoveryModule) InboundBridgeOrphanFilter(org.jboss.narayana.rest.bridge.inbound.InboundBridgeOrphanFilter) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)

Example 14 with RecoveryModule

use of com.arjuna.ats.arjuna.recovery.RecoveryModule in project narayana by jbosstm.

the class XAResourceRecord method getXAResourceDeserializers.

private List<SerializableXAResourceDeserializer> getXAResourceDeserializers() {
    if (serializableXAResourceDeserializers != null) {
        return serializableXAResourceDeserializers;
    }
    synchronized (this) {
        if (serializableXAResourceDeserializers != null) {
            return serializableXAResourceDeserializers;
        }
        serializableXAResourceDeserializers = new ArrayList<SerializableXAResourceDeserializer>();
        for (RecoveryModule recoveryModule : RecoveryManager.manager().getModules()) {
            if (recoveryModule instanceof XARecoveryModule) {
                XARecoveryModule xaRecoveryModule = (XARecoveryModule) recoveryModule;
                serializableXAResourceDeserializers.addAll(xaRecoveryModule.getSeriablizableXAResourceDeserializers());
                return serializableXAResourceDeserializers;
            }
        }
    }
    return serializableXAResourceDeserializers;
}
Also used : SerializableXAResourceDeserializer(com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)

Example 15 with RecoveryModule

use of com.arjuna.ats.arjuna.recovery.RecoveryModule in project narayana by jbosstm.

the class TestCommitMarkableResourceFailAfterCommitTwoXAResources method doTest.

protected void doTest(final DataSource dataSource) throws Exception {
    // Test code
    Utils.createTables(dataSource.getConnection());
    // We can't just instantiate one as we need to be using the
    // same one as
    // the transaction
    // manager would have used to mark the transaction for GC
    CommitMarkableResourceRecordRecoveryModule recoveryModule = null;
    Vector recoveryModules = manager.getModules();
    if (recoveryModules != null) {
        Enumeration modules = recoveryModules.elements();
        while (modules.hasMoreElements()) {
            RecoveryModule m = (RecoveryModule) modules.nextElement();
            if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
                recoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
            } else if (m instanceof XARecoveryModule) {
                XARecoveryModule xarm = (XARecoveryModule) m;
                xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

                    public boolean initialise(String p) throws Exception {
                        return true;
                    }

                    public XAResource[] getXAResources() throws Exception {
                        return new XAResource[] { xaResource };
                    }
                });
            }
        }
    }
    // final Object o = new Object();
    // synchronized (o) {
    Thread foo = new Thread(new Runnable() {

        public void run() {
            try {
                javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
                tm.begin();
                Connection localJDBCConnection = dataSource.getConnection();
                localJDBCConnection.setAutoCommit(false);
                nonXAResource = new JDBCConnectableResource(localJDBCConnection);
                tm.getTransaction().enlistResource(nonXAResource);
                xaResource = new SimpleXAResource();
                tm.getTransaction().enlistResource(xaResource);
                xaResource2 = new SimpleXAResource2();
                tm.getTransaction().enlistResource(xaResource2);
                localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
                tm.commit();
            } catch (ExecuteException t) {
            } catch (Exception e) {
                e.printStackTrace();
                failed = true;
            } catch (Error e) {
            }
        }
    });
    foo.start();
    foo.join();
    assertFalse(failed);
    Xid committed = ((JDBCConnectableResource) nonXAResource).getStartedXid();
    assertNotNull(committed);
    // The recovery module has to perform lookups
    new InitialContext().rebind("commitmarkableresource", dataSource);
    // Check if the item is still in the db
    recoveryModule.periodicWorkFirstPass();
    assertTrue(recoveryModule.wasCommitted("commitmarkableresource", committed));
    recoveryModule.periodicWorkSecondPass();
    // Now we need to correctly complete the transaction
    manager.scan();
    // Make sure the item is no longer in the DB, it will need two scans as
    // second phase of the CommitMarkableResourceRecoveryModule will have
    // executed before the AtomicActionRecoveryModule has been able to GC
    // it
    assertTrue(recoveryModule.wasCommitted("commitmarkableresource", committed));
    recoveryModule.periodicWorkFirstPass();
    recoveryModule.periodicWorkSecondPass();
    assertFalse(recoveryModule.wasCommitted("commitmarkableresource", committed));
    assertTrue(xaResource.wasCommitted());
    assertFalse(xaResource.wasRolledback());
    assertTrue(xaResource2.commitCalled());
    assertFalse(xaResource2.rollbackCalled());
}
Also used : Enumeration(java.util.Enumeration) Connection(java.sql.Connection) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) ExecuteException(org.jboss.byteman.rule.exception.ExecuteException) InitialContext(javax.naming.InitialContext) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) ExecuteException(org.jboss.byteman.rule.exception.ExecuteException) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) Vector(java.util.Vector) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)

Aggregations

RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)27 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)18 Enumeration (java.util.Enumeration)14 Vector (java.util.Vector)14 XAResource (javax.transaction.xa.XAResource)14 Test (org.junit.Test)12 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)11 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)11 Connection (java.sql.Connection)10 Xid (javax.transaction.xa.Xid)10 InitialContext (javax.naming.InitialContext)9 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)7 ExecuteException (org.jboss.byteman.rule.exception.ExecuteException)6 Uid (com.arjuna.ats.arjuna.common.Uid)5 RecoveryManager (com.arjuna.ats.arjuna.recovery.RecoveryManager)5 XAException (javax.transaction.xa.XAException)5 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)4 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)3 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)3 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule)3