Search in sources :

Example 1 with PropagationContext

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

the class InterpositionClientRequestInterceptorImpl method send_request.

public void send_request(ClientRequestInfo request_info) throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        trace_request("send_request", request_info);
    }
    if (systemCall(request_info))
        return;
    final boolean otsAlwaysPropagate = InterceptorInfo.getAlwaysPropagate();
    try {
        if (!otsAlwaysPropagate) {
            TransactionalObject ptr = TransactionalObjectHelper.narrow(request_info.target());
            if (ptr == null)
                throw new BAD_PARAM();
        } else {
            /**
             * If the value is not null then we are currently in use *
             */
            if (_inUse.get() != null) {
                return;
            } else {
                /**
                 * Set the flag *
                 */
                _inUse.set(_inUse);
            }
        }
        try {
            /*
		 * We get back an Any, which contains a key which we must
		 * now use to get the actual transaction context. This saves
		 * use having to pack and unpack the context every time it
		 * changes, even if we don't then make a remote invocation.
		 */
            Any localData = request_info.get_slot(_localSlot);
            String threadId = null;
            boolean problem = false;
            Any data = null;
            if (localData != null && (localData.type().kind().value() != TCKind._tk_null)) {
                if ((threadId = localData.extract_string()) == null)
                    throw new UNKNOWN(jtsLogger.i18NLogger.get_orbspecific_jacorb_interceptors_interposition_invalidparam());
            } else
                threadId = ThreadUtil.getThreadId();
            if (threadId != null) {
                ControlWrapper theControl = OTSImpleManager.systemCurrent().contextManager().current(threadId);
                if (theControl != null) {
                    try {
                        Coordinator theCoordinator = theControl.get_coordinator();
                        PropagationContext ctx = null;
                        if (theCoordinator != null) {
                            ctx = theCoordinator.get_txcontext();
                            data = packPropagationContext(ctx);
                            theCoordinator = null;
                        } else
                            throw new Unavailable();
                    } catch (Unavailable ex) {
                        /*
			     * We may have to make calls during
			     * commit (e.g., after_completion)
			     * which are valid, but which will get
			     * Unavailable.
			     */
                        problem = true;
                    }
                } else
                    problem = true;
            } else
                problem = true;
            if (problem) {
                if (InterceptorInfo.getNeedTranContext())
                    throw new TRANSACTION_REQUIRED();
            }
            if (data != null) {
                byte[] octets = _codec.encode_value(data);
                ServiceContext service_context = new ServiceContext(OTSManager.serviceId, octets);
                request_info.add_request_service_context(service_context, true);
            }
        } catch (SystemException e) {
            throw e;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new UNKNOWN(ex.toString());
        } finally {
            /**
             * If we are set to always propagate then ensure we clear the inuse flag *
             */
            if (otsAlwaysPropagate) {
                _inUse.set(null);
            }
        }
    } catch (BAD_PARAM ex) {
    // narrow failed, so not a transactional object.
    } catch (OBJECT_NOT_EXIST ex) {
    }
}
Also used : PropagationContext(org.omg.CosTransactions.PropagationContext) ServiceContext(org.omg.IOP.ServiceContext) BAD_PARAM(org.omg.CORBA.BAD_PARAM) Coordinator(org.omg.CosTransactions.Coordinator) Any(org.omg.CORBA.Any) SystemException(org.omg.CORBA.SystemException) Unavailable(org.omg.CosTransactions.Unavailable) SystemException(org.omg.CORBA.SystemException) OBJECT_NOT_EXIST(org.omg.CORBA.OBJECT_NOT_EXIST) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) TransactionalObject(org.omg.CosTransactions.TransactionalObject) UNKNOWN(org.omg.CORBA.UNKNOWN) TRANSACTION_REQUIRED(org.omg.CORBA.TRANSACTION_REQUIRED)

Example 2 with PropagationContext

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

use of org.omg.CosTransactions.PropagationContext 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)

Example 4 with PropagationContext

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

the class OTIDMapUnitTest method test.

@Test
public void test() throws Exception {
    OTSImpleManager.current().begin();
    PropagationContext ctx = OTSImpleManager.current().get_control().get_coordinator().get_txcontext();
    otid_t tid = ctx.current.otid;
    assertTrue(OTIDMap.find(tid).notEquals(Uid.nullUid()));
    assertTrue(OTIDMap.remove(OTIDMap.find(tid)));
    OTSImpleManager.current().rollback();
}
Also used : PropagationContext(org.omg.CosTransactions.PropagationContext) CosTransactions.otid_t(org.omg.CosTransactions.otid_t) Test(org.junit.Test)

Example 5 with PropagationContext

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

the class ArjunaInterpositionUnitTest method test.

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

Aggregations

PropagationContext (org.omg.CosTransactions.PropagationContext)14 Test (org.junit.Test)8 SystemException (org.omg.CORBA.SystemException)6 Control (org.omg.CosTransactions.Control)6 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)5 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)5 Coordinator (org.omg.CosTransactions.Coordinator)5 BAD_PARAM (org.omg.CORBA.BAD_PARAM)4 Any (org.omg.CORBA.Any)3 TRANSACTION_REQUIRED (org.omg.CORBA.TRANSACTION_REQUIRED)3 UNKNOWN (org.omg.CORBA.UNKNOWN)3 TransactionalObject (org.omg.CosTransactions.TransactionalObject)3 Unavailable (org.omg.CosTransactions.Unavailable)3 ServiceContext (org.omg.IOP.ServiceContext)3 ActionControl (com.arjuna.ArjunaOTS.ActionControl)2 Uid (com.arjuna.ats.arjuna.common.Uid)2 InterpositionCreator (com.arjuna.ats.internal.jts.interposition.resources.arjuna.InterpositionCreator)2 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)2 CosTransactions.otid_t (org.omg.CosTransactions.otid_t)2 BadControl (com.arjuna.ArjunaOTS.BadControl)1