Search in sources :

Example 16 with Coordinator

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

the class ControlWrapper method register_subtran_aware.

public final void register_subtran_aware(SubtransactionAwareResource sr) throws Inactive, NotSubtransaction, SystemException {
    try {
        if (_controlImpl != null)
            _controlImpl.getImplHandle().register_subtran_aware(sr);
        else {
            try {
                Coordinator coord = _control.get_coordinator();
                coord.register_subtran_aware(sr);
            } catch (Unavailable e2) {
                throw new Inactive();
            } catch (SystemException e3) {
                throw new UNKNOWN();
            } catch (final NullPointerException ex) {
                throw new UNKNOWN();
            }
        }
    } catch (NullPointerException e1) {
        throw new Inactive();
    }
}
Also used : SystemException(org.omg.CORBA.SystemException) Inactive(org.omg.CosTransactions.Inactive) UNKNOWN(org.omg.CORBA.UNKNOWN) UidCoordinator(com.arjuna.ArjunaOTS.UidCoordinator) Coordinator(org.omg.CosTransactions.Coordinator) SynchronizationUnavailable(org.omg.CosTransactions.SynchronizationUnavailable) SubtransactionsUnavailable(org.omg.CosTransactions.SubtransactionsUnavailable) Unavailable(org.omg.CosTransactions.Unavailable)

Example 17 with Coordinator

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

the class ControlWrapper method equals.

/**
 * Overrides Object.equals
 *
 * Does not compare Uids because a foreign transaction may have been
 * imported more than once and given different local ids.
 */
public boolean equals(Object e) {
    if (e instanceof Uid) {
        return _theUid.equals(e);
    }
    if (e instanceof ControlWrapper) {
        ControlWrapper c = (ControlWrapper) e;
        if (c.isLocal() && isLocal()) {
            return c.getImple().equals(_controlImpl);
        } else {
            /*
				 * One of them is not local, so we have to revert to indirect
				 * comparison.
				 */
            Coordinator coord = null;
            try {
                coord = _control.get_coordinator();
            } catch (Exception e1) {
                return false;
            }
            Coordinator myCoord = null;
            try {
                myCoord = get_coordinator();
            } catch (Exception e2) {
                return false;
            }
            try {
                return coord.is_same_transaction(myCoord);
            } catch (Exception e3) {
            }
        }
    }
    return false;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) UidCoordinator(com.arjuna.ArjunaOTS.UidCoordinator) Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException)

Example 18 with Coordinator

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

the class Interposition method checkHierarchy.

/*
     * In a single threaded environment we could walk down the hierarchy,
     * aborting any actions which are no longer valid, and creating any new
     * ones. However, in a multi-threaded environment, a thread can make a
     * call from any point in the client's hierarchy, and multiple client
     * threads can invoke the same server object. So, in general we cannot do
     * this optimisation. We must maintain the entire tree until portions of
     * it have explicitly been termined.
     *
     * Once we find the point in the new hierarchy which deviates from our
     * current representation, we begin to assemble a new subtree in much the
     * same way as we did for creating a completely new hierarchy.
     */
