Search in sources :

Example 1 with ServerTransaction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction in project narayana by jbosstm.

the class ServerTopLevelAction method prepare.

/*
 * Will only be called by the remote top-level transaction.
 */
public org.omg.CosTransactions.Vote prepare() throws HeuristicMixed, HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::prepare for " + _theUid);
    }
    if (_theControl == null) {
        throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
    }
    if (_theControl.isWrapper()) {
        // won't necessarily get another invocation!
        destroyResource();
        return Vote.VoteReadOnly;
    }
    ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
    // ThreadActionData.pushAction(theTransaction); // LockManager needs to know if there is a transaction
    int result = TwoPhaseOutcome.PREPARE_NOTOK;
    /*
	 * Transaction may have locally timed out and been rolled back.
	 */
    int s = theTransaction.status();
    if ((s == ActionStatus.RUNNING) || (s == ActionStatus.ABORT_ONLY))
        result = theTransaction.doPrepare();
    else {
        switch(s) {
            case ActionStatus.COMMITTING:
            case ActionStatus.COMMITTED:
            case ActionStatus.H_COMMIT:
                result = TwoPhaseOutcome.PREPARE_OK;
                break;
            case ActionStatus.H_MIXED:
                result = TwoPhaseOutcome.HEURISTIC_MIXED;
                break;
            case ActionStatus.H_HAZARD:
                result = TwoPhaseOutcome.HEURISTIC_HAZARD;
                break;
        }
    }
    ThreadActionData.popAction();
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::prepare for " + _theUid + " : " + TwoPhaseOutcome.stringForm(result));
    }
    if (result == TwoPhaseOutcome.PREPARE_NOTOK) {
        try {
            rollback();
        } catch (HeuristicCommit ex1) {
            result = TwoPhaseOutcome.HEURISTIC_COMMIT;
        } catch (HeuristicMixed ex2) {
            result = TwoPhaseOutcome.HEURISTIC_MIXED;
        } catch (HeuristicHazard ex3) {
            result = TwoPhaseOutcome.HEURISTIC_HAZARD;
        } catch (SystemException ex4) {
            result = TwoPhaseOutcome.HEURISTIC_HAZARD;
        }
    }
    switch(result) {
        case TwoPhaseOutcome.INVALID_TRANSACTION:
            throw new INVALID_TRANSACTION(ExceptionCodes.INVALID_ACTION, CompletionStatus.COMPLETED_NO);
        case TwoPhaseOutcome.PREPARE_OK:
            return Vote.VoteCommit;
        case TwoPhaseOutcome.PREPARE_NOTOK:
            // won't necessarily get another invocation!
            destroyResource();
            return Vote.VoteRollback;
        case TwoPhaseOutcome.PREPARE_READONLY:
            // won't necessarily get another invocation!
            destroyResource();
            return Vote.VoteReadOnly;
        case TwoPhaseOutcome.HEURISTIC_MIXED:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            // will eventually get forget
            throw new HeuristicMixed();
        case TwoPhaseOutcome.HEURISTIC_HAZARD:
        default:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            throw new HeuristicHazard();
    }
}
Also used : SystemException(org.omg.CORBA.SystemException) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) HeuristicCommit(org.omg.CosTransactions.HeuristicCommit) ServerTransaction(com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard)

Example 2 with ServerTransaction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction in project narayana by jbosstm.

the class ServerTopLevelAction method rollback.

