Search in sources :

Example 1 with ServerNestedAction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction in project narayana by jbosstm.

the class Interposition method checkHierarchy.

/*
     * In a single threaded environment we could walk down the hierarchy,
     * aborting any actions which are no longer valid, and creating any new
     * ones. However, in a multi-threaded environment, a thread can make a
     * call from any point in the client's hierarchy, and multiple client
     * threads can invoke the same server object. So, in general we cannot do
     * this optimisation. We must maintain the entire tree until portions of
     * it have explicitly been termined.
     *
     * Once we find the point in the new hierarchy which deviates from our
     * current representation, we begin to assemble a new subtree in much the
     * same way as we did for creating a completely new hierarchy.
     */
protected synchronized ControlImple checkHierarchy(ServerTopLevelAction hier, PropagationContext context) throws SystemException {
    ServerControl control = null;
    // top-level transaction
    ServerResource currentAction = hier;
    int depth = context.parents.length;
    // index of the new transactions in the hierarchy
    int differenceIndex = -1;
    if (depth == 0) {
        /*
	     * There are no transactions in the context other than the current
	     * transaction, which must therefore be top-level. We already have
	     * the control to return.
	     */
        // top-level transaction's control
        control = hier.control();
    } else {
        ServerResource nestedAction = null;
        for (// don't check depth-1 as it is current action!
        int i = depth - 2; // don't check depth-1 as it is current action!
        i >= 0; // don't check depth-1 as it is current action!
        i--) {
            nestedAction = currentAction.getChild(Utility.otidToUid(context.parents[i].otid));
            if (// point of difference, so stop trawling hierarchy
            nestedAction == null) {
                // remember for later so that we can add new actions.
                differenceIndex = i;
                break;
            } else {
                /*
		     * currentAction *always* points to the last known
		     * good transaction in our hierarchy.
		     */
                currentAction = nestedAction;
            }
        }
        if (differenceIndex != -1) {
            control = currentAction.control();
            Coordinator tmpCoord;
            Terminator tmpTerm;
            for (int j = differenceIndex; j >= 0; j--) {
                tmpCoord = context.parents[j].coord;
                tmpTerm = context.parents[j].term;
                control = ServerFactory.create_subtransaction(Utility.otidToUid(context.parents[j].otid), tmpCoord, tmpTerm, control);
                nestedAction = new ServerNestedAction(control);
                if (!nestedAction.valid()) {
                    try {
                        // does dispose as well!
                        ((ServerNestedAction) nestedAction).rollback();
                        nestedAction = null;
                    } catch (Exception e) {
                    }
                    throw new TRANSACTION_ROLLEDBACK();
                }
                currentAction.addChild((ServerNestedAction) nestedAction);
                currentAction = nestedAction;
            }
        } else {
        /*
		 * Hierarchies may be identical.
		 * Remember to check!
		 */
        }
        Uid currentUid = Utility.otidToUid(context.current.otid);
        /*
	     * currentAction points to the parent of the 'current'
	     * transaction, i.e., the last element in the TransIdentity
	     * structure. So, ask it if the sent hierarchy's child is
	     * one of its children.
	     */
        nestedAction = currentAction.getChild(currentUid);
        if (nestedAction == null) {
            /*
		 * Different notion of current in sent hierarchy.
		 * So, add it to the hierarchy here.
		 */
            control = currentAction.control();
            /*
		 * Now deal with the current transaction.
		 */
            TransIdentity currentID = context.current;
            control = ServerFactory.create_subtransaction(currentUid, currentID.coord, currentID.term, control);
            nestedAction = new ServerNestedAction(control);
            if (!nestedAction.valid()) {
                try {
                    // does dispose as well!
                    ((ServerNestedAction) nestedAction).rollback();
                    nestedAction = null;
                } catch (Exception e) {
                }
                throw new TRANSACTION_ROLLEDBACK();
            }
            currentAction.addChild((ServerNestedAction) nestedAction);
        } else {
            /*
		 * Same current, so get its control and return it.
		 */
            control = nestedAction.control();
        }
    }
    if (jtsLogger.logger.isTraceEnabled())
        compareHierarchies(context, hier);
    return control;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) TransIdentity(org.omg.CosTransactions.TransIdentity) ServerNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction) Terminator(org.omg.CosTransactions.Terminator) Coordinator(org.omg.CosTransactions.Coordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) SystemException(org.omg.CORBA.SystemException)

