Search in sources :

Example 46 with Control

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

the class Test28 method main.

public static void main(String[] args) {
    try {
        ORBInterface.initORB(args, null);
        OAInterface.initOA();
        boolean correct = true;
        Current current = OTS.get_current();
        current.begin();
        Control control = current.get_control();
        current.rollback();
        try {
            current.resume(control);
        } catch (InvalidControl invalidControl) {
            System.err.println("Failed to resume rolled-back transaction!");
            correct = false;
        }
        if (correct) {
            System.out.println("Passed");
        } else {
            System.out.println("Failed");
        }
    } catch (Exception exception) {
        System.out.println("Failed");
        System.err.println("Test28.main: " + exception);
        exception.printStackTrace(System.err);
    }
    try {
        OAInterface.shutdownOA();
        ORBInterface.shutdownORB();
    } catch (Exception exception) {
        System.err.println("Test28.main: " + exception);
        exception.printStackTrace(System.err);
    }
}
Also used : Control(org.omg.CosTransactions.Control) InvalidControl(org.omg.CosTransactions.InvalidControl) Current(org.omg.CosTransactions.Current) InvalidControl(org.omg.CosTransactions.InvalidControl)

Example 47 with Control

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

the class BaseTransaction method checkTransactionState.

/**
 * Called when we want to make sure this thread does not already have a
 * transaction associated with it.
 */
final void checkTransactionState() throws IllegalStateException, javax.transaction.SystemException {
    try {
        Control cont = OTSManager.get_current().get_control();
        if (cont != null) {
            Coordinator coord = cont.get_coordinator();
            if (coord != null) {
                if ((coord.get_status() == org.omg.CosTransactions.Status.StatusActive) && (!_supportSubtransactions)) {
                    throw new IllegalStateException("BaseTransaction.checkTransactionState - " + jtaxLogger.i18NLogger.get_jtax_transaction_jts_alreadyassociated());
                }
            }
            cont = null;
        }
    } catch (org.omg.CORBA.SystemException e1) {
        javax.transaction.SystemException systemException = new javax.transaction.SystemException(e1.toString());
        systemException.initCause(e1);
        throw systemException;
    } catch (org.omg.CosTransactions.Unavailable e2) {
    // ok, no transaction currently associated with thread.
    } catch (NullPointerException ex) {
    // ok, no transaction currently associated with thread.
    }
}
Also used : Coordinator(org.omg.CosTransactions.Coordinator) Control(org.omg.CosTransactions.Control)

Example 48 with Control

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

the class CurrentImple method resume.

/**
 * To support checked transactions we can only resume if the action is local
 * or we received it implicitly.
 *
 * If the control refers to a nested transaction then we must recreate the
 * entire hierarchy, i.e., the effect of a suspend/resume on the same
 * control should be the same as never calling suspend in the first place.
 *
 * If the control is for a local transaction then it is simple to recreate
 * the hierarchy. Otherwise we rely upon the PropagationContext to recreate
 * it.
 *
 * If this control is a "proxy" then create a new proxy instance, so we can
 * delete proxies whenever suspend is called.
 *
 * Should check if "new" transaction is not actually the current one anyway.
 * If so, just return. The spec. doesn't mention what to do in this case, so
 * for now we go to the overhead of the work regardless.
 */
