Search in sources :

Example 1 with ServerRestrictedTopLevelAction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedTopLevelAction 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)

Example 2 with ServerRestrictedTopLevelAction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedTopLevelAction in project narayana by jbosstm.

the class ServerTopLevelRestrictedUnitTest method testCommit.

@Test
public void testCommit() throws Exception {
    ControlImple cont = new ControlImple(null, null);
    Control theControl = cont.getControl();
    ArjunaTransactionImple tx = cont.getImplHandle();
    ServerControl sc = new ServerControl(tx.get_uid(), theControl, tx, theControl.get_coordinator(), theControl.get_terminator());
    ServerRestrictedTopLevelAction act = new ServerRestrictedTopLevelAction(sc);
    assertTrue(act.type() != null);
    assertTrue(act.child() == null);
    assertTrue(act.deepestControl() != null);
}
Also used : Control(org.omg.CosTransactions.Control) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) ServerRestrictedTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedTopLevelAction) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Example 3 with ServerRestrictedTopLevelAction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedTopLevelAction in project narayana by jbosstm.

the class RestrictedInterposition 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;
    ServerTopLevelAction tlAction = 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;
    }
    ServerControl control = ServerFactory.create_transaction(tlUid, null, null, tmpCoord, tmpTerm, ctx.timeout);
    tlAction = new ServerRestrictedTopLevelAction(control);
    if (!tlAction.valid()) {
        try {
            tlAction.rollback();
            tlAction = null;
        } catch (Exception e) {
        }
        throw new TRANSACTION_ROLLEDBACK();
    }
    ServerTopLevelAction newElement = tlAction;
    super._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.
             */
        ServerRestrictedNestedAction 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 ServerRestrictedNestedAction(control);
            if (!nestedAction.valid()) {
                try {
                    nestedAction.rollback();
                    nestedAction = null;
                } catch (Exception e) {
                }
                throw new TRANSACTION_ROLLEDBACK();
            }
            /*
                 * Add transaction resource to list.
                 */
            tlAction.addChild(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 ServerRestrictedNestedAction(control);
        if (!nestedAction.valid()) {
            try {
                nestedAction.rollback();
                nestedAction = null;
            } catch (Exception e) {
            }
            throw new TRANSACTION_ROLLEDBACK();
        }
        tlAction.addChild(nestedAction);
    }
    return control;
}
Also used : ServerTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) 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

ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)3 ServerRestrictedTopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedTopLevelAction)3 ServerRestrictedNestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedNestedAction)2 SystemException (org.omg.CORBA.SystemException)2 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)2 Coordinator (org.omg.CosTransactions.Coordinator)2 Terminator (org.omg.CosTransactions.Terminator)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)1 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)1 ServerTopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction)1 Test (org.junit.Test)1 Control (org.omg.CosTransactions.Control)1 TransIdentity (org.omg.CosTransactions.TransIdentity)1