Example 2 with ServerNestedAction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction in project narayana by jbosstm.

the class Interposition method compareHierarchies.

protected final void compareHierarchies(PropagationContext ctx, ServerTopLevelAction action) {
    int depth = ctx.parents.length;
    Uid[] ctxHierarchy = new Uid[depth + 1];
    boolean printHierarchies = false;
    for (int i = depth - 1; i >= 0; i--) {
        ctxHierarchy[i + 1] = new Uid(Utility.otidToUid(ctx.parents[i].otid));
    }
    ctxHierarchy[0] = new Uid(Utility.otidToUid(ctx.current.otid));
    boolean problem = false;
    if (action != null) {
        if (action.get_uid().notEquals(ctxHierarchy[depth])) {
            jtsLogger.i18NLogger.warn_interposition_resources_arjuna_iptl(action.get_uid(), ctxHierarchy[depth]);
            printHierarchies = true;
        } else {
            if (depth > 0) {
                ServerNestedAction child = action.getChild(ctxHierarchy[depth - 1]);
                if (child != null) {
                    int i = 0;
                    for (i = depth - 2; (i >= 0) && (child != null); i--) {
                        child = child.getChild(ctxHierarchy[i]);
                        if (child == null) {
                            problem = true;
                            break;
                        }
                    }
                    if (i != -1)
                        problem = true;
                } else
                    problem = true;
            }
            if (problem) {
                jtsLogger.i18NLogger.warn_interposition_resources_arjuna_ipnt();
                printHierarchies = true;
            }
        }
    } else {
        jtsLogger.i18NLogger.warn_interposition_resources_arjuna_ipnull();
        printHierarchies = true;
    }
    if (!printHierarchies)
        printHierarchies = jtsLogger.logger.isTraceEnabled();
    if (printHierarchies) {
        synchronized (jtsLogger.logger) {
            if (!problem) {
                if (jtsLogger.logger.isTraceEnabled()) {
                    jtsLogger.logger.trace(Utility.getHierarchy(ctx));
                    jtsLogger.logger.trace(hierarchytoString(action));
                }
            } else {
                jtsLogger.i18NLogger.warn_interposition_resources_arjuna_problemhierarchy(Utility.getHierarchy(ctx));
                jtsLogger.i18NLogger.warn_interposition_resources_arjuna_problemhierarchy(hierarchytoString(action));
            }
        }
    }
    if (ctxHierarchy != null) {
        for (int i = 0; i < (int) depth; i++) {
            if (ctxHierarchy[i] != null)
                ctxHierarchy[i] = null;
        }
        ctxHierarchy = null;
    }
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ServerNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction)

Example 3 with ServerNestedAction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction in project narayana by jbosstm.

the class Interposition method createHierarchy.

