Search in sources :

Example 11 with UNKNOWN

use of org.omg.CORBA.UNKNOWN in project narayana by jbosstm.

the class ArjunaTransactionImple method rollback.

public void rollback() throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::rollback for " + get_uid());
    }
    if (ArjunaTransactionImple._checkedTransactions && !checkAccess()) {
        throw new NO_PERMISSION(0, CompletionStatus.COMPLETED_NO);
    }
    int status = super.status();
    if ((status == ActionStatus.RUNNING) || // already aborted?
    (status == ActionStatus.ABORT_ONLY)) {
        if (ArjunaTransactionImple._syncOn) {
            if (TxControl.isBeforeCompletionWhenRollbackOnly()) {
                try {
                    if (_synchs != null)
                        doBeforeCompletion();
                } catch (Exception e) {
                /*
                           * Don't do anything - we're about to rollback anyway!
                           */
                }
            }
        } else {
            /*
                     * If we have any synchronizations delete them now. Can only be
                     * a top-level action.
                     */
            _synchs = null;
        }
        if (parentTransaction != null) {
            parentTransaction.removeChildAction(this);
        }
        super.Abort();
        if (ArjunaTransactionImple._syncOn) {
            try {
                if (_synchs != null) {
                    currentStatus = determineStatus(this);
                    doAfterCompletion(currentStatus);
                }
            } catch (Exception e) {
            }
        }
        destroyAction();
        status = super.status();
    } else if ((status == ActionStatus.ABORTING) || (status == ActionStatus.ABORTED) || (status == ActionStatus.H_ROLLBACK)) {
        if (jtsLogger.logger.isInfoEnabled()) {
            jtsLogger.i18NLogger.info_rollback_aborted_transaction(get_transaction_name());
        }
        return;
    } else {
        // means
        throw new INVALID_TRANSACTION(0, CompletionStatus.COMPLETED_NO);
    // transaction
    // already
    // terminated.
    }
    switch(status) {
        case ActionStatus.ABORTING:
        case ActionStatus.ABORTED:
        case ActionStatus.H_ROLLBACK:
            /*
			 * If the transaction has already rolledback then silently ignore
			 * the multiple rollback attempts.
			 */
            return;
        // shouldn't be able to get heuristics or
        case ActionStatus.PREPARING:
        // any of these!
        case ActionStatus.PREPARED:
        case ActionStatus.COMMITTING:
        case ActionStatus.COMMITTED:
        case ActionStatus.H_COMMIT:
        case ActionStatus.H_MIXED:
        case ActionStatus.H_HAZARD:
            // means
            throw new INVALID_TRANSACTION(0, CompletionStatus.COMPLETED_NO);
        // terminated.
        case ActionStatus.INVALID:
        case ActionStatus.CLEANUP:
            throw new UNKNOWN(ExceptionCodes.UNKNOWN_EXCEPTION, CompletionStatus.COMPLETED_MAYBE);
    }
}
Also used : NO_PERMISSION(org.omg.CORBA.NO_PERMISSION) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) UNKNOWN(org.omg.CORBA.UNKNOWN) SystemException(org.omg.CORBA.SystemException)

Example 12 with UNKNOWN

use of org.omg.CORBA.UNKNOWN in project narayana by jbosstm.

the class ArjunaTransactionImple method doBeforeCompletion.