public void rollback() throws HeuristicCommit, HeuristicMixed, HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::rollback for " + _theUid);
    }
    if (_theControl == null) {
        throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
    }
    if (_theControl.isWrapper()) {
        destroyResource();
        return;
    }
    ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
    // LockManager needs to know if there is a transaction
    ThreadActionData.pushAction(theTransaction);
    int actionStatus = theTransaction.status();
    if (actionStatus == ActionStatus.PREPARED) {
        /*
	     * This will also call any after_completions on
	     * registered synchronizations.
	     */
        actionStatus = theTransaction.doPhase2Abort();
    } else {
        if ((actionStatus == ActionStatus.RUNNING) || (actionStatus == ActionStatus.ABORT_ONLY)) {
            try {
                if (!valid())
                    // must rollback
                    theTransaction.doPhase2Abort();
                else
                    theTransaction.rollback();
                actionStatus = ActionStatus.ABORTED;
            } catch (SystemException ex) {
                actionStatus = ActionStatus.ABORTED;
                throw ex;
            } finally {
                destroyResource();
            }
        }
    }
    ThreadActionData.popAction();
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::rollback for " + _theUid + " : " + ActionStatus.stringForm(actionStatus));
    }
    switch(actionStatus) {
        case ActionStatus.PREPARED:
            throw new INVALID_TRANSACTION(ExceptionCodes.INVALID_ACTION, CompletionStatus.COMPLETED_NO);
        case ActionStatus.ABORTED:
        case ActionStatus.H_ROLLBACK:
            destroyResource();
            break;
        case ActionStatus.COMMITTED:
        case ActionStatus.H_COMMIT:
            destroyResource();
            throw new HeuristicCommit();
        case ActionStatus.H_MIXED:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            throw new HeuristicMixed();
        case ActionStatus.H_HAZARD:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            throw new HeuristicHazard();
        default:
            destroyResource();
            break;
    }
}
Also used : SystemException(org.omg.CORBA.SystemException) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) HeuristicCommit(org.omg.CosTransactions.HeuristicCommit) ServerTransaction(com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard)

Example 3 with ServerTransaction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction in project narayana by jbosstm.

the class ServerTopLevelAction method commit.

public void commit() throws NotPrepared, HeuristicRollback, HeuristicMixed, HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::commit for " + _theUid);
    }
    if (_theControl == null) {
        throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
    }
    if (_theControl.isWrapper()) {
        destroyResource();
        return;
    }
    ServerTransaction theTransaction = (ServerTransaction) _theControl.getImplHandle();
    // LockManager needs to know if there is a transaction
    ThreadActionData.pushAction(theTransaction);
    int actionStatus = theTransaction.status();
    boolean notPrepared = false;
    if (actionStatus == ActionStatus.PREPARED) {
        /*
	     * This will also call any after_completions on
	     * registered synchronizations.
	     */
        actionStatus = theTransaction.doPhase2Commit();
    } else {
        if (actionStatus == ActionStatus.RUNNING) {
            if (jtsLogger.logger.isTraceEnabled()) {
                jtsLogger.logger.trace("ServerTopLevelAction::commit for " + _theUid + " : NotPrepared");
            }
            notPrepared = true;
        }
    }
    ThreadActionData.popAction();
    if (notPrepared)
        throw new NotPrepared();
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ServerTopLevelAction::commit for " + _theUid + " : " + ActionStatus.stringForm(actionStatus));
    }
    switch(actionStatus) {
        case ActionStatus.PREPARED:
            throw new INVALID_TRANSACTION(ExceptionCodes.SERVERAA_NO_CONTROL, CompletionStatus.COMPLETED_NO);
        case ActionStatus.COMMITTED:
        case ActionStatus.H_COMMIT:
            destroyResource();
            break;
        case ActionStatus.ABORTED:
        case ActionStatus.H_ROLLBACK:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            throw new HeuristicRollback();
        case ActionStatus.H_MIXED:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            throw new HeuristicMixed();
        case ActionStatus.H_HAZARD:
            if (TxControl.getMaintainHeuristics())
                destroyResource();
            throw new HeuristicHazard();
        default:
            destroyResource();
            break;
    }
}
Also used : HeuristicRollback(org.omg.CosTransactions.HeuristicRollback) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) ServerTransaction(com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) NotPrepared(org.omg.CosTransactions.NotPrepared) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard)

