Search in sources :

Example 1 with Inactive

use of org.omg.CosTransactions.Inactive in project narayana by jbosstm.

the class ArjunaTransactionImple method register_resource.

/**
 * Resources are only registered with the current transaction, whereas
 * subtransaction aware resources are registered with their parents when the
 * current transaction ends.
 */
public RecoveryCoordinator register_resource(Resource r) throws SystemException, Inactive {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::register_resource ( " + r + " ) - called for " + get_uid());
    }
    if (r == null)
        throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
    currentStatus = determineStatus(this);
    if (currentStatus != Status.StatusActive) {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple::register_resource - transaction not active: " + Utility.stringStatus(currentStatus));
        }
        if (currentStatus == Status.StatusMarkedRollback) {
            throw new TRANSACTION_ROLLEDBACK(ExceptionCodes.MARKED_ROLLEDBACK, CompletionStatus.COMPLETED_NO);
        } else
            throw new Inactive();
    }
    AbstractRecord corbaRec = null;
    BasicAction registerIn = this;
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple " + get_uid() + " ::register_resource: ");
    }
    // 
    // Creation of recovery coordinator (DBI)
    // 
    // 
    // Pack the params:
    // [0] = Transaction* this
    // 
    int index = 0;
    Object[] params = new Object[10];
    params[index++] = this;
    RecoveryCoordinator recoveryCoordinator = null;
    Uid recoveryCoordinatorUid = null;
    try {
        recoveryCoordinator = RecoveryCreator.createRecoveryCoordinator(r, params);
        if (recoveryCoordinator == null)
            throw new BAD_OPERATION("RecoveryCoordinator " + jtsLogger.i18NLogger.get_orbspecific_coordinator_rcnotcreated());
    } catch (NO_IMPLEMENT ex) {
        /*
			 * This is legal, and is meant to show that this ORB or
			 * configuration simply doesn't support crash recovery.
			 */
        recoveryCoordinator = null;
    } catch (SystemException e) {
        jtsLogger.i18NLogger.warn_orbspecific_coordinator_rccreate(get_uid(), e);
        try {
            rollback_only();
        } catch (Inactive ex1) {
        } catch (SystemException ex2) {
            jtsLogger.i18NLogger.warn_orbspecific_coordinator_rbofail("ArjunaTransactionImple.register_resource", get_uid(), ex2);
            throw ex2;
        }
        throw e;
    }
    if (recoveryCoordinator != null) {
        // 
        // We got a RecoveryCoordinator, so unpack the other return values:
        // [0] = RecoveryCoordinator Uid*
        // 
        index = 0;
        recoveryCoordinatorUid = (Uid) params[index++];
    } else {
        // 
        // We didn't get a RecoveryCoordinator, so we don't assume that
        // the other return values have been populated.
        // 
        recoveryCoordinatorUid = Uid.nullUid();
    }
    try {
        SubtransactionAwareResource staResource = org.omg.CosTransactions.SubtransactionAwareResourceHelper.narrow(r);
        if (staResource != null) {
            if (jtsLogger.logger.isTraceEnabled()) {
                jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " - subtransaction aware resource: YES");
            }
            /*
				 * If here the narrow was ok so we have a subtran aware
				 * resource.
				 */
            Coordinator coord = null;
            if (parentHandle != null) {
                /*
					 * If we are a SubTranResource then we get registered with
					 * the current transaction and its parents upon completion.
					 * The first parameter to the record indicates whether we
					 * should be propagated (registered) with the parent
					 * transaction.
					 */
                coord = parentHandle.get_coordinator();
            }
            corbaRec = createOTSRecord(true, r, coord, recoveryCoordinatorUid);
            coord = null;
            staResource = null;
        } else
            throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
    } catch (BAD_PARAM ex) {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " - subtransaction aware resource: NO");
        }
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple " + get_uid() + " ::register_resource: Simple resource - " + ex);
        }
        corbaRec = createOTSRecord(true, r, null, recoveryCoordinatorUid);
    } catch (Unavailable e1) {
        throw new Inactive();
    } catch (SystemException e2) {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " : catch (SystemException) - " + e2);
        }
        throw e2;
    } catch (Exception e3) {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " : catch (...) - " + e3);
        }
        throw new UNKNOWN(e3.toString(), ExceptionCodes.UNKNOWN_EXCEPTION, CompletionStatus.COMPLETED_NO);
    }
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " : try end");
    }
    if (registerIn.add(corbaRec) != AddOutcome.AR_ADDED) {
        corbaRec = null;
        throw new INVALID_TRANSACTION(ExceptionCodes.ADD_FAILED, CompletionStatus.COMPLETED_NO);
    } else {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " : resource registered");
        }
    }
    return recoveryCoordinator;
}
Also used : NO_IMPLEMENT(org.omg.CORBA.NO_IMPLEMENT) SubtransactionAwareResource(org.omg.CosTransactions.SubtransactionAwareResource) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) BAD_PARAM(org.omg.CORBA.BAD_PARAM) OTSAbstractRecord(com.arjuna.ArjunaOTS.OTSAbstractRecord) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) UidCoordinator(com.arjuna.ArjunaOTS.UidCoordinator) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException) SynchronizationUnavailable(org.omg.CosTransactions.SynchronizationUnavailable) SubtransactionsUnavailable(org.omg.CosTransactions.SubtransactionsUnavailable) Unavailable(org.omg.CosTransactions.Unavailable) Uid(com.arjuna.ats.arjuna.common.Uid) SystemException(org.omg.CORBA.SystemException) Inactive(org.omg.CosTransactions.Inactive) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION) UNKNOWN(org.omg.CORBA.UNKNOWN) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK)

