Search in sources :

Example 31 with ControlWrapper

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

the class CurrentImple method rollback.

/**
 * If another thread has already terminated the transaction then: (i) if it
 * rolled back, we do nothing - could throw TransactionRequired of
 * INVALID_TRANSACTION, or NoTransaction. Probably not NoTransaction, since
 * it would be better to distinguish between the situation where the
 * transaction has already been terminated and there really is no
 * transaction for this thread. (ii) if it committed, we throw
 * INVALID_TRANSACTION.
 */
public void rollback() throws NoTransaction, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("CurrentImple::rollback ()");
    }
    ControlWrapper currentAction = _theManager.current();
    if (currentAction != null) {
        ThreadAssociationControl.updateAssociation(currentAction, TX_ABORTED);
        try {
            currentAction.rollback();
            _theManager.popAction();
        } catch (INVALID_TRANSACTION e1) {
            /*
				 * If transaction has already terminated, then throw
				 * INVALID_TRANSACTION. Differentiates between this stat and not
				 * actually having a transaction associated with the thread.
				 */
            _theManager.popAction();
            throw e1;
        } catch (SystemException e2) {
            _theManager.popAction();
            throw e2;
        } catch (Unavailable e) {
            /*
				 * If no terminator then not allowed!
				 */
            _theManager.popAction();
            throw new INVALID_TRANSACTION();
        }
    } else
        throw new NoTransaction();
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) SystemException(org.omg.CORBA.SystemException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) SubtransactionsUnavailable(org.omg.CosTransactions.SubtransactionsUnavailable) Unavailable(org.omg.CosTransactions.Unavailable)

Example 32 with ControlWrapper

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

the class CurrentImple method get_status.

public org.omg.CosTransactions.Status get_status() throws SystemException {
    ControlWrapper currentAction = _theManager.current();
    org.omg.CosTransactions.Status stat = ((currentAction == null) ? org.omg.CosTransactions.Status.StatusNoTransaction : currentAction.get_status());
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("CurrentImple::get_status - returning " + Utility.stringStatus(stat));
    }
    return stat;
}
Also used : ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper)

Example 33 with ControlWrapper

use of com.arjuna.ats.internal.jts.ControlWrapper 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 34 with ControlWrapper

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

the class ContextManager method createProxy.

public final ControlWrapper createProxy(org.omg.CORBA.Any ctx) throws SystemException {
    String stringRef = null;
    try {
        stringRef = ctx.extract_string();
        if (stringRef.startsWith(IORTag)) {
            org.omg.CORBA.Object obj = ORBManager.getORB().orb().string_to_object(stringRef);
            Coordinator theCoordinator = org.omg.CosTransactions.CoordinatorHelper.narrow(obj);
            if (theCoordinator == null)
                throw new BAD_PARAM();
            return new ControlWrapper(TransactionFactoryImple.createProxy(theCoordinator, null));
        } else
            return null;
    } catch (BAD_PARAM e1) {
        jtsLogger.i18NLogger.warn_context_genfail("ContextManager " + stringRef, e1);
    } catch (Exception e2) {
        jtsLogger.i18NLogger.warn_context_genfail("ContextManager", e2);
        throw new UNKNOWN(e2.toString());
    }
    return null;
}
Also used : ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) BAD_PARAM(org.omg.CORBA.BAD_PARAM) UNKNOWN(org.omg.CORBA.UNKNOWN) Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException) EmptyStackException(java.util.EmptyStackException)

Example 35 with ControlWrapper

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

the class InterpositionServerRequestInterceptorImpl method suspendContext.

/*
     * If there is a thread id associated with PICurrent then it will
     * have been placed there by a server-side thread which executed in
     * the application object and needed to associate an imported
     * transaction with itself. In which case we need to do the
     * equivalent of a suspend to remove the thread from Current and
     * from the current transaction.
     */
private void suspendContext(ServerRequestInfo request_info) throws SystemException, InvalidSlot {
    if (jtsLogger.logger.isTraceEnabled()) {
        trace_request("suspendContext", request_info);
    }
    Any data = request_info.get_slot(_dataSlot);
    if ((data != null) && (data.type().kind().value() != TCKind._tk_null)) {
        String threadId = null;
        try {
            if ((threadId = data.extract_string()) != null) {
                // ControlWrapper ctx = OTSImpleManager.systemCurrent().contextManager().popAction(threadId);
                ControlWrapper ctx = OTSImpleManager.current().contextManager().popAction(threadId);
                // OTSImpleManager.systemCurrent().contextManager().purgeActions(threadId);
                OTSImpleManager.current().contextManager().purgeActions(threadId);
            }
        } catch (BAD_OPERATION bex) {
        // not a string, so still a pgcts
        }
        request_info.set_slot(_dataSlot, null);
    }
}
Also used : ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION) Any(org.omg.CORBA.Any)

Aggregations

ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)44 SystemException (org.omg.CORBA.SystemException)22 UNKNOWN (org.omg.CORBA.UNKNOWN)14 Any (org.omg.CORBA.Any)13 Coordinator (org.omg.CosTransactions.Coordinator)10 Unavailable (org.omg.CosTransactions.Unavailable)10 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)8 BAD_PARAM (org.omg.CORBA.BAD_PARAM)8 EmptyStackException (java.util.EmptyStackException)7 Control (org.omg.CosTransactions.Control)7 Stack (java.util.Stack)6 TRANSACTION_REQUIRED (org.omg.CORBA.TRANSACTION_REQUIRED)6 TransactionalObject (org.omg.CosTransactions.TransactionalObject)6 ServiceContext (org.omg.IOP.ServiceContext)6 PropagationContext (org.omg.CosTransactions.PropagationContext)5 SubtransactionsUnavailable (org.omg.CosTransactions.SubtransactionsUnavailable)4 ActionControl (com.arjuna.ArjunaOTS.ActionControl)3 TransactionImple (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple)3 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)3 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)3