protected synchronized ControlImple checkHierarchy(ServerTopLevelAction hier, PropagationContext context) throws SystemException {
    ServerControl control = null;
    // top-level transaction
    ServerResource currentAction = hier;
    int depth = context.parents.length;
    // index of the new transactions in the hierarchy
    int differenceIndex = -1;
    if (depth == 0) {
        /*
	     * There are no transactions in the context other than the current
	     * transaction, which must therefore be top-level. We already have
	     * the control to return.
	     */
        // top-level transaction's control
        control = hier.control();
    } else {
        ServerResource nestedAction = null;
        for (// don't check depth-1 as it is current action!
        int i = depth - 2; // don't check depth-1 as it is current action!
        i >= 0; // don't check depth-1 as it is current action!
        i--) {
            nestedAction = currentAction.getChild(Utility.otidToUid(context.parents[i].otid));
            if (// point of difference, so stop trawling hierarchy
            nestedAction == null) {
                // remember for later so that we can add new actions.
                differenceIndex = i;
                break;
            } else {
                /*
		     * currentAction *always* points to the last known
		     * good transaction in our hierarchy.
		     */
                currentAction = nestedAction;
            }
        }
        if (differenceIndex != -1) {
            control = currentAction.control();
            Coordinator tmpCoord;
            Terminator tmpTerm;
            for (int j = differenceIndex; j >= 0; j--) {
                tmpCoord = context.parents[j].coord;
                tmpTerm = context.parents[j].term;
                control = ServerFactory.create_subtransaction(Utility.otidToUid(context.parents[j].otid), tmpCoord, tmpTerm, control);
                nestedAction = new ServerNestedAction(control);
                if (!nestedAction.valid()) {
                    try {
                        // does dispose as well!
                        ((ServerNestedAction) nestedAction).rollback();
                        nestedAction = null;
                    } catch (Exception e) {
                    }
                    throw new TRANSACTION_ROLLEDBACK();
                }
                currentAction.addChild((ServerNestedAction) nestedAction);
                currentAction = nestedAction;
            }
        } else {
        /*
		 * Hierarchies may be identical.
		 * Remember to check!
		 */
        }
        Uid currentUid = Utility.otidToUid(context.current.otid);
        /*
	     * currentAction points to the parent of the 'current'
	     * transaction, i.e., the last element in the TransIdentity
	     * structure. So, ask it if the sent hierarchy's child is
	     * one of its children.
	     */
        nestedAction = currentAction.getChild(currentUid);
        if (nestedAction == null) {
            /*
		 * Different notion of current in sent hierarchy.
		 * So, add it to the hierarchy here.
		 */
            control = currentAction.control();
            /*
		 * Now deal with the current transaction.
		 */
            TransIdentity currentID = context.current;
            control = ServerFactory.create_subtransaction(currentUid, currentID.coord, currentID.term, control);
            nestedAction = new ServerNestedAction(control);
            if (!nestedAction.valid()) {
                try {
                    // does dispose as well!
                    ((ServerNestedAction) nestedAction).rollback();
                    nestedAction = null;
                } catch (Exception e) {
                }
                throw new TRANSACTION_ROLLEDBACK();
            }
            currentAction.addChild((ServerNestedAction) nestedAction);
        } else {
            /*
		 * Same current, so get its control and return it.
		 */
            control = nestedAction.control();
        }
    }
    if (jtsLogger.logger.isTraceEnabled())
        compareHierarchies(context, hier);
    return control;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) TransIdentity(org.omg.CosTransactions.TransIdentity) ServerNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction) Terminator(org.omg.CosTransactions.Terminator) Coordinator(org.omg.CosTransactions.Coordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) SystemException(org.omg.CORBA.SystemException)

Example 19 with Coordinator

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

the class Interposition method createHierarchy.

