Search in sources :

Example 21 with Control

use of org.omg.CosTransactions.Control 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 22 with Control

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

the class ContextManager method addActionControlHierarchy.

/*
     * All OTSArjuna controls have a method for getting their parent.
     */
public final boolean addActionControlHierarchy(ActionControl cont) {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ContextManager::addActionControlHierarchy ()");
    }
    boolean isError = false;
    try {
        ActionControl actControl = cont;
        Control parentControl = actControl.getParentControl();
        Stack hier = new Stack();
        while (parentControl != null) {
            hier.push(new ControlWrapper(parentControl));
            actControl = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(parentControl);
            if (actControl != null)
                parentControl = actControl.getParentControl();
            else
                parentControl = null;
        }
        actControl = null;
        try {
            ControlWrapper wrapper = (ControlWrapper) hier.pop();
            while (wrapper != null) {
                pushAction(wrapper);
                wrapper = null;
                wrapper = (ControlWrapper) hier.pop();
            }
        } catch (EmptyStackException e) {
        }
    } catch (Exception e) {
        jtsLogger.i18NLogger.warn_context_genfail("ContextManager.addActionControlHierarchy", e);
        isError = true;
    }
    return isError;
}
Also used : EmptyStackException(java.util.EmptyStackException) ActionControl(com.arjuna.ArjunaOTS.ActionControl) Control(org.omg.CosTransactions.Control) ActionControl(com.arjuna.ArjunaOTS.ActionControl) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) SystemException(org.omg.CORBA.SystemException) EmptyStackException(java.util.EmptyStackException) Stack(java.util.Stack)

Example 23 with Control

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

the class FactoryList method recreate.

public static Control recreate(PropagationContext ctx, int formatID) throws SystemException {
    Control toReturn = null;
    if (ctx == null)
        throw new INVALID_TRANSACTION();
    FactoryElement ptr = find(formatID);
    if (ptr != null) {
        toReturn = ptr.recreate(ctx);
    }
    return toReturn;
}
Also used : Control(org.omg.CosTransactions.Control) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION)

Example 24 with Control

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

the class ServerFactory method create_subtransaction.

public static ServerControl create_subtransaction(Uid actUid, Coordinator realCoord, Terminator realTerm, ServerControl parent) {
    if (parent == null) {
        jtsLogger.i18NLogger.warn_interposition_sfnoparent("ServerFactory.create_subtransaction");
        return null;
    }
    ServerControl toReturn = null;
    try {
        Control handle = parent.getControl();
        ArjunaTransactionImple tranHandle = parent.getImplHandle();
        toReturn = new ServerControl(actUid, handle, tranHandle, realCoord, realTerm);
        handle = null;
        tranHandle = null;
    } catch (Exception e) {
        if (toReturn != null) {
            try {
                // will delete itself
                toReturn.destroy();
            } catch (Exception ex) {
            }
        }
    }
    return toReturn;
}
Also used : ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) Control(org.omg.CosTransactions.Control) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) SystemException(org.omg.CORBA.SystemException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 25 with Control

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

the class TransactionImpleUnitTest method testEnlist.

@Test
public void testEnlist() throws Exception {
    ThreadActionData.purgeActions();
    OTSImpleManager.current().contextManager().purgeActions();
    TransactionImple tx = new TransactionImple();
    tx.setRollbackOnly();
    try {
        tx.enlistResource(null);
        fail();
    } catch (final SystemException ex) {
    }
    try {
        tx.enlistResource(new DummyXA(false));
        fail();
    } catch (final RollbackException ex) {
    }
    try {
        tx.commit();
        fail();
    } catch (final RollbackException ex) {
    }
    try {
        tx.enlistResource(new DummyXA(false));
        fail();
    } catch (final IllegalStateException ex) {
    }
    Control suspend = OTSImpleManager.current().suspend();
    tx = new TransactionImple();
    DummyXA res = new DummyXA(false);
    tx.enlistResource(res);
    tx.delistResource(res, XAResource.TMSUSPEND);
    tx.enlistResource(res);
    tx.commit();
}
Also used : Control(org.omg.CosTransactions.Control) DummyXA(com.hp.mwtests.ts.jta.jts.common.DummyXA) SystemException(javax.transaction.SystemException) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Aggregations

Control (org.omg.CosTransactions.Control)103 Test (org.junit.Test)40 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)24 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)20 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)20 ORB (com.arjuna.orbportability.ORB)20 RootOA (com.arjuna.orbportability.RootOA)18 TransactionFactory (org.omg.CosTransactions.TransactionFactory)16 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)14 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)13 Coordinator (org.omg.CosTransactions.Coordinator)13 SystemException (org.omg.CORBA.SystemException)11 IntHolder (org.omg.CORBA.IntHolder)10 Current (org.omg.CosTransactions.Current)9 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)6 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)6 Services (com.arjuna.orbportability.Services)6 PropagationContext (org.omg.CosTransactions.PropagationContext)6 ActionControl (com.arjuna.ArjunaOTS.ActionControl)5 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)5