Search in sources :

Example 26 with Coordinator

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

the class OSIInterposition 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.
     */
/*
     * Also we would like to just register one resource to represent the entire
     * hierarchy, but this has problems: since threads can invoke operations at
     * any point in a hierarchy, we end up with multiple resources at top-level
     * for the same transaction. Each will try to commit the top-level
     * transaction!
     * In this implementation, the first to do so will garbage collect the root
     * of the hierarchy, and probably cause the subsequent ones to fail! There
     * is also the problem with many cross-process calls for the *same*
     * transaction.
     * So, we register *one* resource for each level of the hierarchy *when it
     * is required*, i.e., as the previous transaction terminates, and remove
     * terminated transaction resources when they occur. This means that at
     * top-level we only have a single resource to commit. There are the same
     * number of cross-process invocations. However, we also maintain the
     * entire hierarchy at the server, so if it makes subsequent invocations,
     * the right hierarchy gets sent out!
     */
protected synchronized ControlImple checkHierarchy(ServerTopLevelAction hier, PropagationContext context) {
    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. However, make sure it has registered
	     * itself with the "real" transaction.
	     */
        ServerOSITopLevelAction tx = (ServerOSITopLevelAction) hier;
        tx.interposeResource();
        // top-level transaction's control
        control = tx.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(OTIDMap.find(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 = null;
            Terminator tmpTerm = null;
            for (int j = differenceIndex; j >= 0; j--) {
                tmpCoord = context.parents[j].coord;
                tmpTerm = context.parents[j].term;
                control = ServerFactory.create_subtransaction(OTIDMap.find(context.parents[j].otid), tmpCoord, tmpTerm, control);
                nestedAction = new ServerOSINestedAction(control, false);
                if (!nestedAction.valid()) {
                    try {
                        // does dispose as well!
                        ((ServerOSINestedAction) nestedAction).rollback();
                        nestedAction = null;
                    } catch (Exception e) {
                    }
                    throw new TRANSACTION_ROLLEDBACK();
                }
                currentAction.addChild((ServerOSINestedAction) nestedAction);
                currentAction = nestedAction;
            }
        } else {
        /*
		 * Hierarchies may be identical.
		 * Remember to check!
		 */
        }
        Uid currentUid = OTIDMap.find(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 ServerOSINestedAction(control, true);
            if (!nestedAction.valid()) {
                try {
                    // does dispose as well!
                    ((ServerOSINestedAction) nestedAction).rollback();
                    nestedAction = null;
                } catch (Exception e) {
                }
                throw new TRANSACTION_ROLLEDBACK();
            }
            currentAction.addChild((ServerOSINestedAction) nestedAction);
        } else {
            /*
		 * Same current, so get its control and return it.
		 * Remember to make sure it has registered itself with
		 * the "real" transaction.
		 */
            nestedAction.interposeResource();
            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) ServerOSINestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.osi.ServerOSINestedAction) ServerResource(com.arjuna.ats.internal.jts.interposition.resources.arjuna.ServerResource) Terminator(org.omg.CosTransactions.Terminator) Coordinator(org.omg.CosTransactions.Coordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) SystemException(org.omg.CORBA.SystemException) ServerOSITopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.osi.ServerOSITopLevelAction)

Example 27 with Coordinator

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

the class ContextManager method createProxy.

public final ControlWrapper createProxy(org.omg.CORBA.Any ctx) throws SystemException {
    String stringRef = null;
    try {
        stringRef = ctx.extract_string();
        if (stringRef.startsWith(IORTag)) {
            org.omg.CORBA.Object obj = ORBManager.getORB().orb().string_to_object(stringRef);
            Coordinator theCoordinator = org.omg.CosTransactions.CoordinatorHelper.narrow(obj);
            if (theCoordinator == null)
                throw new BAD_PARAM();
            return new ControlWrapper(TransactionFactoryImple.createProxy(theCoordinator, null));
        } else
            return null;
    } catch (BAD_PARAM e1) {
        jtsLogger.i18NLogger.warn_context_genfail("ContextManager " + stringRef, e1);
    } catch (Exception e2) {
        jtsLogger.i18NLogger.warn_context_genfail("ContextManager", e2);
        throw new UNKNOWN(e2.toString());
    }
    return null;
}
Also used : ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) BAD_PARAM(org.omg.CORBA.BAD_PARAM) UNKNOWN(org.omg.CORBA.UNKNOWN) Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException) EmptyStackException(java.util.EmptyStackException)

