Search in sources :

Example 1 with Terminator

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

the class ContextManager method addRemoteHierarchy.

/**
 * We could maintain a list of suspended action hierarchies and resume
 * the right one (and the right place!) given the control. However, this
 * can lead to memory leaks, since we never know when to remove this
 * hierarchy information. So, for now we simply rely on the propagation
 * context.
 */
public final boolean addRemoteHierarchy(Control cont) {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ContextManager::addRemoteHierarchy ()");
    }
    if (false) {
        pushAction(new ControlWrapper(cont));
        return true;
    } else {
        boolean isError = false;
        try {
            Coordinator coord = cont.get_coordinator();
            PropagationContext ctx = coord.get_txcontext();
            if (ctx != null) {
                /*
		     * Depth must be non-zero or we wouldn't be here!
		     */
                int depth = ctx.parents.length;
                for (int i = depth - 1; i >= 0; i--) {
                    /*
			 * No memory leak as we delete either when suspend
			 * is called, or the transaction is terminated.
			 */
                    Coordinator tmpCoord = ctx.parents[i].coord;
                    Terminator tmpTerm = ctx.parents[i].term;
                    Control theControl = TransactionFactoryImple.createProxy(tmpCoord, tmpTerm);
                    // takes care of thread/BasicAction for us.
                    pushAction(new ControlWrapper(theControl));
                }
                ctx = null;
            } else {
                /*
		     * If we can't get a propagation context then we cannot
		     * create the hierarchy!
		     */
                isError = true;
            }
            coord = null;
        } catch (Exception e) {
            isError = true;
        }
        return isError;
    }
}
Also used : Control(org.omg.CosTransactions.Control) ActionControl(com.arjuna.ArjunaOTS.ActionControl) PropagationContext(org.omg.CosTransactions.PropagationContext) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) Terminator(org.omg.CosTransactions.Terminator) Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException) EmptyStackException(java.util.EmptyStackException)

Example 2 with Terminator

use of org.omg.CosTransactions.Terminator 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 3 with Terminator

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

use of org.omg.CosTransactions.Terminator 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 5 with Terminator

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

the class GridTest method test.

@Test
public void test() {
    ORB myORB = null;
    RootOA myOA = null;
    try {
        myORB = ORB.getInstance("test");
        myOA = OA.getRootOA(myORB);
        myORB.initORB(new String[] {}, null);
        myOA.initOA();
        ORBManager.setORB(myORB);
        ORBManager.setPOA(myOA);
        TransactionFactoryImple theOTS = new TransactionFactoryImple();
        Control myControl;
        grid_i localGrid = new grid_i(100, 100);
        int h, w, v;
        myControl = theOTS.create(0);
        assertNotNull(myControl);
        h = localGrid.height();
        w = localGrid.width();
        localGrid.set(2, 4, 123, myControl);
        v = localGrid.get(2, 4, myControl);
        // no problem setting and getting the elememt:
        System.out.println("grid[2,4] is " + v);
        assertEquals(123, v);
        Terminator handle = myControl.get_terminator();
        try {
            if (handle != null) {
                handle.commit(false);
            } else
                System.err.println("Error - no transaction terminator!");
        } catch (Exception ex) {
            System.out.println("Test error! Caught: " + ex);
        }
        ORBManager.getPOA().shutdownObject(theOTS);
        ORBManager.getPOA().shutdownObject(localGrid);
    } catch (UserException e) {
        fail("Caught UserException: " + e);
        e.printStackTrace();
    } catch (SystemException e) {
        fail("Caught SystemException: " + e);
        e.printStackTrace();
    }
    System.out.println("\nWill now try different thread terminating transaction.\n");
    try {
        org.omg.CosTransactions.Current current = OTSManager.get_current();
        System.out.println("Starting new transaction.");
        current.begin();
        Control tc = current.get_control();
        if (tc != null) {
            System.out.println("Creating new thread.");
            TransactionalThread tranThread = new TransactionalThread(tc);
            System.out.println("Waiting for thread to terminate transaction.\n");
            tranThread.start();
            while (!tranThread.finished()) Thread.yield();
            System.out.println("\nCreator will now attempt to rollback transaction. Should fail.");
            try {
                current.rollback();
                fail("Error - managed to rollback transaction!");
            } catch (NoTransaction e1) {
                System.out.println("Correct termination - caught: " + e1);
            } catch (INVALID_TRANSACTION e2) {
                System.out.println("Correct termination - caught: " + e2);
            } catch (Exception e3) {
                fail("Wrong termination - caught unexpected exception: " + e3);
                e3.printStackTrace();
            }
            System.out.println("Test completed successfully.");
        } else
            System.err.println("Error - null transaction control!");
    } catch (Exception e) {
        System.out.println("Caught unexpected exception: " + e);
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : TransactionalThread(com.hp.mwtests.ts.jts.resources.TransactionalThread) NoTransaction(org.omg.CosTransactions.NoTransaction) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) RootOA(com.arjuna.orbportability.RootOA) Terminator(org.omg.CosTransactions.Terminator) com.hp.mwtests.ts.jts.orbspecific.resources.grid_i(com.hp.mwtests.ts.jts.orbspecific.resources.grid_i) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) Control(org.omg.CosTransactions.Control) SystemException(org.omg.CORBA.SystemException) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) UserException(org.omg.CORBA.UserException) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Aggregations

Terminator (org.omg.CosTransactions.Terminator)13 SystemException (org.omg.CORBA.SystemException)11 Coordinator (org.omg.CosTransactions.Coordinator)10 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)9 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)8 Control (org.omg.CosTransactions.Control)5 Uid (com.arjuna.ats.arjuna.common.Uid)4 ServerResource (com.arjuna.ats.internal.jts.interposition.resources.arjuna.ServerResource)4 ServerTopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction)4 ORB (com.arjuna.orbportability.ORB)4 RootOA (com.arjuna.orbportability.RootOA)4 Test (org.junit.Test)4 TransIdentity (org.omg.CosTransactions.TransIdentity)4 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)2 ServerNestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction)2 ServerOSINestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.osi.ServerOSINestedAction)2 ServerOSITopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.osi.ServerOSITopLevelAction)2 ServerRestrictedNestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedNestedAction)2 ServerRestrictedTopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedTopLevelAction)2 ServerStrictNestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.strict.ServerStrictNestedAction)2