protected void doBeforeCompletion() throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::doBeforeCompletion for " + get_uid());
    }
    boolean problem = false;
    SystemException exp = null;
    /*
	     * If we have a synchronization list then we must be top-level.
	     */
    if (_synchs != null) {
        boolean doSuspend = false;
        ControlWrapper cw = null;
        try {
            try {
                // cw = OTSImpleManager.systemCurrent().getControlWrapper();
                cw = OTSImpleManager.current().getControlWrapper();
                if ((cw == null) || (!controlHandle.equals(cw.getImple()))) {
                    // OTSImpleManager.systemCurrent().resumeImple(controlHandle);
                    OTSImpleManager.current().resumeImple(controlHandle);
                    doSuspend = true;
                }
            } catch (Exception ex) {
            /*
	                 * It should be OK to continue with the invocations even if
	                 * we couldn't resume, because a Synchronization is only
	                 * supposed to be associated with a single transaction. So,
	                 * it should be able to infer the transaction.
	                 */
            }
            /*
	             * Since Synchronizations may add register other Synchronizations, we can't simply
	             * iterate the collection. Instead we work from an ordered copy, which we periodically
	             * check for freshness. The addSynchronization method uses _currentRecord to disallow
	             * adding records in the part of the array we have already traversed, thus all
	             * Synchronization will be called and the (jta only) rules on ordering of interposed
	             * Synchronization will be respected.
	             */
            int lastIndexProcessed = -1;
            SynchronizationRecord[] copiedSynchs = (SynchronizationRecord[]) _synchs.toArray(new SynchronizationRecord[] {});
            while ((lastIndexProcessed < _synchs.size() - 1) && !problem) {
                // if new Synchronization have been registered, refresh our copy of the collection:
                if (copiedSynchs.length != _synchs.size()) {
                    copiedSynchs = (SynchronizationRecord[]) _synchs.toArray(new SynchronizationRecord[] {});
                }
                lastIndexProcessed = lastIndexProcessed + 1;
                _currentRecord = copiedSynchs[lastIndexProcessed];
                Synchronization c = _currentRecord.contents();
                c.before_completion();
            }
        } catch (SystemException e) {
            jtsLogger.i18NLogger.warn_orbspecific_coordinator_generror("ArjunaTransactionImple.doBeforeCompletion", e);
            if (!problem) {
                exp = e;
                problem = true;
                try {
                    rollback_only();
                } catch (Inactive ex) {
                    /*
	                     * This should not happen. If it does, continue with
	                     * commit to tidy-up.
	                     */
                    jtsLogger.i18NLogger.warn_orbspecific_coordinator_rbofail("ArjunaTransactionImple.doBeforeCompletion", get_uid(), ex);
                }
            }
        } finally {
            if (doSuspend) {
                try {
                    if (cw != null)
                        OTSImpleManager.current().resumeWrapper(cw);
                    else
                        OTSImpleManager.current().suspend();
                } catch (Exception ex) {
                }
            // OTSImpleManager.systemCurrent().suspend();
            }
        }
    }
    if (!problem)
        problem = !super.beforeCompletion();
    if (problem) {
        if (exp != null)
            throw exp;
        else
            throw new UNKNOWN(ExceptionCodes.SYNCHRONIZATION_EXCEPTION, CompletionStatus.COMPLETED_NO);
    }
}
Also used : SystemException(org.omg.CORBA.SystemException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) Inactive(org.omg.CosTransactions.Inactive) UNKNOWN(org.omg.CORBA.UNKNOWN) Synchronization(org.omg.CosTransactions.Synchronization) ManagedSynchronization(com.arjuna.ArjunaOTS.ManagedSynchronization) SystemException(org.omg.CORBA.SystemException) SynchronizationRecord(com.arjuna.ats.internal.jts.resources.SynchronizationRecord)

Example 13 with UNKNOWN

use of org.omg.CORBA.UNKNOWN in project narayana by jbosstm.

the class ExtendedResourceRecord method resourceHandle.

/**
 * Specific OTS method for getting at the value.
 */
