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;
}
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);
}
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());
}
}
}
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;
}
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());
}
Aggregations