protected synchronized ControlImple createHierarchy(PropagationContext ctx, Uid tlUid) throws SystemException {
    /*
	 * Start at the parent and work our way down to "current". The current
	 * transaction is not in the IDL sequence, but sent as separate field
	 * of the propagation context. This tends to make the code more
	 * complex than it would be if the entire hierarchy was represented in
	 * one place.
	 */
    int depth = ctx.parents.length;
    ServerResource action = null;
    Coordinator tmpCoord = null;
    Terminator tmpTerm = null;
    if (depth == 0) {
        tmpCoord = ctx.current.coord;
        tmpTerm = ctx.current.term;
    } else {
        tmpCoord = ctx.parents[depth - 1].coord;
        tmpTerm = ctx.parents[depth - 1].term;
    }
    if (// terminator may correctly be null
    tmpCoord == null) {
        return null;
    }
    ServerControl control = ServerFactory.create_transaction(tlUid, null, null, tmpCoord, tmpTerm, ctx.timeout);
    action = new ServerTopLevelAction(control);
    if (!action.valid()) {
        try {
            // does dispose as well!
            ((ServerTopLevelAction) action).rollback();
        } catch (Exception e) {
        }
        if (((ServerTopLevelAction) action).isTransactionInactive()) {
            throw new TRANSACTION_UNAVAILABLE(jtsLogger.i18NLogger.get_transaction_was_inactive(), 1, CompletionStatus.COMPLETED_NO);
        } else {
            throw new TRANSACTION_ROLLEDBACK();
        }
    }
    ServerTopLevelAction newElement = (ServerTopLevelAction) action;
    _head.add(newElement);
    if (// current is a nested transaction
    depth > 0) {
        /*
	     * Now deal with any nested transactions.
	     * As we create, register with the original transactions.
	     */
        ServerResource nestedAction = null;
        for (int i = depth - 2; i >= 0; i--) {
            tmpCoord = ctx.parents[i].coord;
            tmpTerm = ctx.parents[i].term;
            control = ServerFactory.create_subtransaction(Utility.otidToUid(ctx.parents[i].otid), tmpCoord, tmpTerm, control);
            nestedAction = new ServerNestedAction(control);
            if (!nestedAction.valid()) {
                try {
                    // does dispose as well!
                    ((ServerNestedAction) nestedAction).rollback_subtransaction();
                    nestedAction = null;
                } catch (Exception e) {
                }
                throw new TRANSACTION_ROLLEDBACK();
            }
            /*
		 * Add transaction resource to list.
		 */
            action.addChild((ServerNestedAction) nestedAction);
            action = nestedAction;
        }
        /*
	     * Now deal with current transaction. If there is
	     * only one transaction we do nothing.
	     */
        tmpCoord = ctx.current.coord;
        tmpTerm = ctx.current.term;
        control = ServerFactory.create_subtransaction(Utility.otidToUid(ctx.current.otid), tmpCoord, tmpTerm, control);
        nestedAction = new ServerNestedAction(control);
        if (!nestedAction.valid()) {
            try {
                // does dispose as well!
                ((ServerNestedAction) nestedAction).rollback_subtransaction();
                nestedAction = null;
            } catch (Exception e) {
            }
            throw new TRANSACTION_ROLLEDBACK();
        }
        action.addChild((ServerNestedAction) nestedAction);
    }
    if (jtsLogger.logger.isTraceEnabled())
        compareHierarchies(ctx, newElement);
    return control;
}
Also used : ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ServerTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction) ServerNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction) Terminator(org.omg.CosTransactions.Terminator) Coordinator(org.omg.CosTransactions.Coordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) SystemException(org.omg.CORBA.SystemException) TRANSACTION_UNAVAILABLE(org.omg.CORBA.TRANSACTION_UNAVAILABLE)

Example 4 with ServerNestedAction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction in project narayana by jbosstm.

the class Interposition method hierarchytoString.

private final String hierarchytoString(ServerTopLevelAction action) {
    String hier = "InterposedHierarchy:";
    if (action != null) {
        hier += action.get_uid();
        List<ServerNestedAction> children = action.getChildren();
        synchronized (children) {
            for (ServerNestedAction child : children) {
                hier += "\n" + child.get_uid();
                hier += child.getChildren(2);
            }
        }
    } else
        hier += "EMPTY";
    return hier;
}
Also used : ServerNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction)

Example 5 with ServerNestedAction

use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction in project narayana by jbosstm.

the class ServerResource method getChildren.

public final String getChildren(int depth) {
    String children = "";
    synchronized (_children) {
        for (ServerNestedAction child : _children) {
            children += "\n";
            for (int i = 0; i < depth; i++) children += " ";
            children += child.get_uid();
            children += child.getChildren(depth + 1);
        }
    }
    return children;
}
Also used : ServerNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction)

Aggregations

ServerNestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction)9 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)5 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)3 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)3 Test (org.junit.Test)3 Control (org.omg.CosTransactions.Control)3 Uid (com.arjuna.ats.arjuna.common.Uid)2 SystemException (org.omg.CORBA.SystemException)2 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)2 Coordinator (org.omg.CosTransactions.Coordinator)2 Terminator (org.omg.CosTransactions.Terminator)2 ServerTopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction)1 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)1 TRANSACTION_UNAVAILABLE (org.omg.CORBA.TRANSACTION_UNAVAILABLE)1 TransIdentity (org.omg.CosTransactions.TransIdentity)1