Search in sources :

Example 21 with CurrentImple

use of com.arjuna.ats.internal.jts.orbspecific.CurrentImple 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 CurrentImple

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

the class OTSImpleManager method init.

private static final synchronized void init() {
    if (_current == null) {
        if (OTSImpleManager._theFactory == null) {
            /*
				 * Only check once, when the factory is first created.
				 */
            int resolver = Services.CONFIGURATION_FILE;
            boolean requireTransactionManager = false;
            if (jtsPropertyManager.getJTSEnvironmentBean().isTransactionManager()) {
                requireTransactionManager = true;
                String resolveMechanism = opPropertyManager.getOrbPortabilityEnvironmentBean().getResolveService();
                if (resolveMechanism.compareTo("NAME_SERVICE") == 0)
                    resolver = Services.NAME_SERVICE;
                else {
                    if (resolveMechanism.compareTo("BIND_CONNECT") == 0)
                        resolver = Services.BIND_CONNECT;
                }
            }
            if (requireTransactionManager) {
                try {
                    if (resolver != Services.BIND_CONNECT) {
                        String[] params = new String[1];
                        params[0] = Services.otsKind;
                        org.omg.CORBA.Object obj = ORBManager.getServices().getService(Services.transactionService, params, resolver);
                        params = null;
                        OTSImpleManager._theFactoryRef = org.omg.CosTransactions.TransactionFactoryHelper.narrow(obj);
                    } else {
                    }
                    if (OTSImpleManager._theFactoryRef == null)
                        throw new BAD_PARAM();
                } catch (InvalidName e1) {
                    jtsLogger.i18NLogger.warn_otsserverfailed(e1);
                    throw new FatalError(e1.toString(), e1);
                } catch (BAD_PARAM ex1) {
                    jtsLogger.i18NLogger.warn_otsserverfailed(ex1);
                    throw new FatalError(ex1.toString(), ex1);
                } catch (IOException e2) {
                    jtsLogger.i18NLogger.warn_otsservererror(e2);
                    throw new FatalError(e2.toString(), e2);
                } catch (SystemException e3) {
                    jtsLogger.i18NLogger.warn_otsservererror(e3);
                    throw new FatalError(e3.toString(), e3);
                } catch (UserException e4) {
                    jtsLogger.i18NLogger.warn_otsservererror(e4);
                    throw new FatalError(e4.toString(), e4);
                }
            } else {
                /* force to be local */
                OTSImpleManager._theFactory = new TransactionFactoryImple();
            }
        }
        if (OTSImpleManager._current == null) {
            try {
                OTSImpleManager._current = new CurrentImple();
                OTSImpleManager._currentRef = OTSImpleManager._current;
            } catch (Exception e) {
                OTSImpleManager._current = null;
                throw new com.arjuna.ats.arjuna.exceptions.FatalError("OTSImpleManager.current: " + e.toString(), e);
            }
        }
    }
}
Also used : BAD_PARAM(org.omg.CORBA.BAD_PARAM) FatalError(com.arjuna.ats.arjuna.exceptions.FatalError) IOException(java.io.IOException) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) IOException(java.io.IOException) FatalError(com.arjuna.ats.arjuna.exceptions.FatalError) InvalidName(org.omg.CORBA.ORBPackage.InvalidName) SystemException(org.omg.CORBA.SystemException) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) UserException(org.omg.CORBA.UserException)

Example 23 with CurrentImple

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

the class InterpositionThreadSetup method setup.

public void setup() {
    /*
	 * Simply getting (or trying to get) the current tx control
	 * will ensure that this thread is initialised properly. We
	 * have to do this because in a POA implementation the receiving
	 * thread may not be the same one which does the work, so we
	 * cannot do thread association at the interceptor level. We must
	 * do it when the invoked method actually gets called.
	 */
    CurrentImple curr = OTSImpleManager.current();
    /*
	 * Probably separate the underlying work out so that we can
	 * call that directly. No real harm at present since the hard
	 * work represents most of the overhead and has to be done
	 * anyway.
	 */
    curr.contextManager().associate();
}
Also used : CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple)

Example 24 with CurrentImple

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

the class ContextThreadSetup method setup.

public void setup() {
    /*
	 * Simply getting (or trying to get) the current tx control
	 * will ensure that this thread is initialised properly. We
	 * have to do this because in a POA implementation the receiving
	 * thread may not be the same one which does the work, so we
	 * cannot do thread association at the interceptor level. We must
	 * do it when the invoked method actually gets called.
	 */
    CurrentImple curr = OTSImpleManager.current();
    /*
	 * Probably separate the underlying work out so that we can
	 * call that directly. No real harm at present since the hard
	 * work represents most of the overhead and has to be done
	 * anyway.
	 */
    curr.contextManager().associate();
}
Also used : CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple)

Example 25 with CurrentImple

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

the class ContextThreadSetup method setup.

public void setup() {
    /*
	 * Simply getting (or trying to get) the current tx control
	 * will ensure that this thread is initialised properly. We
	 * have to do this because in a POA implementation the receiving
	 * thread may not be the same one which does the work, so we
	 * cannot do thread association at the interceptor level. We must
	 * do it when the invoked method actually gets called.
	 */
    CurrentImple curr = OTSImpleManager.current();
    /*
	 * Probably separate the underlying work out so that we can
	 * call that directly. No real harm at present since the hard
	 * work represents most of the overhead and has to be done
	 * anyway.
	 */
    curr.contextManager().associate();
}
Also used : CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple)

Aggregations

CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)47 Control (org.omg.CosTransactions.Control)14 SystemException (org.omg.CORBA.SystemException)12 ORB (com.arjuna.orbportability.ORB)9 RootOA (com.arjuna.orbportability.RootOA)9 IOException (java.io.IOException)7 Lock (com.arjuna.ats.txoj.Lock)6 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)6 Coordinator (org.omg.CosTransactions.Coordinator)6 Services (com.arjuna.orbportability.Services)5 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)5 ExplicitInterposition (com.arjuna.ats.jts.ExplicitInterposition)4 Test (org.junit.Test)4 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)3 TestException (com.hp.mwtests.ts.jts.exceptions.TestException)3 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)3 NoTransaction (org.omg.CosTransactions.NoTransaction)3 InterpositionFailed (com.arjuna.ArjunaOTS.InterpositionFailed)2 FatalError (com.arjuna.ats.arjuna.exceptions.FatalError)2 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)2