use of com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple in project narayana by jbosstm.
the class XATerminatorImple method doRecover.
/**
* Return a list of indoubt transactions. This may include those
* transactions that are currently in-flight and running 2PC and do not need
* recovery invoked on them.
*
* @param nodeName
* Only recover transactions for this node (unless set to NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES)
* @throws XAException
* thrown if any error occurs.
* @return a list of potentially indoubt transactions or <code>null</code>.
*/
public Xid[] doRecover(Xid xid, String parentNodeName) throws XAException {
/*
* Requires going through the objectstore for the states of imported
* transactions. Our own crash recovery takes care of transactions
* imported via CORBA, Web Services etc.
*/
Xid[] indoubt = null;
try {
RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
InputObjectState states = new InputObjectState();
if (recoveryStore.allObjUids(SubordinateAtomicAction.getType(), states) && (states.notempty())) {
Stack<Xid> values = new Stack<Xid>();
boolean finished = false;
do {
Uid uid = null;
try {
uid = UidHelper.unpackFrom(states);
} catch (IOException ex) {
ex.printStackTrace();
finished = true;
}
if (uid.notEquals(Uid.nullUid())) {
if (parentNodeName != null) {
SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
XidImple loadedXid = (XidImple) saa.getXid();
if (loadedXid != null && loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
String loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
if ((loadedXidSubordinateNodeName == null && loadedXidSubordinateNodeName == TxControl.getXANodeName()) || loadedXidSubordinateNodeName.equals(TxControl.getXANodeName())) {
if (parentNodeName.equals(saa.getParentNodeName())) {
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("Found record for " + saa);
}
// TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
values.push(loadedXid);
}
}
}
} else if (xid == null) {
TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
if (tx != null)
values.push(tx.baseXid());
} else {
SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
XidImple loadedXid = (XidImple) saa.getXid();
if (loadedXid != null && loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
String loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
if (XATxConverter.getSubordinateNodeName(new XidImple(xid).getXID()).equals(loadedXidSubordinateNodeName)) {
if (Arrays.equals(loadedXid.getGlobalTransactionId(), xid.getGlobalTransactionId())) {
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("Found record for " + saa);
}
TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
values.push(loadedXid);
}
}
}
}
} else
finished = true;
} while (!finished);
if (values.size() > 0) {
int index = 0;
indoubt = new Xid[values.size()];
while (!values.empty()) {
indoubt[index] = values.pop();
index++;
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return indoubt;
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple in project narayana by jbosstm.
the class TransactionImporterImple method getInflightXids.
public Set<Xid> getInflightXids(String parentNodeName) {
Iterator<AtomicReference<TransactionImple>> iterator = _transactions.values().iterator();
Set<Xid> toReturn = new HashSet<Xid>();
while (iterator.hasNext()) {
AtomicReference<TransactionImple> holder = iterator.next();
TransactionImple imported = holder.get();
if (imported != null && imported.getParentNodeName().equals(parentNodeName)) {
toReturn.add(imported.baseXid());
}
}
return toReturn;
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple in project narayana by jbosstm.
the class TransactionImporterImple method removeImportedTransaction.
/**
* Remove the subordinate (imported) transaction.
*
* @param xid
* the global transaction.
*
* @throws javax.transaction.xa.XAException
* thrown if there are any errors.
*/
public void removeImportedTransaction(Xid xid) throws XAException {
if (xid == null)
throw new IllegalArgumentException();
AtomicReference<TransactionImple> remove = _transactions.remove(new SubordinateXidImple(xid));
if (remove != null) {
synchronized (remove) {
TransactionImple transactionImple = remove.get();
while (transactionImple == null) {
try {
remove.wait();
transactionImple = remove.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new XAException(XAException.XAER_RMFAIL);
}
}
TransactionImple.removeTransaction(transactionImple);
}
}
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple in project narayana by jbosstm.
the class XARecoveryModuleUnitTest method testRecover.
@Test
public void testRecover() throws Exception {
ArrayList<String> r = new ArrayList<String>();
TransactionImple tx = new TransactionImple(0);
assertTrue(tx.enlistResource(new RecoveryXAResource()));
assertEquals(tx.doPrepare(), TwoPhaseOutcome.PREPARE_OK);
r.add("com.hp.mwtests.ts.jta.recovery.DummyXARecoveryResource");
jtaPropertyManager.getJTAEnvironmentBean().setXaResourceRecoveryClassNames(r);
XARecoveryModule xarm = new XARecoveryModule();
assertNull(xarm.getNewXAResource(new XAResourceRecord(null, null, new XidImple(), null)));
for (int i = 0; i < 11; i++) {
xarm.periodicWorkFirstPass();
xarm.periodicWorkSecondPass();
}
assertTrue(xarm.getNewXAResource(new XAResourceRecord(null, null, new XidImple(new Uid()), null)) == null);
assertNull(xarm.getNewXAResource(new XAResourceRecord(null, null, new XidImple(), null)));
}
Aggregations