use of com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction in project narayana by jbosstm.
the class InboundBridgeRecoveryModule method getUidsToRecover.
/**
* Returns UIDs of JTA subordinate transactions with format id specified in inbound bridge class which were found in
* transaction log.
*
* @return Set<Uid>
*/
private Set<Uid> getUidsToRecover() {
if (LOG.isTraceEnabled()) {
LOG.trace("InboundBridgeRecoveryModule.getUidsToRecover");
}
final Set<Uid> uids = new HashSet<Uid>();
try {
final RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
final InputObjectState states = new InputObjectState();
// Only look in the JCA section of the object store
if (recoveryStore.allObjUids(SubordinateAtomicAction.getType(), states) && states.notempty()) {
boolean finished = false;
do {
final Uid uid = UidHelper.unpackFrom(states);
if (uid.notEquals(Uid.nullUid())) {
final SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
if (saa.getXid().getFormatId() == InboundBridge.XARESOURCE_FORMAT_ID) {
uids.add(uid);
}
} else {
finished = true;
}
} while (!finished);
}
} catch (Exception e) {
LOG.warn(e.getMessage(), e);
}
return uids;
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction in project narayana by jbosstm.
the class SubordinateTxUnitTest method testSAADeferred.
@Test
public void testSAADeferred() throws Exception {
SubordinateAtomicAction saa = new SubordinateAtomicAction();
saa.add(new XAResourceRecord(null, new XAResource() {
@Override
public void commit(Xid xid, boolean b) throws XAException {
}
@Override
public void end(Xid xid, int i) throws XAException {
}
@Override
public void forget(Xid xid) throws XAException {
}
@Override
public int getTransactionTimeout() throws XAException {
return 0;
}
@Override
public boolean isSameRM(XAResource xaResource) throws XAException {
return false;
}
@Override
public int prepare(Xid xid) throws XAException {
XAException xae = new XAException(XAException.XAER_INVAL);
xae.initCause(new Throwable("test message"));
throw xae;
}
@Override
public Xid[] recover(int i) throws XAException {
return new Xid[0];
}
@Override
public void rollback(Xid xid) throws XAException {
}
@Override
public boolean setTransactionTimeout(int i) throws XAException {
return false;
}
@Override
public void start(Xid xid, int i) throws XAException {
}
}, new XidImple(new Xid() {
@Override
public int getFormatId() {
return 0;
}
@Override
public byte[] getGlobalTransactionId() {
return new byte[0];
}
@Override
public byte[] getBranchQualifier() {
return new byte[0];
}
}), null));
saa.doPrepare();
List<Throwable> deferredThrowables = saa.getDeferredThrowables();
assertEquals("test message", deferredThrowables.get(0).getCause().getMessage());
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction in project narayana by jbosstm.
the class SubordinateTxUnitTest method testSAA.
@Test
public void testSAA() throws Exception {
SubordinateAtomicAction saa = new SubordinateAtomicAction();
saa.add(new XAResourceRecord(null, new XAResource() {
@Override
public void commit(Xid xid, boolean b) throws XAException {
}
@Override
public void end(Xid xid, int i) throws XAException {
}
@Override
public void forget(Xid xid) throws XAException {
}
@Override
public int getTransactionTimeout() throws XAException {
return 0;
}
@Override
public boolean isSameRM(XAResource xaResource) throws XAException {
return false;
}
@Override
public int prepare(Xid xid) throws XAException {
return 0;
}
@Override
public Xid[] recover(int i) throws XAException {
return new Xid[0];
}
@Override
public void rollback(Xid xid) throws XAException {
}
@Override
public boolean setTransactionTimeout(int i) throws XAException {
return false;
}
@Override
public void start(Xid xid, int i) throws XAException {
}
}, new XidImple(new Xid() {
@Override
public int getFormatId() {
return 0;
}
@Override
public byte[] getGlobalTransactionId() {
return new byte[0];
}
@Override
public byte[] getBranchQualifier() {
return new byte[0];
}
}), null));
saa.doPrepare();
SubordinateAtomicAction saa2 = new SubordinateAtomicAction(saa.get_uid(), true);
assertTrue(saa2.getXid() != null);
saa.doCommit();
SubordinateAtomicAction saa3 = new SubordinateAtomicAction(saa.get_uid(), true);
// Since the SAA was committed the transaction log record will have been removed so the xid returned from getXid() should no longer be available and the intention is the SAA creator would disregard this instance
assertTrue(saa3.getXid() == null);
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction 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.SubordinateAtomicAction in project narayana by jbosstm.
the class SubordinateJTAXAResourceOrphanFilter method transactionLog.
/**
* Is there a log file for this transaction?
*
* @param recoveredResourceXid
* the transaction to check.
*
* @return <code>boolean</code>true if there is a log file,
* <code>false</code> if there isn't.
*/
private boolean transactionLog(Xid recoveredResourceXid, String recoveredResourceNodeName) {
XidImple theXid = new XidImple(recoveredResourceXid);
Uid u = theXid.getTransactionUid();
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("Checking whether Xid " + theXid + " exists in ObjectStore.");
}
if (!u.equals(Uid.nullUid())) {
RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
String transactionType = SubordinateAtomicAction.getType();
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("Looking for " + u + " and " + transactionType);
}
InputObjectState states = new InputObjectState();
try {
if (recoveryStore.allObjUids(transactionType, states) && (states.notempty())) {
Stack values = new Stack();
boolean finished = false;
do {
Uid uid = null;
try {
uid = UidHelper.unpackFrom(states);
} catch (IOException ex) {
ex.printStackTrace();
finished = true;
}
if (uid.notEquals(Uid.nullUid())) {
SubordinateAtomicAction tx = new SubordinateAtomicAction(uid, true);
XidImple transactionXid = (XidImple) tx.getXid();
if (transactionXid != null && transactionXid.isSameTransaction(recoveredResourceXid)) {
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("Found record for " + theXid);
}
return true;
}
} else
finished = true;
} while (!finished);
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("No record found for " + theXid);
}
} else {
jtaLogger.i18NLogger.info_recovery_notaxid(XAHelper.xidToString(recoveredResourceXid));
}
} catch (ObjectStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return false;
}
Aggregations