Search in sources :

Example 21 with ControlImple

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

the class JTSInterpositionSynchronizationTest method test.

@Test
public void test() throws Exception {
    InterpositionCreator creator = new InterpositionCreator();
    jtaPropertyManager.getJTAEnvironmentBean().setTransactionManagerClassName(com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple.class.getName());
    jtaPropertyManager.getJTAEnvironmentBean().setUserTransactionClassName(com.arjuna.ats.internal.jta.transaction.jts.UserTransactionImple.class.getName());
    jtsPropertyManager.getJTSEnvironmentBean().setSupportInterposedSynchronization(true);
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    tm.setTransactionTimeout(1000000);
    tm.begin();
    TransactionImple transaction = (TransactionImple) tm.getTransaction();
    transaction.enlistResource(new XAResource() {

        @Override
        public int prepare(Xid arg0) throws XAException {
            prepareCalled = true;
            beforeCompletionCalledFirst = beforeCompletionCalled;
            return 0;
        }

        @Override
        public void commit(Xid arg0, boolean arg1) throws XAException {
        }

        @Override
        public void end(Xid arg0, int arg1) throws XAException {
        }

        @Override
        public void forget(Xid arg0) throws XAException {
        }

        @Override
        public int getTransactionTimeout() throws XAException {
            return 0;
        }

        @Override
        public boolean isSameRM(XAResource arg0) throws XAException {
            return false;
        }

        @Override
        public Xid[] recover(int arg0) throws XAException {
            return null;
        }

        @Override
        public void rollback(Xid arg0) throws XAException {
        }

        @Override
        public boolean setTransactionTimeout(int arg0) throws XAException {
            return false;
        }

        @Override
        public void start(Xid arg0, int arg1) throws XAException {
        }
    });
    ControlWrapper controlWrapper = transaction.getControlWrapper();
    Uid get_uid = transaction.get_uid();
    ControlImple cont = controlWrapper.getImple();
    ArjunaTransactionImple tx = cont.getImplHandle();
    CurrentImple current = OTSImpleManager.current();
    Control get_control = current.get_control();
    PropagationContext ctx = cont.get_coordinator().get_txcontext();
    ControlImple recreateLocal = creator.recreateLocal(ctx);
    assertTrue(recreateLocal != null);
    Control recreate = creator.recreate(ctx);
    assertTrue(recreate != null);
    Object remove = ControlImple.allControls.remove(get_uid);
    ServerControl sc = new ServerControl(get_uid, get_control, null, cont.get_coordinator(), cont.get_terminator());
    ControlImple.allControls.put(get_uid, remove);
    ServerTopLevelAction serverTopLevelAction = new ServerTopLevelAction(sc);
    sc.getImplHandle().register_synchronization(new ManagedSynchronizationImple(new Synchronization() {

        @Override
        public void beforeCompletion() {
            beforeCompletionCalled = true;
        }

        @Override
        public void afterCompletion(int status) {
            afterCompletionCalled = true;
        }
    }).getSynchronization());
    transaction.commit();
    assertTrue(prepareCalled == true);
    assertTrue(beforeCompletionCalled);
    assertTrue(afterCompletionCalled);
    assertTrue(beforeCompletionCalledFirst == jtsPropertyManager.getJTSEnvironmentBean().isSupportInterposedSynchronization());
}
Also used : InterpositionCreator(com.arjuna.ats.internal.jts.interposition.resources.arjuna.InterpositionCreator) ManagedSynchronizationImple(com.arjuna.ats.internal.jta.resources.jts.orbspecific.ManagedSynchronizationImple) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) PropagationContext(org.omg.CosTransactions.PropagationContext) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) Control(org.omg.CosTransactions.Control) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) XAException(javax.transaction.xa.XAException) Synchronization(javax.transaction.Synchronization) Uid(com.arjuna.ats.arjuna.common.Uid) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) ServerTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction) Test(org.junit.Test)

Example 22 with ControlImple

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

the class FactoryList method recreateLocal.