Example 2 with Inactive

use of org.omg.CosTransactions.Inactive in project narayana by jbosstm.

the class ArjunaTransactionImple method register_subtran_aware.

/**
 * Do not propagate the resource to the parent.
 */
public void register_subtran_aware(SubtransactionAwareResource r) throws Inactive, NotSubtransaction, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::register_subtran_aware called for " + get_uid());
    }
    if (r == null)
        throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
    currentStatus = determineStatus(this);
    if (currentStatus != Status.StatusActive) {
        if (currentStatus == Status.StatusMarkedRollback) {
            throw new TRANSACTION_ROLLEDBACK(ExceptionCodes.MARKED_ROLLEDBACK, CompletionStatus.COMPLETED_NO);
        } else
            throw new Inactive();
    }
    if (this == rootAction) {
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("ArjunaTransactionImple::register_subtran_aware called for " + get_uid() + " : not a subtransaction!");
        }
        throw new NotSubtransaction();
    } else {
        Coordinator coord = null;
        AbstractRecord corbaRec = null;
        try {
            coord = parentHandle.get_coordinator();
            corbaRec = createOTSRecord(false, r, coord);
        } catch (Unavailable ex) {
            throw new UNKNOWN(ExceptionCodes.INACTIVE_TRANSACTION, // what else to raise?
            CompletionStatus.COMPLETED_NO);
        }
        coord = null;
        if (add(corbaRec) != AddOutcome.AR_ADDED) {
            if (jtsLogger.logger.isTraceEnabled()) {
                jtsLogger.logger.trace("ArjunaTransactionImple::register_subtran_aware called for " + get_uid() + " : could not add.");
            }
            corbaRec = null;
            // what else to raise??
            throw new Inactive();
        }
    }
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::register_subtran_aware called for " + get_uid() + " : subtran_aware_resource registered");
    }
}
Also used : BAD_PARAM(org.omg.CORBA.BAD_PARAM) NotSubtransaction(org.omg.CosTransactions.NotSubtransaction) OTSAbstractRecord(com.arjuna.ArjunaOTS.OTSAbstractRecord) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) Inactive(org.omg.CosTransactions.Inactive) UNKNOWN(org.omg.CORBA.UNKNOWN) UidCoordinator(com.arjuna.ArjunaOTS.UidCoordinator) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) Coordinator(org.omg.CosTransactions.Coordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) SynchronizationUnavailable(org.omg.CosTransactions.SynchronizationUnavailable) SubtransactionsUnavailable(org.omg.CosTransactions.SubtransactionsUnavailable) Unavailable(org.omg.CosTransactions.Unavailable)

Example 3 with Inactive

use of org.omg.CosTransactions.Inactive 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 4 with Inactive

use of org.omg.CosTransactions.Inactive in project narayana by jbosstm.

the class ServerTransaction method register_synchronization.

/**
 * Registering a synchronization with interposition is a bit complicated!
 * Synchronizations must be called prior to prepare; if no
 * interposed-synchronization is used then either synchronizations would be
 * registered locally (and then ignored by the commit protocol) or they
 * would need to be registered remotely, which would mean a cross-address
 * space call for each synchronization!
 *
 * The first time a synchronization is registered locally, we register a
 * proxy back with the real coordinator. When that transaction commits, it
 * will call this proxy, which will then drive the locally registered
 * synchronizations (actually it calls appropriate on the transaction to do
 * this.)
 *
 * However, one-phase commit complicates matters even more since we call
 * commit on the interposed coordinator, which runs through the commit and
 * then the after_completion code before returning to the real coordinator's
 * commit call. Rather than separate commit and synchronization code
 * completely from the transaction (in which case we could just call the
 * commit portion here) we let after_completion get called before returning
 * the commit response, and simply ignore the real coordinator's subsequent
 * call to after_completion.
 */