Example 4 with ServerTransaction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction in project narayana by jbosstm.

the class GenericRecoveryCreator method create.

/**
 * Create a new RecoveryCoordinator for Resource res. The params
 * array is used to pass additional data. Currently params[0] is
 * the ArjunaTransactionImple ref. When create returns additional data is
 * passed back using params. Currently returned params[0] is the
 * RecoveryCoordinator Uid.
 */
public RecoveryCoordinator create(Resource res, Object[] params) throws SystemException {
    RecoveryCoordinator recoveryCoordinator = null;
    if (jtsLogger.logger.isDebugEnabled()) {
        jtsLogger.logger.debug("GenericRecoveryCreator.create()");
    }
    // we dont use the res parameter in this version
    if ((params != null) && (params[0] != null)) {
        int index = 0;
        ArjunaTransactionImple otsTransaction = (ArjunaTransactionImple) params[index++];
        // Get the Uid of the top-level transaction. This will be
        // the top-level interposed transaction in the case of
        // interposition.
        BasicAction rootAction = otsTransaction;
        while ((rootAction.parent()) != null) rootAction = rootAction.parent();
        Uid rootActionUid = rootAction.getSavingUid();
        // Uid processUid = Utility.getProcessUid();
        Uid processUid = com.arjuna.ats.arjuna.utils.Utility.getProcessUid();
        // Create a Uid for the new RecoveryCoordinator
        Uid RCUid = new Uid();
        // Is this transaction a ServerTransaction?
        boolean isServerTransaction = (otsTransaction instanceof ServerTransaction);
        // Now ask the orb-specific bit to make the RecoveryCoordinator IOR
        // (it may or may not actually make the RC itself)
        recoveryCoordinator = _orbSpecificManager.makeRC(RCUid, rootActionUid, processUid, isServerTransaction);
        // Tidy up
        otsTransaction = null;
        rootAction = null;
        // Pass the RecoveryCoordinator Uid back
        params[0] = RCUid;
    } else {
        jtsLogger.i18NLogger.warn_recovery_recoverycoordinators_GenericRecoveryCreator_1();
    }
    return recoveryCoordinator;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) ServerTransaction(com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction)

Example 5 with ServerTransaction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction in project narayana by jbosstm.

the class SubordinateAtomicTransaction method doCommit.

/**
 * @return ActionStatus
 * @throws SystemException
 */
public int doCommit() throws SystemException {
    ServerTransaction stx = getTransaction();
    int outcome = ActionStatus.INVALID;
    try {
        if (stx != null)
            return stx.doPhase2Commit();
    } catch (final Exception ex) {
        ex.printStackTrace();
    }
    return ActionStatus.H_HAZARD;
}
Also used : ServerTransaction(com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction) SystemException(org.omg.CORBA.SystemException)

Aggregations

ServerTransaction (com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction)17 Uid (com.arjuna.ats.arjuna.common.Uid)8 SystemException (org.omg.CORBA.SystemException)8 Test (org.junit.Test)7 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)7 HeuristicHazard (org.omg.CosTransactions.HeuristicHazard)5 HeuristicMixed (org.omg.CosTransactions.HeuristicMixed)4 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)3 UNKNOWN (org.omg.CORBA.UNKNOWN)3 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)2 HeuristicCommit (org.omg.CosTransactions.HeuristicCommit)2 RecoveryCoordinator (org.omg.CosTransactions.RecoveryCoordinator)2 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)1 ServerSynchronization (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.ServerSynchronization)1 AssumedCompleteHeuristicServerTransaction (com.arjuna.ats.internal.jts.recovery.transactions.AssumedCompleteHeuristicServerTransaction)1 com.hp.mwtests.ts.jts.orbspecific.resources.demosync (com.hp.mwtests.ts.jts.orbspecific.resources.demosync)1 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)1 HeuristicRollback (org.omg.CosTransactions.HeuristicRollback)1