public void resume(Control which) throws InvalidControl, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("CurrentImple::resume ( " + which + " )");
    }
    /*
		 * We must now "forget" any current transaction information. This is
		 * because when we end this transaction we must be associated with no
		 * transaction.
		 */
    _theManager.purgeActions();
    if (// if null then return
    which == null) {
        ThreadAssociationControl.updateAssociation(null, TX_RESUMED);
        return;
    }
    /*
		 * Must duplicate because it is an 'in' parameter which we want to keep.
		 */
    org.omg.CosTransactions.Control cont = which;
    boolean invalidControl = false;
    try {
        Coordinator coord = cont.get_coordinator();
        if (!coord.is_top_level_transaction()) {
            /*
				 * Is the Control an ActionControl? If so then it has methods to
				 * allow us to get the parent directly. Otherwise, rely on the
				 * PropagationContext.
				 */
            ActionControl actControl = null;
            try {
                actControl = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(cont);
                if (actControl == null)
                    throw new BAD_PARAM();
            } catch (Exception e) {
                /*
					 * Not an ActionControl.
					 */
                actControl = null;
            }
            if (actControl != null) {
                invalidControl = _theManager.addActionControlHierarchy(actControl);
            } else {
                invalidControl = _theManager.addRemoteHierarchy(cont);
            }
        }
        coord = null;
    } catch (OBJECT_NOT_EXIST one) {
    // throw new InvalidControl();
    } catch (// JacORB 1.4.5 bug
    UNKNOWN ue) {
    } catch (// JacORB 2.0 beta 2 bug
    org.omg.CORBA.OBJ_ADAPTER oae) {
    } catch (SystemException sysEx) {
        throw new InvalidControl();
    } catch (UserException usrEx) {
        throw new InvalidControl();
    } catch (NullPointerException npx) {
        throw new InvalidControl();
    } catch (Exception ex) {
        throw new BAD_OPERATION("CurrentImple.resume: " + ex.toString());
    }
    try {
        if (!invalidControl) {
            ControlWrapper wrap = new ControlWrapper(cont);
            ThreadAssociationControl.updateAssociation(wrap, TX_RESUMED);
            _theManager.pushAction(wrap);
        }
    } catch (NullPointerException npx) {
        invalidControl = true;
    }
    cont = null;
    if (invalidControl)
        throw new InvalidControl();
}
Also used : Control(org.omg.CosTransactions.Control) BAD_PARAM(org.omg.CORBA.BAD_PARAM) Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) InvalidControl(org.omg.CosTransactions.InvalidControl) ActionControl(com.arjuna.ArjunaOTS.ActionControl) OBJECT_NOT_EXIST(org.omg.CORBA.OBJECT_NOT_EXIST) SystemException(org.omg.CORBA.SystemException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) UNKNOWN(org.omg.CORBA.UNKNOWN) UserException(org.omg.CORBA.UserException) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION)

Example 49 with Control

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

the class ArjunaTransactionImple method propagationContext.

/*
	 * The caller should delete the context.
	 *
	 * The propagation context is specified on a per client thread basis.
	 * Therefore, at the server side we must maintain a hierarchy for each
	 * thread. However, the server cannot simply tear down this hierarchy
	 * whenever it receives a completely new one from the same thread, since the
	 * OTS lets a thread suspend/resume contexts at will. Potential for memory
	 * leaks in C++ version, but not Java!!
	 *
	 * Currently we assume that the hierarchy will be JBoss transactions so we
	 * can get the parents of transactions. If it is not then we could simply
	 * just call get_txcontext on the control!
	 */