protected synchronized ControlImple createHierarchy(PropagationContext ctx, Uid tlUid) throws SystemException {
    /*
	 * Start at the parent and work our way down to "current". The current
	 * transaction is not in the IDL sequence, but sent as separate field
	 * of the propagation context. This tends to make the code more
	 * complex than it would be if the entire hierarchy was represented in
	 * one place.
	 */
    int depth = ctx.parents.length;
    ServerResource action = null;
    Coordinator tmpCoord = null;
    Terminator tmpTerm = null;
    if (depth == 0) {
        tmpCoord = ctx.current.coord;
        tmpTerm = ctx.current.term;
    } else {
        tmpCoord = ctx.parents[depth - 1].coord;
        tmpTerm = ctx.parents[depth - 1].term;
    }
    if (// terminator may correctly be null
    tmpCoord == null) {
        return null;
    }
    ServerControl control = ServerFactory.create_transaction(tlUid, null, null, tmpCoord, tmpTerm, ctx.timeout);
    action = new ServerTopLevelAction(control);
    if (!action.valid()) {
        try {
            // does dispose as well!
            ((ServerTopLevelAction) action).rollback();
        } catch (Exception e) {
        }
        if (((ServerTopLevelAction) action).isTransactionInactive()) {
            throw new TRANSACTION_UNAVAILABLE(jtsLogger.i18NLogger.get_transaction_was_inactive(), 1, CompletionStatus.COMPLETED_NO);
        } else {
            throw new TRANSACTION_ROLLEDBACK();
        }
    }
    ServerTopLevelAction newElement = (ServerTopLevelAction) action;
    _head.add(newElement);
    if (// current is a nested transaction
    depth > 0) {
        /*
	     * Now deal with any nested transactions.
	     * As we create, register with the original transactions.
	     */
        ServerResource nestedAction = null;
        for (int i = depth - 2; i >= 0; i--) {
            tmpCoord = ctx.parents[i].coord;
            tmpTerm = ctx.parents[i].term;
            control = ServerFactory.create_subtransaction(Utility.otidToUid(ctx.parents[i].otid), tmpCoord, tmpTerm, control);
            nestedAction = new ServerNestedAction(control);
            if (!nestedAction.valid()) {
                try {
                    // does dispose as well!
                    ((ServerNestedAction) nestedAction).rollback_subtransaction();
                    nestedAction = null;
                } catch (Exception e) {
                }
                throw new TRANSACTION_ROLLEDBACK();
            }
            /*
		 * Add transaction resource to list.
		 */
            action.addChild((ServerNestedAction) nestedAction);
            action = nestedAction;
        }
        /*
	     * Now deal with current transaction. If there is
	     * only one transaction we do nothing.
	     */
        tmpCoord = ctx.current.coord;
        tmpTerm = ctx.current.term;
        control = ServerFactory.create_subtransaction(Utility.otidToUid(ctx.current.otid), tmpCoord, tmpTerm, control);
        nestedAction = new ServerNestedAction(control);
        if (!nestedAction.valid()) {
            try {
                // does dispose as well!
                ((ServerNestedAction) nestedAction).rollback_subtransaction();
                nestedAction = null;
            } catch (Exception e) {
            }
            throw new TRANSACTION_ROLLEDBACK();
        }
        action.addChild((ServerNestedAction) nestedAction);
    }
    if (jtsLogger.logger.isTraceEnabled())
        compareHierarchies(ctx, newElement);
    return control;
}
Also used : ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ServerTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction) ServerNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction) Terminator(org.omg.CosTransactions.Terminator) Coordinator(org.omg.CosTransactions.Coordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) SystemException(org.omg.CORBA.SystemException) TRANSACTION_UNAVAILABLE(org.omg.CORBA.TRANSACTION_UNAVAILABLE)

Example 20 with Coordinator

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

the class RestrictedInterposition method checkHierarchy.

/*
     * Work our way down the hierarchy, aborting any actions which are no longer
     * valid, and creating any new ones. These new actions must be nested
     * actions.
     */
