use of javax.transaction.xa.XAException in project hazelcast by hazelcast.
the class XAResourceImpl method commit.
@Override
public void commit(Xid xid, boolean onePhase) throws XAException {
List<TransactionContext> contexts = xidContextMap.remove(xid);
if (contexts == null && onePhase) {
throw new XAException("There is no TransactionContexts for the given xid: " + xid);
}
if (contexts == null) {
finalizeTransactionRemotely(xid, true);
return;
}
for (TransactionContext context : contexts) {
Transaction transaction = getTransaction(context);
if (onePhase) {
transaction.prepare();
}
transaction.commit();
}
clearRemoteTransactions(xid);
}
use of javax.transaction.xa.XAException in project hazelcast by hazelcast.
the class XAResourceImpl method finalizeTransactionRemotely.
private void finalizeTransactionRemotely(Xid xid, boolean isCommit) throws XAException {
NodeEngine nodeEngine = getNodeEngine();
IPartitionService partitionService = nodeEngine.getPartitionService();
OperationService operationService = nodeEngine.getOperationService();
SerializableXID serializableXID = new SerializableXID(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier());
Data xidData = nodeEngine.toData(serializableXID);
int partitionId = partitionService.getPartitionId(xidData);
FinalizeRemoteTransactionOperation operation = new FinalizeRemoteTransactionOperation(xidData, isCommit);
InternalCompletableFuture<Integer> future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
Integer errorCode;
try {
errorCode = future.get();
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
if (errorCode != null) {
throw new XAException(errorCode);
}
}
use of javax.transaction.xa.XAException in project aries by apache.
the class NamedXAResourceImpl method handleException.
private XAException handleException(Exception e) throws XAException {
if (e instanceof XAException) {
XAException xae = (XAException) e;
if (xae.errorCode == 0) {
if (original) {
// We are the originally enlisted resource, and will play some tricks to attempt recovery
if (transactionManager.getNamedResource(name) == null) {
logger.error("The XA resource named {} threw an XAException but did not set the error code. There is also no RecoverableXAResource available with the name {}. It is not possible to recover from this situation and so the transaction will have to be resolved by an operator.", name, name, xae);
xae.errorCode = XAException.XAER_RMERR;
} else {
logger.warn("The XA resource named {} threw an XAException but did not set the error code. Changing it to be an \"RM_FAIL\" to permit recovery attempts", name, xae);
xae.errorCode = XAException.XAER_RMFAIL;
}
} else {
logger.warn("The XA resource named {} threw an XAException but did not set the error code. Recovery has already been attempted for this resource and it has not been possible to recover from this situation. The transaction will have to be resolved by an operator.", name, xae);
xae.errorCode = XAException.XAER_RMERR;
}
}
return xae;
} else {
logger.warn("The recoverable XA resource named {} threw an Exception which is not permitted by the interface. Changing it to be a \"Resource Manager Error\" XAException which prevents recovery", name, e);
XAException xaException = new XAException(XAException.XAER_RMERR);
xaException.initCause(e);
return xaException;
}
}
use of javax.transaction.xa.XAException in project aries by apache.
the class TransactionContextImpl method finish.
@Override
public void finish() {
if (!resources.isEmpty()) {
XAResource localResource = new LocalXAResourceImpl();
try {
currentTransaction.enlistResource(localResource);
} catch (Exception e) {
safeSetRollbackOnly();
recordFailure(e);
try {
localResource.rollback(null);
} catch (XAException e1) {
recordFailure(e1);
}
}
}
try {
TxListener listener = new TxListener();
try {
transactionManager.registerInterposedSynchronization(listener);
if (getRollbackOnly()) {
// GERONIMO-4449 says that we get no beforeCompletion
// callback for rollback :(
listener.beforeCompletion();
transactionManager.rollback();
} else {
transactionManager.commit();
}
} catch (Exception e) {
recordFailure(e);
}
} finally {
try {
transactionManager.resume(oldTran);
} catch (Exception e) {
recordFailure(e);
}
}
}
use of javax.transaction.xa.XAException in project geode by apache.
the class XAResourceAdaptor method testXAExceptionRollback.
@Test
public void testXAExceptionRollback() throws Exception {
utx.begin();
Thread thread = Thread.currentThread();
Transaction txn = (Transaction) tm.getTransactionMap().get(thread);
txn.registerSynchronization(new Synchronization() {
public void beforeCompletion() {
fail("Notify Before Completion should not be called in rollback");
}
public void afterCompletion(int status) {
assertTrue(status == Status.STATUS_ROLLEDBACK);
}
});
txn.enlistResource(new XAResourceAdaptor() {
public void commit(Xid arg0, boolean arg1) throws XAException {
}
public void rollback(Xid arg0) throws XAException {
throw new XAException(6);
}
});
try {
utx.rollback();
fail("The rollback should have thrown SystemException");
} catch (SystemException expected) {
// success
}
assertTrue(tm.getGlobalTransactionMap().isEmpty());
}
Aggregations