Example 28 with Coordinator

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

the class RestrictedInterposition 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;
    ServerTopLevelAction tlAction = 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;
    }
    ServerControl control = ServerFactory.create_transaction(tlUid, null, null, tmpCoord, tmpTerm, ctx.timeout);
    tlAction = new ServerRestrictedTopLevelAction(control);
    if (!tlAction.valid()) {
        try {
            tlAction.rollback();
            tlAction = null;
        } catch (Exception e) {
        }
        throw new TRANSACTION_ROLLEDBACK();
    }
    ServerTopLevelAction newElement = tlAction;
    super._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.
             */
        ServerRestrictedNestedAction 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 ServerRestrictedNestedAction(control);
            if (!nestedAction.valid()) {
                try {
                    nestedAction.rollback();
                    nestedAction = null;
                } catch (Exception e) {
                }
                throw new TRANSACTION_ROLLEDBACK();
            }
            /*
                 * Add transaction resource to list.
                 */
            tlAction.addChild(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 ServerRestrictedNestedAction(control);
        if (!nestedAction.valid()) {
            try {
                nestedAction.rollback();
                nestedAction = null;
            } catch (Exception e) {
            }
            throw new TRANSACTION_ROLLEDBACK();
        }
        tlAction.addChild(nestedAction);
    }
    return control;
}
Also used : ServerTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ServerRestrictedTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedTopLevelAction) Terminator(org.omg.CosTransactions.Terminator) ServerRestrictedNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedNestedAction) Coordinator(org.omg.CosTransactions.Coordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) SystemException(org.omg.CORBA.SystemException)

Example 29 with Coordinator

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

the class StrictInterposition 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.
 */
/*
 * Also we would like to just register one resource to represent the entire
 * hierarchy, but this has problems: since threads can invoke operations at
 * any point in a hierarchy, we end up with multiple resources at top-level
 * for the same transaction. Each will try to commit the top-level transaction!
 * In this implementation, the first to do so will garbage collect the root
 * of the hierarchy, and probably cause the subsequent ones to fail! There is
 * also the problem with many cross-process calls for the *same* transaction.
 * So, we register *one* resource for each level of the hierarchy *when it is
 * required*, i.e., as the previous transaction terminates, and remove
 * terminated transaction resources when they occur. This means that at
 * top-level we only have a single resource to commit. There are the same
 * number of cross-process invocations. However, we also maintain the entire
 * hierarchy at the server, so if it makes subsequent invocations, the right
 * hierarchy gets sent out!
 */
protected synchronized ControlImple checkHierarchy(ServerTopLevelAction hier, PropagationContext context) {
    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. However, make sure it has registered
	     * itself with the "real" transaction.
	     */
        ServerStrictTopLevelAction tx = (ServerStrictTopLevelAction) hier;
        tx.interposeResource();
        // top-level transaction's control
        control = tx.control();
    } else {
        ServerResource nestedAction = null;
        for (// don't check depth-1 as it is current action!
        int i = (int) 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 = null;
            Terminator tmpTerm = null;
            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 ServerStrictNestedAction(control, false);
                if (!nestedAction.valid()) {
                    try {
                        // does dispose as well!
                        ((ServerStrictNestedAction) nestedAction).rollback();
                        nestedAction = null;
                    } catch (Exception e) {
                    }
                    throw new TRANSACTION_ROLLEDBACK();
                }
                currentAction.addChild((ServerStrictNestedAction) 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 ServerStrictNestedAction(control, true);
            if (!nestedAction.valid()) {
                try {
                    // does dispose as well!
                    ((ServerStrictNestedAction) nestedAction).rollback();
                    nestedAction = null;
                } catch (Exception e) {
                }
                throw new TRANSACTION_ROLLEDBACK();
            }
            currentAction.addChild((ServerStrictNestedAction) nestedAction);
        } else {
            /*
		 * Same current, so get its control and return it.
		 * Remember to make sure it has registered itself with
		 * the "real" transaction.
		 */
            nestedAction.interposeResource();
            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) ServerStrictNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.strict.ServerStrictNestedAction) TransIdentity(org.omg.CosTransactions.TransIdentity) ServerResource(com.arjuna.ats.internal.jts.interposition.resources.arjuna.ServerResource) Terminator(org.omg.CosTransactions.Terminator) ServerStrictTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.strict.ServerStrictTopLevelAction) Coordinator(org.omg.CosTransactions.Coordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) SystemException(org.omg.CORBA.SystemException)

