Search in sources :

Example 36 with Coordinator

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

the class ContextClientRequestInterceptorImpl method send_request.

public void send_request(ClientRequestInfo request_info) throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ContextClientRequestInterceptorImpl::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 {
                _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;
            String stringRef = 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_context_invalidparam());
            } else
                threadId = ThreadUtil.getThreadId();
            if (threadId != null) {
                ControlWrapper theControl = OTSImpleManager.current().contextManager().current(threadId);
                if (theControl != null) {
                    try {
                        Coordinator theCoordinator = theControl.get_coordinator();
                        if (theCoordinator != null) {
                            stringRef = ORBManager.getORB().orb().object_to_string(theCoordinator);
                        } else {
                            problem = true;
                        }
                    } catch (Unavailable e) {
                        problem = true;
                    }
                    theControl = null;
                } else
                    problem = true;
            } else
                problem = true;
            if (problem) {
                if (InterceptorInfo.getNeedTranContext())
                    throw new TRANSACTION_REQUIRED();
                else
                    stringRef = null;
            }
            if (stringRef != null) {
                Any data = ORBManager.getORB().orb().create_any();
                data.insert_string(stringRef);
                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) {
            jtsLogger.i18NLogger.warn_orbspecific_jacorb_interceptors_context_error(ex);
            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 : 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 37 with Coordinator

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

the class RecoveredTransaction method addResourceRecord.

/**
 * Allows a new Resource to be added to the transaction. Typically this is
 * used to replace a Resource that has failed and cannot be recovered on
 * it's original IOR.
 */
public void addResourceRecord(Uid rcUid, Resource r) {
    Coordinator coord = null;
    AbstractRecord corbaRec = createOTSRecord(true, r, coord, rcUid);
    addRecord(corbaRec);
}
Also used : AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) Coordinator(org.omg.CosTransactions.Coordinator)

Example 38 with Coordinator

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

the class SynchTest method test.

@Test
public void test() {
    org.omg.CosTransactions.Status status = Status.StatusUnknown;
    tranobject_i localObject = null;
    demosync sync = null;
    ORB myORB = null;
    RootOA myOA = null;
    try {
        ServerORB orb = new ServerORB();
        myORB = orb.getORB();
        myOA = orb.getOA();
        Control myControl = null;
        org.omg.CosTransactions.Current current = OTSManager.get_current();
        Coordinator coord = null;
        sync = new demosync();
        localObject = new tranobject_i();
        current.begin();
        myControl = current.get_control();
        coord = myControl.get_coordinator();
        coord.register_resource(localObject.getReference());
        coord.register_synchronization(sync.getReference());
        try {
            current.commit(true);
        } catch (TRANSACTION_ROLLEDBACK e1) {
            System.out.println("Transaction rolledback");
        }
        try {
            status = coord.get_status();
        } catch (SystemException ex) {
            // assume reference no longer valid!
            status = Status.StatusUnknown;
        }
    } catch (UserException e1) {
        fail("Caught UserException: " + e1);
        e1.printStackTrace();
    } catch (SystemException e2) {
        fail("Caught SystemException: " + e2);
        e2.printStackTrace();
    }
    System.out.print("Final action status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(status));
    System.out.println("\nTest completed successfully.");
    myOA.shutdownObject(sync);
    myOA.shutdownObject(localObject);
    myOA.destroy();
    myORB.shutdown();
}
Also used : com.hp.mwtests.ts.jts.orbspecific.resources.tranobject_i(com.hp.mwtests.ts.jts.orbspecific.resources.tranobject_i) com.hp.mwtests.ts.jts.orbspecific.resources.demosync(com.hp.mwtests.ts.jts.orbspecific.resources.demosync) RootOA(com.arjuna.orbportability.RootOA) Coordinator(org.omg.CosTransactions.Coordinator) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Control(org.omg.CosTransactions.Control) SystemException(org.omg.CORBA.SystemException) Status(org.omg.CosTransactions.Status) UserException(org.omg.CORBA.UserException) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 39 with Coordinator

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

the class ExplicitInterposition method registerTransaction.

/**
 * Perform interposition with the specified transaction.
 */
public final synchronized void registerTransaction(Control action) throws InterpositionFailed, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ExplicitInterposition::registerTransaction ( Control action )");
    }
    if (_inUse) {
        jtsLogger.i18NLogger.warn_excalledagain("ExplicitInterposition.unregisterTransaction");
        throw new InterpositionFailed();
    }
    boolean registerNull = false;
    if (action != null) {
        try {
            Coordinator coord = action.get_coordinator();
            if (coord != null) {
                PropagationContext ctx = coord.get_txcontext();
                if (ctx != null) {
                    try {
                        registerTransaction(ctx);
                        ctx = null;
                    } catch (Exception e) {
                        e.printStackTrace();
                        ctx = null;
                        throw new InterpositionFailed(e.toString());
                    }
                } else
                    registerNull = true;
                coord = null;
            } else
                registerNull = true;
        } catch (Exception e) {
            e.printStackTrace();
            throw new InterpositionFailed(e.toString());
        }
    } else {
        _inUse = true;
        registerNull = true;
    }
    if (registerNull) {
        try {
            OTSImpleManager.current().resume((Control) null);
        } catch (Exception e) {
            e.printStackTrace();
            throw new InterpositionFailed(e.toString());
        }
    }
}
Also used : InterpositionFailed(com.arjuna.ArjunaOTS.InterpositionFailed) PropagationContext(org.omg.CosTransactions.PropagationContext) Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException)

Example 40 with Coordinator

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

the class TopLevelTransaction method finalize.

public void finalize() {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("TopLevelTransaction.finalize ()");
    }
    if (_originalTransaction != null) {
        String name = null;
        Coordinator coord = null;
        try {
            coord = _originalTransaction.get_coordinator();
            if (coord != null) {
                name = coord.get_transaction_name();
            }
        } catch (Exception e) {
        }
        coord = null;
        jtsLogger.i18NLogger.warn_extensions_tltnestedscope(((name != null) ? name : "UNKNOWN"));
        name = null;
        _originalTransaction = null;
    }
    super.finalize();
}
Also used : Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException)

Aggregations

Coordinator (org.omg.CosTransactions.Coordinator)47 SystemException (org.omg.CORBA.SystemException)32 UNKNOWN (org.omg.CORBA.UNKNOWN)15 Control (org.omg.CosTransactions.Control)14 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)13 BAD_PARAM (org.omg.CORBA.BAD_PARAM)12 Unavailable (org.omg.CosTransactions.Unavailable)11 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)10 Terminator (org.omg.CosTransactions.Terminator)10 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)9 UidCoordinator (com.arjuna.ArjunaOTS.UidCoordinator)6 Uid (com.arjuna.ats.arjuna.common.Uid)6 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)6 ORB (com.arjuna.orbportability.ORB)6 Any (org.omg.CORBA.Any)6 TRANSACTION_REQUIRED (org.omg.CORBA.TRANSACTION_REQUIRED)6 TransactionalObject (org.omg.CosTransactions.TransactionalObject)6 ServiceContext (org.omg.IOP.ServiceContext)6 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)5 PropagationContext (org.omg.CosTransactions.PropagationContext)5