use of com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple in project narayana by jbosstm.
the class XATerminatorImple method doRecover.
/**
* <p>
* Recovering /JCA section of object store.
* The filtering functionality on xid or parentNodeName is not permitted and throws {@link NotSupportedException}.<br>
* Expected to be called only with null parameters <code>doRecover(null, null)</code>
*
* @param xid has to be null
* @param parentNodeName has to be null
* @return array of subordinate recovered xids
* @throws XAException if recovery operation fails for the XA protocol reason
* @throws NotSupportedException if not null params are passes as method parameters
*/
@Override
public Xid[] doRecover(Xid xid, String parentNodeName) throws XAException, NotSupportedException {
if (xid != null || parentNodeName != null)
throw new NotSupportedException("doRecover method works only with null arguments");
Xid[] indoubt = null;
try {
RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
InputObjectState states = new InputObjectState();
// only look in the JCA section of the object store
if (recoveryStore.allObjUids(ServerTransaction.getType(), states) && (states.notempty())) {
Stack<Transaction> values = new Stack<Transaction>();
boolean finished = false;
do {
Uid uid = null;
try {
uid = UidHelper.unpackFrom(states);
} catch (IOException ex) {
jtsLogger.i18NLogger.info_fail_to_read_subordinate_uid(recoveryStore, states, ex);
finished = true;
}
if (uid.notEquals(Uid.nullUid())) {
Transaction tx = SubordinationManager.getTransactionImporter().recoverTransaction(uid);
if (tx != null)
values.push(tx);
} else
finished = true;
} while (!finished);
if (values.size() > 0) {
int index = 0;
indoubt = new Xid[values.size()];
while (!values.empty()) {
TransactionImple id = (TransactionImple) values.pop();
indoubt[index] = id.baseXid();
index++;
}
}
}
} catch (Exception ex) {
jtsLogger.i18NLogger.info_fail_to_dorecover(xid, parentNodeName, ex);
}
return indoubt;
}
use of com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple in project narayana by jbosstm.
the class TransactionImporterImple method removeImportedTransaction.
/**
* Remove the subordinate (imported) transaction.
*
* @param xid the global transaction.
*
* @throws XAException thrown if there are any errors.
*/
public void removeImportedTransaction(Xid xid) throws XAException {
if (xid == null)
throw new IllegalArgumentException();
AtomicReference<SubordinateTransaction> remove = _transactions.remove(new SubordinateXidImple(xid));
if (remove != null) {
synchronized (remove) {
com.arjuna.ats.internal.jta.transaction.jts.TransactionImple transactionImple = (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) remove.get();
while (transactionImple == null) {
try {
remove.wait();
transactionImple = (com.arjuna.ats.internal.jta.transaction.jts.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.jts.subordinate.jca.TransactionImple in project narayana by jbosstm.
the class SubordinateTxUnitTest method testTransactionImple.
@Test
public void testTransactionImple() throws Exception {
TransactionImple tx = new TransactionImple(new Uid());
TransactionImple dummy = new TransactionImple(new Uid());
tx.recordTransaction();
assertFalse(tx.equals(dummy));
assertTrue(tx.toString() != null);
tx.recover();
}
use of com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple in project narayana by jbosstm.
the class TransactionImpleUnitTest method test.
@Test
public void test() throws Exception {
TransactionImple tx = new TransactionImple(0);
tx.recordTransaction();
assertFalse(tx.equals(null));
assertTrue(tx.equals(tx));
assertFalse(tx.equals(new TransactionImple(0)));
assertTrue(tx.toString() != null);
assertTrue(tx.baseXid() != null);
tx.recover();
assertTrue(tx.activated());
}
use of com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple in project narayana by jbosstm.
the class TransactionImporterImple method addImportedTransaction.
/**
* This can be used for newly imported transactions or recovered ones.
*
* @param recoveredTransaction If this is recovery
* @param xid if this is import
* @param timeout
* @return
*/
private TransactionImportResult addImportedTransaction(TransactionImple recoveredTransaction, Xid mapKey, Xid xid, int timeout) {
boolean isNew = false;
SubordinateXidImple importedXid = new SubordinateXidImple(mapKey);
// We need to store the imported transaction in a volatile field holder so that it can be shared between threads
AtomicReference<SubordinateTransaction> holder = new AtomicReference<>();
AtomicReference<SubordinateTransaction> existing;
if ((existing = _transactions.putIfAbsent(importedXid, holder)) != null) {
holder = existing;
}
SubordinateTransaction txn = holder.get();
// Should only be called by the recovery system - this will replace the Transaction with one from disk
if (recoveredTransaction != null) {
synchronized (holder) {
// now it's safe to add the imported transaction to the holder
recoveredTransaction.recordTransaction();
txn = recoveredTransaction;
holder.set(txn);
holder.notifyAll();
}
}
if (txn == null) {
// a volatile so can be concurrently accessed by multiple threads
synchronized (holder) {
txn = holder.get();
if (txn == null) {
txn = new TransactionImple(timeout, xid);
holder.set(txn);
holder.notifyAll();
isNew = true;
}
}
}
return new TransactionImportResult(txn, isNew);
}
Aggregations