protected synchronized ControlImple checkHierarchy(ServerTopLevelAction hier, PropagationContext context) throws SystemException {
    ServerRestrictedTopLevelAction tlAction = (ServerRestrictedTopLevelAction) hier;
    // top-level's control
    ServerControl control = tlAction.control();
    int depth = context.parents.length;
    // index of the new transactions in the
    int differenceIndex = -1;
    // hierarchy
    // top-level
    ServerRestrictedNestedAction nestedAction = tlAction.child();
    if (depth == 0) {
        if (nestedAction != null) {
            // automatically removed from
            tlAction.abortChild(nestedAction);
            // resource list
            nestedAction = null;
            control = tlAction.deepestControl();
        }
    } else {
        for (int i = depth - 2; (i >= 0) && (nestedAction != null); i--) {
            if (nestedAction.get_uid().equals(Utility.otidToUid(context.parents[i].otid))) {
                /*
                     * nestedActionalways points to the next transaction in the
                     * hierarchy when we leave this loop.
                     */
                nestedAction = nestedAction.child();
                if ((nestedAction == null) && (i > 0)) {
                    differenceIndex = i - 1;
                    control = tlAction.deepestControl();
                }
            } else {
                /*
                     * Uids not equal, so abort. No need to continue down the
                     * hierarchy, as aborting from this point will implicitly
                     * abort out children.
                     */
                // remember for later so that we can
                differenceIndex = i;
                // add new actions.
                tlAction.abortChild(nestedAction);
                nestedAction = null;
                control = tlAction.deepestControl();
                break;
            }
        }
        if (differenceIndex != -1) {
            Coordinator tmpCoord;
            Terminator tmpTerm;
            for (int j = differenceIndex; j >= 0; j--) {
                tmpCoord = context.parents[j].coord;
                tmpTerm = context.parents[j].term;
                control = ServerFactory.create_subtransaction(Utility.otidToUid(context.parents[j].otid), tmpCoord, tmpTerm, control);
                nestedAction = new ServerRestrictedNestedAction(control);
                if (!nestedAction.valid()) {
                    try {
                        // does dispose as well!
                        nestedAction.rollback();
                        nestedAction = null;
                    } catch (Exception e) {
                    }
                    throw new TRANSACTION_ROLLEDBACK();
                }
                tlAction.addChild(nestedAction);
            }
            nestedAction = null;
        } else {
            if (nestedAction != null) {
                /*
                     * If current transaction has a child then we should abort
                     * it, since it does not exist in the hierarchy we have just
                     * received.
                     */
                nestedAction = nestedAction.child();
                if (nestedAction != null) {
                    tlAction.abortChild(nestedAction);
                    nestedAction = null;
                    control = tlAction.deepestControl();
                }
            }
        }
    }
    boolean newCurrent = false;
    Uid sentCurrent = Utility.otidToUid(context.current.otid);
    if (differenceIndex == -1) {
        /*
             * Now determine whether we have to create any new nested actions.
             */
        Uid currentUid = null;
        if (nestedAction == null) {
            nestedAction = tlAction.child();
            if (nestedAction != null) {
                while (nestedAction.child() != null) nestedAction = nestedAction.child();
                currentUid = nestedAction.get_uid();
            } else
                currentUid = tlAction.get_uid();
        } else
            currentUid = nestedAction.get_uid();
        if (currentUid.notEquals(sentCurrent)) {
            newCurrent = true;
        }
    } else
        newCurrent = true;
    if (newCurrent) {
        if (depth == 1) {
            /*
                 * Old current is gone.
                 */
            nestedAction = tlAction.child();
            if (nestedAction != null) {
                tlAction.abortChild(nestedAction);
                nestedAction = null;
            }
            control = (ServerControl) tlAction.control();
        } else
            control = tlAction.deepestControl();
        TransIdentity currentID = context.current;
        control = ServerFactory.create_subtransaction(sentCurrent, currentID.coord, currentID.term, control);
        nestedAction = new ServerRestrictedNestedAction(control);
        if (!nestedAction.valid()) {
            try {
                // does dispose as well!
                nestedAction.rollback();
                nestedAction = null;
            } catch (Exception e) {
            }
            throw new TRANSACTION_ROLLEDBACK();
        }
        tlAction.addChild(nestedAction);
        nestedAction = null;
    }
    return control;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) TransIdentity(org.omg.CosTransactions.TransIdentity) ServerRestrictedTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedTopLevelAction) Terminator(org.omg.CosTransactions.Terminator) ServerRestrictedNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedNestedAction) Coordinator(org.omg.CosTransactions.Coordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) SystemException(org.omg.CORBA.SystemException)

Aggregations

Coordinator (org.omg.CosTransactions.Coordinator)47 SystemException (org.omg.CORBA.SystemException)32 UNKNOWN (org.omg.CORBA.UNKNOWN)15 Control (org.omg.CosTransactions.Control)14 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)13 BAD_PARAM (org.omg.CORBA.BAD_PARAM)12 Unavailable (org.omg.CosTransactions.Unavailable)11 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)10 Terminator (org.omg.CosTransactions.Terminator)10 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)9 UidCoordinator (com.arjuna.ArjunaOTS.UidCoordinator)6 Uid (com.arjuna.ats.arjuna.common.Uid)6 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)6 ORB (com.arjuna.orbportability.ORB)6 Any (org.omg.CORBA.Any)6 TRANSACTION_REQUIRED (org.omg.CORBA.TRANSACTION_REQUIRED)6 TransactionalObject (org.omg.CosTransactions.TransactionalObject)6 ServiceContext (org.omg.IOP.ServiceContext)6 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)5 PropagationContext (org.omg.CosTransactions.PropagationContext)5