private final PropagationContext propagationContext() throws Unavailable, Inactive, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::propagationContext for " + get_uid());
    }
    String theUid = null;
    Control currentControl = controlHandle.getControl();
    PropagationContext context = new PropagationContext();
    // most transactions will be top-level
    int sequenceThreshold = 1;
    int sequenceIncrement = 5;
    context.parents = null;
    context.current = new TransIdentity();
    // uughh!!
    context.implementation_specific_data = ORBManager.getORB().orb().create_any();
    /*
		 * Some ORBs (e.g., JBroker) don't like to pass round an unused Any,
		 * i.e., one which has only been created and had nothing put in it! So
		 * we have to put something in it!!
		 */
    context.implementation_specific_data.insert_short((short) 0);
    try {
        context.current.coord = controlHandle.get_coordinator();
        // will reset later!
        context.timeout = 0;
        if (ArjunaTransactionImple._propagateTerminator) {
            context.current.term = controlHandle.get_terminator();
        } else
            context.current.term = null;
    } catch (Exception e) {
        return null;
    }
    /*
		 * We send the Uid hierarchy as the otid_t part of the TransIdentity.
		 */
    // the sequence should do the memory management for us.
    theUid = controlHandle.get_uid().stringForm();
    context.current.otid = Utility.uidToOtid(theUid);
    context.current.otid.formatID = ArjunaTransactionImple._ipType;
    int index = 0;
    while (currentControl != null) {
        try {
            ActionControl control = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(currentControl);
            if (control != null) {
                /*
					 * Must be an Arjuna control.
					 */
                currentControl = control.getParentControl();
                if (currentControl != null) {
                    if (// first time
                    index == 0) {
                        // initial
                        context.parents = new TransIdentity[sequenceThreshold];
                        for (int ii = 0; ii < sequenceThreshold; ii++) context.parents[ii] = null;
                    }
                    context.parents[index] = new TransIdentity();
                    context.parents[index].coord = currentControl.get_coordinator();
                    if (ArjunaTransactionImple._propagateTerminator)
                        context.parents[index].term = currentControl.get_terminator();
                    else
                        context.parents[index].term = null;
                    /*
						 * Don't bother checking whether narrow works because we
						 * can't cope with mixed transaction types anyway! If we
						 * got here then the root transaction must be an Arjuna
						 * transaction, so the nested transactions *must* also
						 * be JBoss transactions!
						 */
                    UidCoordinator uidCoord = Helper.getUidCoordinator(context.parents[index].coord);
                    theUid = uidCoord.uid();
                    context.parents[index].otid = Utility.uidToOtid(theUid);
                    context.parents[index].otid.formatID = ArjunaTransactionImple._ipType;
                    theUid = null;
                    uidCoord = null;
                    index++;
                    if (index >= sequenceThreshold) {
                        sequenceThreshold = index + sequenceIncrement;
                        context.parents = resizeHierarchy(context.parents, index + sequenceIncrement);
                    }
                } else {
                    if (_propagateRemainingTimeout) {
                        long timeInMills = TransactionReaper.transactionReaper().getRemainingTimeoutMills(control);
                        context.timeout = (int) (timeInMills / 1000L);
                    } else {
                        context.timeout = TransactionReaper.transactionReaper().getTimeout(control);
                    }
                }
                control = null;
            } else
                throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
        } catch (SystemException e) {
            /*
				 * Not an Arjuna control!! Should not happen!!
				 */
            currentControl = null;
        } catch (Exception e) {
            e.printStackTrace();
            currentControl = null;
        }
    }
    try {
        context.parents = resizeHierarchy(context.parents, index);
    } catch (Exception e) {
        jtsLogger.i18NLogger.warn_orbspecific_coordinator_generror("ArjunaTransactionImple.resizeHierarchy", e);
        context = null;
    }
    return context;
}
Also used : TxControl(com.arjuna.ats.arjuna.coordinator.TxControl) Control(org.omg.CosTransactions.Control) ActionControl(com.arjuna.ArjunaOTS.ActionControl) BadControl(com.arjuna.ArjunaOTS.BadControl) ActionControl(com.arjuna.ArjunaOTS.ActionControl) UidCoordinator(com.arjuna.ArjunaOTS.UidCoordinator) PropagationContext(org.omg.CosTransactions.PropagationContext) SystemException(org.omg.CORBA.SystemException) TransIdentity(org.omg.CosTransactions.TransIdentity) BAD_PARAM(org.omg.CORBA.BAD_PARAM) SystemException(org.omg.CORBA.SystemException)

Example 50 with Control

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

Aggregations

Control (org.omg.CosTransactions.Control)103 Test (org.junit.Test)40 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)24 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)20 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)20 ORB (com.arjuna.orbportability.ORB)20 RootOA (com.arjuna.orbportability.RootOA)18 TransactionFactory (org.omg.CosTransactions.TransactionFactory)16 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)14 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)13 Coordinator (org.omg.CosTransactions.Coordinator)13 SystemException (org.omg.CORBA.SystemException)11 IntHolder (org.omg.CORBA.IntHolder)10 Current (org.omg.CosTransactions.Current)9 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)6 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)6 Services (com.arjuna.orbportability.Services)6 PropagationContext (org.omg.CosTransactions.PropagationContext)6 ActionControl (com.arjuna.ArjunaOTS.ActionControl)5 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)5