Search in sources :

Example 21 with ControlWrapper

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

the class ContextManager method current.

/**
 * Get the current transaction associated with the invoking thread. Do
 * not look in the PI thread data.
 *
 * Does not need to be synchronized since it is implicitly single-threaded.
 *
 * @return the context.
 */
public ControlWrapper current(String threadId) throws SystemException {
    Object arg = otsCurrent.get(threadId);
    ControlWrapper wrapper = null;
    if (arg != null) {
        try {
            Stack hier = (Stack) arg;
            return (ControlWrapper) hier.peek();
        } catch (EmptyStackException e) {
        }
    }
    return null;
}
Also used : EmptyStackException(java.util.EmptyStackException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) Stack(java.util.Stack)

Example 22 with ControlWrapper

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

the class ContextManager method addRemoteHierarchy.

/**
 * We could maintain a list of suspended action hierarchies and resume
 * the right one (and the right place!) given the control. However, this
 * can lead to memory leaks, since we never know when to remove this
 * hierarchy information. So, for now we simply rely on the propagation
 * context.
 */
public final boolean addRemoteHierarchy(Control cont) {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ContextManager::addRemoteHierarchy ()");
    }
    if (false) {
        pushAction(new ControlWrapper(cont));
        return true;
    } else {
        boolean isError = false;
        try {
            Coordinator coord = cont.get_coordinator();
            PropagationContext ctx = coord.get_txcontext();
            if (ctx != null) {
                /*
		     * Depth must be non-zero or we wouldn't be here!
		     */
                int depth = ctx.parents.length;
                for (int i = depth - 1; i >= 0; i--) {
                    /*
			 * No memory leak as we delete either when suspend
			 * is called, or the transaction is terminated.
			 */
                    Coordinator tmpCoord = ctx.parents[i].coord;
                    Terminator tmpTerm = ctx.parents[i].term;
                    Control theControl = TransactionFactoryImple.createProxy(tmpCoord, tmpTerm);
                    // takes care of thread/BasicAction for us.
                    pushAction(new ControlWrapper(theControl));
                }
                ctx = null;
            } else {
                /*
		     * If we can't get a propagation context then we cannot
		     * create the hierarchy!
		     */
                isError = true;
            }
            coord = null;
        } catch (Exception e) {
            isError = true;
        }
        return isError;
    }
}
Also used : Control(org.omg.CosTransactions.Control) ActionControl(com.arjuna.ArjunaOTS.ActionControl) PropagationContext(org.omg.CosTransactions.PropagationContext) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) Terminator(org.omg.CosTransactions.Terminator) Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException) EmptyStackException(java.util.EmptyStackException)

Example 23 with ControlWrapper

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

the class ContextManager method purgeActions.

public final void purgeActions(String threadId) {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ContextManager::purgeActions ()");
    }
    /*
	 * Don't do anything with these actions, i.e., do
	 * not commit/abort them. Just because this thread is
	 * finished with them does not mean other threads
	 * are!
	 */
    ControlWrapper ptr = popAction(threadId);
    while (ptr != null) {
        ptr = null;
        ptr = popAction(threadId);
    }
    while (ptr != null) ;
}
Also used : ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper)

Example 24 with ControlWrapper

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

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

the class PropagationContextManager method getTransactionPropagationContext.

/**
 * Return a transaction propagation context for the transaction currently
 * associated with the invoking thread, or <code>null</code> if the invoking
 * thread is not associated with a transaction.
 */
public Object getTransactionPropagationContext() {
    if (jbossatxLogger.logger.isTraceEnabled()) {
        jbossatxLogger.logger.trace("PropagationContextManager.getTransactionPropagationContext - called");
    }
    final String threadId = ThreadUtil.getThreadId();
    ControlWrapper theControl;
    if (threadId != null) {
        theControl = OTSImpleManager.current().contextManager().current(threadId);
    } else {
        theControl = OTSImpleManager.current().contextManager().current();
    }
    try {
        final PropagationContext cxt = theControl.get_coordinator().get_txcontext();
        PropagationContextWrapper pcw = new PropagationContextWrapper(cxt);
        if (jbossatxLogger.logger.isTraceEnabled()) {
            jbossatxLogger.logger.trace("PropagationContextManager.getTransactionPropagationContext() - returned tpc = " + pcw);
        }
        return pcw;
    } catch (Exception e) {
    }
    return null;
}
Also used : ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper)

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