use of com.arjuna.ats.internal.jta.xa.TxInfo in project narayana by jbosstm.
the class TransactionImple method delistResource.
/*
* Do we have to unregister resources? Assume not as it would not make much
* sense otherwise!
*/
public boolean delistResource(XAResource xaRes, int flags) throws IllegalStateException, javax.transaction.SystemException {
if (jtaxLogger.logger.isTraceEnabled()) {
jtaxLogger.logger.trace("TransactionImple.delistResource ( " + xaRes + ", " + flags + " )");
}
if (xaRes == null)
throw new javax.transaction.SystemException("TransactionImple.delistResource - " + jtaxLogger.i18NLogger.get_jtax_transaction_jts_nullparam());
int status = getStatus();
switch(status) {
case javax.transaction.Status.STATUS_ACTIVE:
break;
case javax.transaction.Status.STATUS_MARKED_ROLLBACK:
break;
default:
throw new IllegalStateException(jtaxLogger.i18NLogger.get_jtax_transaction_jts_inactivetx());
}
TxInfo info = null;
try {
synchronized (this) {
info = (TxInfo) _resources.get(xaRes);
if (info == null)
info = (TxInfo) _duplicateResources.get(xaRes);
}
if (info == null) {
jtaxLogger.i18NLogger.warn_jtax_transaction_jts_unknownres("TransactionImple.delistResource");
return false;
} else {
boolean optimizedRollback = false;
try {
if (status == javax.transaction.Status.STATUS_MARKED_ROLLBACK) {
if (XAUtils.canOptimizeDelist(xaRes)) {
xaRes.end(info.xid(), XAResource.TMFAIL);
xaRes.rollback(info.xid());
info.setState(TxInfo.OPTIMIZED_ROLLBACK);
optimizedRollback = true;
}
}
} catch (Exception e) {
// failed, so try again when transaction does rollback
}
switch(info.getState()) {
case TxInfo.ASSOCIATED:
{
if ((flags & XAResource.TMSUCCESS) != 0) {
xaRes.end(info.xid(), XAResource.TMSUCCESS);
info.setState(TxInfo.NOT_ASSOCIATED);
} else {
if ((flags & XAResource.TMSUSPEND) != 0) {
xaRes.end(info.xid(), XAResource.TMSUSPEND);
info.setState(TxInfo.ASSOCIATION_SUSPENDED);
synchronized (this) {
_suspendCount++;
}
} else {
xaRes.end(info.xid(), XAResource.TMFAIL);
info.setState(TxInfo.FAILED);
}
}
}
break;
case TxInfo.ASSOCIATION_SUSPENDED:
{
if ((flags & XAResource.TMSUCCESS) != 0) {
if (XAUtils.mustEndSuspendedRMs(xaRes))
xaRes.start(info.xid(), XAResource.TMRESUME);
xaRes.end(info.xid(), XAResource.TMSUCCESS);
info.setState(TxInfo.NOT_ASSOCIATED);
synchronized (this) {
_suspendCount--;
}
} else {
if ((flags & XAResource.TMSUSPEND) != 0) {
throw new IllegalStateException("TransactionImple.delistResource - " + jtaxLogger.i18NLogger.get_jtax_transaction_jts_ressusp());
} else {
xaRes.end(info.xid(), XAResource.TMFAIL);
info.setState(TxInfo.FAILED);
synchronized (this) {
_suspendCount--;
}
}
}
}
break;
default:
if (!optimizedRollback)
throw new IllegalStateException("TransactionImple.delistResource - " + jtaxLogger.i18NLogger.get_jtax_transaction_jts_illegalstate() + info.getState());
}
info = null;
return true;
}
} catch (IllegalStateException ex) {
throw ex;
} catch (XAException exp) {
if (info != null)
info.setState(TxInfo.FAILED);
/*
* For safety mark the transaction as rollback only.
*/
markRollbackOnly();
jtaxLogger.i18NLogger.warn_jtax_transaction_jts_xaerror("TransactionImple.delistResource", XAHelper.printXAErrorCode(exp), exp);
return false;
} catch (Exception e) {
jtaxLogger.i18NLogger.warn_jtax_transaction_jts_delistfailed(e);
/*
* Some exception occurred and we probably could not delist the
* resource. So, for safety mark the transaction as rollback only.
*/
markRollbackOnly();
return false;
}
}
Aggregations