Search in sources :

Example 6 with ServerControl

use of com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl 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 7 with ServerControl

use of com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl 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 8 with ServerControl

use of com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl 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 9 with ServerControl

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

the class ServerTopLevelStrictUnitTest method test.

@Test
public void test() 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());
    ServerStrictTopLevelAction act = new ServerStrictTopLevelAction(sc, true);
    assertTrue(act.interposeResource());
    assertTrue(act.type() != 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) ServerStrictTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.strict.ServerStrictTopLevelAction) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Example 10 with ServerControl

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

the class ServerNestedRestrictedUnitTest method test.

@Test
public void test() 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());
    ServerRestrictedNestedAction act = new ServerRestrictedNestedAction(sc);
    assertTrue(act.deepestControl() != null);
    assertEquals(act.child(), 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) ServerRestrictedNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedNestedAction) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Aggregations

ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)33 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)21 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)20 Test (org.junit.Test)20 Control (org.omg.CosTransactions.Control)20 SystemException (org.omg.CORBA.SystemException)12 Coordinator (org.omg.CosTransactions.Coordinator)9 ServerTopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction)8 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)8 Terminator (org.omg.CosTransactions.Terminator)8 Uid (com.arjuna.ats.arjuna.common.Uid)6 ServerNestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction)5 ServerOSITopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.osi.ServerOSITopLevelAction)5 ServerResource (com.arjuna.ats.internal.jts.interposition.resources.arjuna.ServerResource)4 ServerOSINestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.osi.ServerOSINestedAction)4 ServerStrictNestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.strict.ServerStrictNestedAction)4 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)4 TransIdentity (org.omg.CosTransactions.TransIdentity)4 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)3 ServerRestrictedNestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedNestedAction)3