public synchronized void register_synchronization(Synchronization theSync) throws Inactive, SynchronizationUnavailable, SystemException {
    if (// are we a top-level transaction?
    !is_top_level_transaction()) {
        throw new SynchronizationUnavailable();
    } else {
        if (_interposedSynch) {
            if (_sync == null) {
                _sync = new ServerSynchronization(this);
                Coordinator realCoord = null;
                try {
                    ServerControl control = (ServerControl) super.controlHandle;
                    if (controlHandle != null) {
                        realCoord = control.originalCoordinator();
                        if (realCoord != null) {
                            realCoord.register_synchronization(_sync.getSynchronization());
                        } else
                            throw new BAD_OPERATION(ExceptionCodes.NO_TRANSACTION, CompletionStatus.COMPLETED_NO);
                    } else
                        throw new BAD_OPERATION(ExceptionCodes.NO_TRANSACTION, CompletionStatus.COMPLETED_NO);
                } catch (Inactive e1) {
                    realCoord = null;
                    throw e1;
                } catch (SynchronizationUnavailable e2) {
                    realCoord = null;
                    throw e2;
                } catch (SystemException e3) {
                    realCoord = null;
                    throw e3;
                }
                realCoord = null;
            }
        }
        /*
			 * Now register the synchronization locally.
			 */
        super.register_synchronization(theSync);
    }
}
Also used : ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) SystemException(org.omg.CORBA.SystemException) ServerSynchronization(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.ServerSynchronization) Inactive(org.omg.CosTransactions.Inactive) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION) Coordinator(org.omg.CosTransactions.Coordinator) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) SynchronizationUnavailable(org.omg.CosTransactions.SynchronizationUnavailable)

Example 5 with Inactive

use of org.omg.CosTransactions.Inactive in project narayana by jbosstm.

the class TransactionFactoryImple method activeTransactions.

private final org.omg.CosTransactions.otid_t[] activeTransactions() throws Inactive, NoTransaction, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("TransactionFactoryImple::activeTransactions ()");
    }
    if (ControlImple.allControls == null)
        throw new Inactive();
    else {
        synchronized (ControlImple.allControls) {
            if (ControlImple.allControls.size() == 0)
                throw new NoTransaction();
            else {
                org.omg.CosTransactions.otid_t[] ids = new org.omg.CosTransactions.otid_t[ControlImple.allControls.size()];
                Enumeration iter = ControlImple.allControls.elements();
                int i = 0;
                while (iter.hasMoreElements()) {
                    ControlImple cont = (ControlImple) iter.nextElement();
                    if (cont != null) {
                        ids[i] = Utility.uidToOtid(cont.get_uid().stringForm());
                        i++;
                    }
                }
                return ids;
            }
        }
    }
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) Enumeration(java.util.Enumeration) CosTransactions.otid_t(org.omg.CosTransactions.otid_t) Inactive(org.omg.CosTransactions.Inactive)

Aggregations

Inactive (org.omg.CosTransactions.Inactive)14 SystemException (org.omg.CORBA.SystemException)9 UNKNOWN (org.omg.CORBA.UNKNOWN)5 Coordinator (org.omg.CosTransactions.Coordinator)5 SubtransactionsUnavailable (org.omg.CosTransactions.SubtransactionsUnavailable)5 SynchronizationUnavailable (org.omg.CosTransactions.SynchronizationUnavailable)5 Unavailable (org.omg.CosTransactions.Unavailable)5 UidCoordinator (com.arjuna.ArjunaOTS.UidCoordinator)4 BAD_PARAM (org.omg.CORBA.BAD_PARAM)4 NoTransaction (org.omg.CosTransactions.NoTransaction)4 RecoveryCoordinator (org.omg.CosTransactions.RecoveryCoordinator)4 Status (org.omg.CosTransactions.Status)4 CosTransactions.otid_t (org.omg.CosTransactions.otid_t)4 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)3 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)3 OTSAbstractRecord (com.arjuna.ArjunaOTS.OTSAbstractRecord)2 Uid (com.arjuna.ats.arjuna.common.Uid)2 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)2 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)2 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)2