public final ArjunaSubtranAwareResource resourceHandle() {
    if ((_resourceHandle == null) && (_stringifiedResourceHandle != null)) {
        try {
            org.omg.CORBA.ORB theOrb = ORBManager.getORB().orb();
            if (theOrb == null)
                throw new UNKNOWN();
            if (jtsLogger.logger.isTraceEnabled()) {
                jtsLogger.logger.trace("ExtendedResourceRecord: About to string_to_object on " + _stringifiedResourceHandle);
            }
            org.omg.CORBA.Object optr = theOrb.string_to_object(_stringifiedResourceHandle);
            if (jtsLogger.logger.isTraceEnabled()) {
                jtsLogger.logger.trace("ExtendedResourceRecord: Successfully stringed to object, next try to narrow");
            }
            theOrb = null;
            // This is needed because for JDK ORB it could narrow and won't allow shutdown of OA
            _resourceHandle = com.arjuna.ArjunaOTS.ArjunaSubtranAwareResourceHelper.narrow(optr);
            if (jtsLogger.logger.isTraceEnabled()) {
                jtsLogger.logger.trace("ExtendedResourceRecord: Successfully narrowed");
            }
            if (_resourceHandle == null)
                throw new BAD_PARAM();
            else {
                optr = null;
            }
        } catch (SystemException e) {
            if (jtsLogger.logger.isTraceEnabled()) {
                jtsLogger.logger.trace("ExtendedResourceRecord: Failed to narrow to ArjunaSubtranAwareResource");
            }
        }
    }
    return _resourceHandle;
}
Also used : SystemException(org.omg.CORBA.SystemException) BAD_PARAM(org.omg.CORBA.BAD_PARAM) UNKNOWN(org.omg.CORBA.UNKNOWN)

Example 14 with UNKNOWN

use of org.omg.CORBA.UNKNOWN in project narayana by jbosstm.

the class XAResourceRecord method handleForget.

private void handleForget() throws org.omg.CORBA.SystemException {
    if ((_theXAResource != null) && (_tranID != null)) {
        try {
            _theXAResource.forget(_tranID);
            _heuristic = TwoPhaseOutcome.FINISH_OK;
            _forgotten = true;
        } catch (Exception e) {
            jtaLogger.i18NLogger.warn_recovery_forgetfailed("XAResourceRecord forget failed:", e);
            // log will be rewritten
            throw new UNKNOWN(e.getMessage());
        }
    }
}
Also used : UNKNOWN(org.omg.CORBA.UNKNOWN) SystemException(org.omg.CORBA.SystemException) XAException(javax.transaction.xa.XAException) NotSerializableException(java.io.NotSerializableException)

Example 15 with UNKNOWN

use of org.omg.CORBA.UNKNOWN in project narayana by jbosstm.

the class XAResourceRecord method commit.