Example 30 with Coordinator

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

the class StrictInterposition method createHierarchy.

protected synchronized ControlImple createHierarchy(PropagationContext ctx, Uid currentUid) 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.
	 */
    /*
	 * We only ever register the current transaction with its parent, and
	 * as each transaction commits, it registers its parent with the
	 * "real" parent.
	 */
    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 my correctory be null
    tmpCoord == null)
        return null;
    ServerControl control = ServerFactory.create_transaction(currentUid, null, null, tmpCoord, tmpTerm, ctx.timeout);
    action = new ServerStrictTopLevelAction(control, ((depth == 0) ? true : false));
    if (!action.valid()) {
        try {
            // does dispose as well!
            ((ServerStrictTopLevelAction) action).rollback();
            action = null;
        } catch (Exception e) {
        }
        throw new TRANSACTION_ROLLEDBACK();
    }
    ServerTopLevelAction newElement = (ServerStrictTopLevelAction) 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);
            // not current, so don't register
            nestedAction = new ServerStrictNestedAction(control, false);
            if (!nestedAction.valid()) {
                try {
                    // does dispose as well!
                    ((ServerStrictNestedAction) nestedAction).rollback_subtransaction();
                    nestedAction = null;
                } catch (Exception e) {
                }
                throw new TRANSACTION_ROLLEDBACK();
            }
            /*
		 * Add transaction resource to list.
		 */
            action.addChild((ServerStrictNestedAction) 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);
        // current, so register
        nestedAction = new ServerStrictNestedAction(control, true);
        if (!nestedAction.valid()) {
            try {
                // does dispose as well!
                ((ServerStrictNestedAction) nestedAction).rollback_subtransaction();
                nestedAction = null;
            } catch (Exception e) {
            }
            throw new TRANSACTION_ROLLEDBACK();
        }
        action.addChild((ServerStrictNestedAction) 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) ServerStrictNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.strict.ServerStrictNestedAction) ServerResource(com.arjuna.ats.internal.jts.interposition.resources.arjuna.ServerResource) Terminator(org.omg.CosTransactions.Terminator) ServerStrictTopLevelAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.strict.ServerStrictTopLevelAction) Coordinator(org.omg.CosTransactions.Coordinator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) SystemException(org.omg.CORBA.SystemException)

Aggregations

Coordinator (org.omg.CosTransactions.Coordinator)47 SystemException (org.omg.CORBA.SystemException)32 UNKNOWN (org.omg.CORBA.UNKNOWN)15 Control (org.omg.CosTransactions.Control)14 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)13 BAD_PARAM (org.omg.CORBA.BAD_PARAM)12 Unavailable (org.omg.CosTransactions.Unavailable)11 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)10 Terminator (org.omg.CosTransactions.Terminator)10 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)9 UidCoordinator (com.arjuna.ArjunaOTS.UidCoordinator)6 Uid (com.arjuna.ats.arjuna.common.Uid)6 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)6 ORB (com.arjuna.orbportability.ORB)6 Any (org.omg.CORBA.Any)6 TRANSACTION_REQUIRED (org.omg.CORBA.TRANSACTION_REQUIRED)6 TransactionalObject (org.omg.CosTransactions.TransactionalObject)6 ServiceContext (org.omg.IOP.ServiceContext)6 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)5 PropagationContext (org.omg.CosTransactions.PropagationContext)5