Search in sources :

Example 1 with ActionControl

use of com.arjuna.ArjunaOTS.ActionControl in project narayana by jbosstm.

the class OTSManager method destroyControl.

/**
 * Destroy the transaction control.
 */
public static void destroyControl(Control control) throws ActiveTransaction, ActiveThreads, BadControl, Destroyed, SystemException {
    if (control == null)
        throw new BadControl();
    ControlImple lCont = Helper.localControl(control);
    if (lCont != null) {
        destroyControl(lCont);
    } else {
        /*
	     * Just in case control is a top-level transaction, and has
	     * been registered with the reaper, we need to get it removed.
	     *
	     */
        Coordinator coord = null;
        try {
            coord = control.get_coordinator();
        } catch (Exception e) {
            // nothing else we can do!
            coord = null;
        }
        if (coord != null) {
            try {
                if (coord.is_top_level_transaction()) {
                    // wrap the control so it gets compared against reaper list entries using the correct test
                    PseudoControlWrapper wrapper = new PseudoControlWrapper(control);
                    TransactionReaper.transactionReaper().remove(wrapper);
                }
            } catch (Exception e) {
            }
            coord = null;
        }
        if (jtsLogger.logger.isTraceEnabled()) {
            jtsLogger.logger.trace("OTS::destroyControl - remote control.");
        }
        /*
	     * Remote transaction, so memory management is different!
	     */
        ActionControl action = null;
        try {
            action = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(control);
            if (action == null)
                throw new BAD_PARAM();
        } catch (Exception e) {
            action = null;
        }
        if (action != null) {
            if (jtsLogger.logger.isTraceEnabled()) {
                jtsLogger.logger.trace("OTS::destroyControl - Arjuna control.");
            }
            /*
		 * Is an Arjuna control, so we can call destroy on it?
		 */
            action.destroy();
            action = null;
            control = null;
        } else {
            /*
		 * Just call release on the control.
		 *
		 * We could throw a BadControl exception, but
		 * what would that do for the programmer?
		 */
            control = null;
        }
    }
}
Also used : ActionControl(com.arjuna.ArjunaOTS.ActionControl) BAD_PARAM(org.omg.CORBA.BAD_PARAM) BadControl(com.arjuna.ArjunaOTS.BadControl) PseudoControlWrapper(com.arjuna.ats.internal.jts.PseudoControlWrapper) Coordinator(org.omg.CosTransactions.Coordinator) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) SystemException(org.omg.CORBA.SystemException)

Example 2 with ActionControl

use of com.arjuna.ArjunaOTS.ActionControl in project narayana by jbosstm.

the class ContextManagerUnitTest method testContextManager.

@Test
public void testContextManager() throws Exception {
    ContextManager manager = new ContextManager();
    assertEquals(manager.current(Thread.currentThread().getName()), null);
    assertEquals(manager.current(), null);
    OTSImpleManager.current().begin();
    manager.associate();
    OTSImpleManager.current().suspend();
    OTSImpleManager.current().begin();
    Control ct = OTSImpleManager.current().suspend();
    manager.addRemoteHierarchy(ct);
    manager.popAction();
    OTSImpleManager.current().suspend();
    OTSImpleManager.current().begin();
    ActionControl cont = (ActionControl) OTSImpleManager.current().getControlWrapper().getImple().getControl();
    manager.addActionControlHierarchy(cont);
    manager.purgeActions();
    OTSImpleManager.current().suspend();
    OTSImpleManager.current().begin();
    manager.addControlImpleHierarchy(OTSImpleManager.current().getControlWrapper().getImple());
    manager.purgeActions();
    OTSImpleManager.current().suspend();
}
Also used : Control(org.omg.CosTransactions.Control) ActionControl(com.arjuna.ArjunaOTS.ActionControl) ActionControl(com.arjuna.ArjunaOTS.ActionControl) ContextManager(com.arjuna.ats.internal.jts.context.ContextManager) Test(org.junit.Test)

Example 3 with ActionControl

use of com.arjuna.ArjunaOTS.ActionControl in project narayana by jbosstm.

the class ContextManager method addActionControlHierarchy.

/*
     * All OTSArjuna controls have a method for getting their parent.
     */
public final boolean addActionControlHierarchy(ActionControl cont) {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ContextManager::addActionControlHierarchy ()");
    }
    boolean isError = false;
    try {
        ActionControl actControl = cont;
        Control parentControl = actControl.getParentControl();
        Stack hier = new Stack();
        while (parentControl != null) {
            hier.push(new ControlWrapper(parentControl));
            actControl = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(parentControl);
            if (actControl != null)
                parentControl = actControl.getParentControl();
            else
                parentControl = null;
        }
        actControl = null;
        try {
            ControlWrapper wrapper = (ControlWrapper) hier.pop();
            while (wrapper != null) {
                pushAction(wrapper);
                wrapper = null;
                wrapper = (ControlWrapper) hier.pop();
            }
        } catch (EmptyStackException e) {
        }
    } catch (Exception e) {
        jtsLogger.i18NLogger.warn_context_genfail("ContextManager.addActionControlHierarchy", e);
        isError = true;
    }
    return isError;
}
Also used : EmptyStackException(java.util.EmptyStackException) ActionControl(com.arjuna.ArjunaOTS.ActionControl) Control(org.omg.CosTransactions.Control) ActionControl(com.arjuna.ArjunaOTS.ActionControl) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) SystemException(org.omg.CORBA.SystemException) EmptyStackException(java.util.EmptyStackException) Stack(java.util.Stack)

Example 4 with ActionControl

use of com.arjuna.ArjunaOTS.ActionControl 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 5 with ActionControl

use of com.arjuna.ArjunaOTS.ActionControl 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)

Aggregations

ActionControl (com.arjuna.ArjunaOTS.ActionControl)5 SystemException (org.omg.CORBA.SystemException)4 Control (org.omg.CosTransactions.Control)4 BAD_PARAM (org.omg.CORBA.BAD_PARAM)3 BadControl (com.arjuna.ArjunaOTS.BadControl)2 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)2 Coordinator (org.omg.CosTransactions.Coordinator)2 UidCoordinator (com.arjuna.ArjunaOTS.UidCoordinator)1 TxControl (com.arjuna.ats.arjuna.coordinator.TxControl)1 PseudoControlWrapper (com.arjuna.ats.internal.jts.PseudoControlWrapper)1 ContextManager (com.arjuna.ats.internal.jts.context.ContextManager)1 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)1 EmptyStackException (java.util.EmptyStackException)1 Stack (java.util.Stack)1 Test (org.junit.Test)1 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)1 OBJECT_NOT_EXIST (org.omg.CORBA.OBJECT_NOT_EXIST)1 UNKNOWN (org.omg.CORBA.UNKNOWN)1 UserException (org.omg.CORBA.UserException)1 InvalidControl (org.omg.CosTransactions.InvalidControl)1