public static ControlImple recreateLocal(PropagationContext ctx, int formatID) throws SystemException {
    ControlImple toReturn = null;
    if (ctx == null)
        throw new INVALID_TRANSACTION();
    FactoryElement ptr = find(formatID);
    if (ptr != null) {
        toReturn = ptr.recreateLocal(ctx);
    }
    return toReturn;
}
Also used : INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple)

Example 23 with ControlImple

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

the class ServerFactory method create_transaction.

public static ServerControl create_transaction(Uid u, Control parentControl, ArjunaTransactionImple parentImpl, Coordinator realCoord, Terminator realTerm, int time_out) {
    ServerControl tranControl = new ServerControl(u, parentControl, parentImpl, realCoord, realTerm);
    if ((time_out != 0) && (parentImpl == null)) {
        TransactionReaper reaper = TransactionReaper.transactionReaper();
        reaper.insert(new ServerControlWrapper((ControlImple) tranControl), time_out);
    }
    return tranControl;
}
Also used : ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) TransactionReaper(com.arjuna.ats.arjuna.coordinator.TransactionReaper) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple)

Example 24 with ControlImple

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

the class Interposition method setupHierarchy.

/*
     * Assume that all actions in the imported hierarchy are of the same
     * type, i.e., all JBoss transactions.
     *
     * Because of the way garbage collection works in the ORB we have to
     * run an explicit garbage collection phase for finished hierarchies.
     */
public synchronized ControlImple setupHierarchy(PropagationContext context) throws SystemException {
    ControlImple controlPtr = null;
    Uid theUid = null;
    ServerTopLevelAction proxyAction = null;
    if (context.parents.length == 0)
        theUid = Utility.otidToUid(context.current.otid);
    else
        theUid = Utility.otidToUid(context.parents[context.parents.length - 1].otid);
    proxyAction = present(theUid);
    if (proxyAction == null) {
        /*
	     * Create a new proxyAction element and return the
	     * "current" transaction.
	     */
        controlPtr = createHierarchy(context, theUid);
    } else {
        /*
	     * Check hierarchy of existing element.
	     */
        controlPtr = checkHierarchy(proxyAction, context);
        proxyAction = null;
    }
    return controlPtr;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ServerTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple)

Example 25 with ControlImple

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

the class Helper method localAction.

/**
 * Given a Control_ptr determine if this is a reference to a local
 * action, and if so return the raw BasicAction pointer.
 */
public static final BasicAction localAction(org.omg.CosTransactions.Control control) {
    if (control == null)
        return null;
    if (control instanceof ControlImple) {
        try {
            ControlImple c = (ControlImple) control;
            return (BasicAction) c.getImplHandle();
        } catch (Exception e) {
        }
    }
    try {
        UidCoordinator coord = Helper.getUidCoordinator(control);
        if (coord != null) {
            Uid u = Helper.getUid(coord);
            coord = null;
            return ActionManager.manager().get(u);
        } else
            throw new BAD_PARAM();
    } catch (Exception e) {
    /*
	     * Can't be an Arjuna action, so ignore.
	     */
    }
    return null;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) UidCoordinator(com.arjuna.ArjunaOTS.UidCoordinator) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) BAD_PARAM(org.omg.CORBA.BAD_PARAM) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple)

Aggregations

ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)41 Test (org.junit.Test)30 Control (org.omg.CosTransactions.Control)24 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)21 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)19 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)10 Uid (com.arjuna.ats.arjuna.common.Uid)8 ServerTopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction)7 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)7 PropagationContext (org.omg.CosTransactions.PropagationContext)5 SystemException (org.omg.CORBA.SystemException)4 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)3 ServerNestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction)3 ServerOSITopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.osi.ServerOSITopLevelAction)3 BAD_PARAM (org.omg.CORBA.BAD_PARAM)3 GlobalTransactionInfo (com.arjuna.ArjunaOTS.GlobalTransactionInfo)2 UidCoordinator (com.arjuna.ArjunaOTS.UidCoordinator)2 ServerControlWrapper (com.arjuna.ats.internal.jts.interposition.ServerControlWrapper)2 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)2 ServerOSINestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.osi.ServerOSINestedAction)2