Search in sources :

Example 1 with ControlImple

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

the class ExtendedResourceRecord method nestedCommit.

public int nestedCommit() {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ExtendedResourceRecord::nestedCommit() for " + order());
    }
    int o = TwoPhaseOutcome.FINISH_ERROR;
    try {
        resourceHandle().commit_subtransaction(_parentCoordHandle);
        /*
			 * Now release the parent as it is about to be destroyed anyway.
			 */
        _parentCoordHandle = null;
        if (_currentTransaction != null) {
            /*
				 * Now change our notion of our parent for subsequent nested
				 * transaction commits. We were passed a reference to the
				 * current transaction, so we can just ask it for it's parent.
				 * If it doesn't have one, then generate an error.
				 */
            _currentTransaction = (ArjunaTransactionImple) _currentTransaction.parent();
            ControlImple control = ((_currentTransaction == null) ? null : _currentTransaction.getControlHandle());
            if (control != null) {
                _parentCoordHandle = control.get_coordinator();
                control = null;
                o = TwoPhaseOutcome.FINISH_OK;
            } else {
                jtsLogger.i18NLogger.warn_resources_errnoparent("ExtendedResourceRecord.nestedCommit");
                o = TwoPhaseOutcome.FINISH_ERROR;
            }
        } else {
            jtsLogger.i18NLogger.warn_resources_noparent(get_uid());
            o = TwoPhaseOutcome.FINISH_ERROR;
        }
    } catch (Exception e) {
        jtsLogger.i18NLogger.warn_resources_errgenerr("ExtendedResourceRecord.nestedCommit", e);
        o = TwoPhaseOutcome.FINISH_ERROR;
    }
    return o;
}
Also used : ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException)

Example 2 with ControlImple

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

the class OTSManager method destroyControl.

/**
 * Destroy the transaction control.
 */
public static void destroyControl(Control control) throws ActiveTransaction, ActiveThreads, BadControl, Destroyed, SystemException {
    if (control == null)
        throw new BadControl();
    ControlImple lCont = Helper.localControl(control);
    if (lCont != null) {
        destroyControl(lCont);
    } else {
        /*
	     * Just in case control is a top-level transaction, and has
	     * been registered with the reaper, we need to get it removed.
	     *
	     */
        Coordinator coord = null;
        try {
            coord = control.get_coordinator();
        } catch (Exception e) {
            // nothing else we can do!
            coord = null;
        }
        if (coord != null) {
            try {
                if (coord.is_top_level_transaction()) {
                    // wrap the control so it gets compared against reaper list entries using the correct test
                    PseudoControlWrapper wrapper = new PseudoControlWrapper(control);
                    TransactionReaper.transactionReaper().remove(wrapper);
                }
            } catch (Exception e) {
            }
            coord = null;
        }
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("OTS::destroyControl - remote control.");
        }
        /*
	     * Remote transaction, so memory management is different!
	     */
        ActionControl action = null;
        try {
            action = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(control);
            if (action == null)
                throw new BAD_PARAM();
        } catch (Exception e) {
            action = null;
        }
        if (action != null) {
            if (jtsLogger.logger.isTraceEnabled()) {
                jtsLogger.logger.trace("OTS::destroyControl - Arjuna control.");
            }
            /*
		 * Is an Arjuna control, so we can call destroy on it?
		 */
            action.destroy();
            action = null;
            control = null;
        } else {
            /*
		 * Just call release on the control.
		 *
		 * We could throw a BadControl exception, but
		 * what would that do for the programmer?
		 */
            control = null;
        }
    }
}
Also used : ActionControl(com.arjuna.ArjunaOTS.ActionControl) BAD_PARAM(org.omg.CORBA.BAD_PARAM) BadControl(com.arjuna.ArjunaOTS.BadControl) PseudoControlWrapper(com.arjuna.ats.internal.jts.PseudoControlWrapper) Coordinator(org.omg.CosTransactions.Coordinator) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) SystemException(org.omg.CORBA.SystemException)

Example 3 with ControlImple

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

the class Helper method localControl.

public static final ControlImple localControl(org.omg.CosTransactions.Control control) {
    if (control == null)
        return null;
    if (control instanceof ControlImple)
        return (ControlImple) control;
    try {
        UidCoordinator uidCoord = Helper.getUidCoordinator(control);
        if (uidCoord != null) {
            Uid u = Helper.getUid(uidCoord);
            ControlImple toReturn = null;
            uidCoord = null;
            if (ControlImple.allControls != null) {
                synchronized (ControlImple.allControls) {
                    toReturn = (ControlImple) ControlImple.allControls.get(u);
                }
            }
            if (toReturn == null) {
                if (ServerControl.allServerControls != null) {
                    synchronized (ServerControl.allServerControls) {
                        toReturn = (ControlImple) ServerControl.allServerControls.get(u);
                    }
                }
            }
            u = null;
            return toReturn;
        } else
            throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
    } 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) BAD_PARAM(org.omg.CORBA.BAD_PARAM) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple)

Example 4 with ControlImple

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

the class TransactionFactoryUnitTest method testContext.

@Test
public void testContext() throws Exception {
    TransactionFactoryImple factory = new TransactionFactoryImple("test");
    ControlImple tx = factory.createLocal(1000);
    org.omg.CosTransactions.otid_t txId = Utility.uidToOtid(tx.get_uid());
    Uid theUid = Utility.otidToUid(txId);
    assertEquals(theUid, tx.get_uid());
    // no state in OS yet!
    assertEquals(factory.getOSStatus(tx.get_uid()), org.omg.CosTransactions.Status.StatusNoTransaction);
    PropagationContext ctx = tx.get_coordinator().get_txcontext();
    Control cont = factory.recreate(ctx);
    String toString = Utility.getHierarchy(ctx);
    System.out.println(toString);
    assertTrue(toString != null);
    assertTrue(toString.length() > 1);
    assertTrue(Utility.getUid(cont).equals(tx.get_uid()));
    try {
        tx.getImplHandle().rollback();
    } catch (final Throwable ex) {
    }
}
Also used : CosTransactions.otid_t(org.omg.CosTransactions.otid_t) Uid(com.arjuna.ats.arjuna.common.Uid) Control(org.omg.CosTransactions.Control) PropagationContext(org.omg.CosTransactions.PropagationContext) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Example 5 with ControlImple

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

the class OSIInterpositionUnitTest method test.

@Test
public void test() throws Exception {
    OTSImpleManager.current().begin();
    PropagationContext ctx = OTSImpleManager.current().get_control().get_coordinator().get_txcontext();
    OSIInterpositionCreator creator = new OSIInterpositionCreator();
    Control cnt = creator.recreate(ctx);
    ControlImple impl = creator.recreateLocal(ctx);
    assertTrue(cnt != null);
    assertTrue(impl != null);
    OTSImpleManager.current().rollback();
}
Also used : OSIInterpositionCreator(com.arjuna.ats.internal.jts.interposition.resources.osi.OSIInterpositionCreator) Control(org.omg.CosTransactions.Control) PropagationContext(org.omg.CosTransactions.PropagationContext) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

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