public void commit() throws org.omg.CORBA.SystemException, NotPrepared, HeuristicRollback, HeuristicMixed, HeuristicHazard {
    if (jtaxLogger.logger.isTraceEnabled()) {
        jtaxLogger.logger.trace("XAResourceRecord.commit for " + _tranID);
    }
    if (_tranID == null) {
        jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_nulltransaction("XAResourceRecord.commit");
    } else {
        if ((_theXAResource != null) && (!_committed)) {
            switch(_heuristic) {
                case TwoPhaseOutcome.HEURISTIC_HAZARD:
                    throw new org.omg.CosTransactions.HeuristicHazard();
                case TwoPhaseOutcome.HEURISTIC_MIXED:
                    throw new org.omg.CosTransactions.HeuristicMixed();
                case TwoPhaseOutcome.HEURISTIC_ROLLBACK:
                    throw new org.omg.CosTransactions.HeuristicRollback();
                default:
                    break;
            }
            if (!_prepared)
                throw new NotPrepared();
            boolean removeConnection = true;
            try {
                if (!_committed) {
                    _committed = true;
                    _theXAResource.commit(_tranID, false);
                    destroyState();
                }
            } catch (XAException e1) {
                if (notAProblem(e1, true)) {
                    // some other thread got there first (probably)
                    destroyState();
                } else {
                    _committed = false;
                    jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_xaerror("XAResourceRecord.commit", XAHelper.printXAErrorCode(e1), _theXAResource.toString(), XAHelper.xidToString(_tranID), e1);
                    if (jtaxLogger.logger.isTraceEnabled()) {
                        jtaxLogger.logger.tracef("XAResourceRecord.commit exception %s " + "resource_trace: txn uid=%s resource uid=%s\n", XAHelper.printXAErrorCode(e1), _tranID, get_uid());
                    }
                    switch(e1.errorCode) {
                        case XAException.XA_HEURHAZ:
                            updateState(TwoPhaseOutcome.HEURISTIC_HAZARD);
                            throw new org.omg.CosTransactions.HeuristicHazard();
                        case // what about forget? OTS doesn't support this code here.
                        XAException.XA_HEURCOM:
                            destroyState();
                            break;
                        case XAException.XA_HEURRB:
                        case XAException.XA_RBROLLBACK:
                        case XAException.XA_RBCOMMFAIL:
                        case XAException.XA_RBDEADLOCK:
                        case XAException.XA_RBINTEGRITY:
                        case XAException.XA_RBOTHER:
                        case XAException.XA_RBPROTO:
                        case XAException.XA_RBTIMEOUT:
                        case XAException.XA_RBTRANSIENT:
                        case XAException.XAER_RMERR:
                            updateState(TwoPhaseOutcome.HEURISTIC_ROLLBACK);
                            throw new org.omg.CosTransactions.HeuristicRollback();
                        case XAException.XA_HEURMIX:
                            updateState(TwoPhaseOutcome.HEURISTIC_MIXED);
                            throw new org.omg.CosTransactions.HeuristicMixed();
                        case XAException.XAER_NOTA:
                            if (// committed previously on participant
                            _phaseTwoStarted)
                                break;
                            // RM unexpectedly lost track of the tx, outcome is uncertain
                            updateState(TwoPhaseOutcome.HEURISTIC_HAZARD);
                            throw new org.omg.CosTransactions.HeuristicHazard();
                        case XAException.XAER_PROTO:
                            // presumed abort (or we could be really paranoid and throw a heuristic)
                            throw new TRANSACTION_ROLLEDBACK();
                        case XAException.XA_RETRY:
                        case XAException.XAER_RMFAIL:
                            removeConnection = false;
                            // Since JBTM-2710 this is not right because it will mean that commit is not reattempted _committed = true;  // remember for recovery later.
                            throw // will cause log to be rewritten.
                            new UNKNOWN();
                        // resource manager failed, did it rollback?
                        case XAException.XAER_INVAL:
                        default:
                            throw new org.omg.CosTransactions.HeuristicHazard();
                    }
                }
            } catch (Exception e2) {
                _committed = false;
                jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_generror("XAResourceRecord.commit", _theXAResource.toString(), XAHelper.xidToString(_tranID), e2);
                throw new UNKNOWN();
            } finally {
                _phaseTwoStarted = true;
                if (removeConnection) {
                    removeConnection();
                }
            }
        }
    }
}
Also used : XAException(javax.transaction.xa.XAException) HeuristicRollback(org.omg.CosTransactions.HeuristicRollback) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) NotPrepared(org.omg.CosTransactions.NotPrepared) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) SystemException(org.omg.CORBA.SystemException) XAException(javax.transaction.xa.XAException) NotSerializableException(java.io.NotSerializableException) HeuristicRollback(org.omg.CosTransactions.HeuristicRollback) UNKNOWN(org.omg.CORBA.UNKNOWN) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK)

Aggregations

UNKNOWN (org.omg.CORBA.UNKNOWN)51 SystemException (org.omg.CORBA.SystemException)32 BAD_PARAM (org.omg.CORBA.BAD_PARAM)27 Coordinator (org.omg.CosTransactions.Coordinator)15 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)14 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)13 BadParametersException (com.cosylab.acs.maci.BadParametersException)13 CoreException (com.cosylab.acs.maci.CoreException)13 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)13 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)12 Unavailable (org.omg.CosTransactions.Unavailable)11 Any (org.omg.CORBA.Any)9 Object (org.omg.CORBA.Object)8 URI (java.net.URI)7 URISyntaxException (java.net.URISyntaxException)7 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)6 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)6 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)6 TRANSACTION_REQUIRED (org.omg.CORBA.TRANSACTION_REQUIRED)6 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)6