Search in sources :

Example 11 with TxInfo

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;
    }
}
Also used : XAException(javax.transaction.xa.XAException) TxInfo(com.arjuna.ats.internal.jta.xa.TxInfo) InactiveTransactionException(com.arjuna.ats.jta.exceptions.InactiveTransactionException) RollbackException(javax.transaction.RollbackException) InvalidTerminationStateException(com.arjuna.ats.jta.exceptions.InvalidTerminationStateException) XAException(javax.transaction.xa.XAException) HeuristicMixedException(javax.transaction.HeuristicMixedException)

Aggregations

TxInfo (com.arjuna.ats.internal.jta.xa.TxInfo)11 XAException (javax.transaction.xa.XAException)10 InactiveTransactionException (com.arjuna.ats.jta.exceptions.InactiveTransactionException)8 InvalidTerminationStateException (com.arjuna.ats.jta.exceptions.InvalidTerminationStateException)8 RollbackException (javax.transaction.RollbackException)8 Enumeration (java.util.Enumeration)6 XAResource (javax.transaction.xa.XAResource)6 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)4 IOException (java.io.IOException)4 HeuristicMixedException (javax.transaction.HeuristicMixedException)4 SystemException (javax.transaction.SystemException)4 XAModifier (com.arjuna.ats.jta.xa.XAModifier)2 Xid (javax.transaction.xa.Xid)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)1 XAResourceRecord (com.arjuna.ats.internal.jta.resources.jts.orbspecific.XAResourceRecord)1 XidImple (com.arjuna.ats.jta.xa.XidImple)1 Test (org.junit.Test)1 UNKNOWN (org.omg.CORBA.UNKNOWN)1 RecoveryCoordinator (org.omg.CosTransactions.RecoveryCoordinator)1