Search in sources :

Example 1 with ServerControl

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

the class ServerTransaction method register_synchronization.

/**
 * Registering a synchronization with interposition is a bit complicated!
 * Synchronizations must be called prior to prepare; if no
 * interposed-synchronization is used then either synchronizations would be
 * registered locally (and then ignored by the commit protocol) or they
 * would need to be registered remotely, which would mean a cross-address
 * space call for each synchronization!
 *
 * The first time a synchronization is registered locally, we register a
 * proxy back with the real coordinator. When that transaction commits, it
 * will call this proxy, which will then drive the locally registered
 * synchronizations (actually it calls appropriate on the transaction to do
 * this.)
 *
 * However, one-phase commit complicates matters even more since we call
 * commit on the interposed coordinator, which runs through the commit and
 * then the after_completion code before returning to the real coordinator's
 * commit call. Rather than separate commit and synchronization code
 * completely from the transaction (in which case we could just call the
 * commit portion here) we let after_completion get called before returning
 * the commit response, and simply ignore the real coordinator's subsequent
 * call to after_completion.
 */
public synchronized void register_synchronization(Synchronization theSync) throws Inactive, SynchronizationUnavailable, SystemException {
    if (// are we a top-level transaction?
    !is_top_level_transaction()) {
        throw new SynchronizationUnavailable();
    } else {
        if (_interposedSynch) {
            if (_sync == null) {
                _sync = new ServerSynchronization(this);
                Coordinator realCoord = null;
                try {
                    ServerControl control = (ServerControl) super.controlHandle;
                    if (controlHandle != null) {
                        realCoord = control.originalCoordinator();
                        if (realCoord != null) {
                            realCoord.register_synchronization(_sync.getSynchronization());
                        } else
                            throw new BAD_OPERATION(ExceptionCodes.NO_TRANSACTION, CompletionStatus.COMPLETED_NO);
                    } else
                        throw new BAD_OPERATION(ExceptionCodes.NO_TRANSACTION, CompletionStatus.COMPLETED_NO);
                } catch (Inactive e1) {
                    realCoord = null;
                    throw e1;
                } catch (SynchronizationUnavailable e2) {
                    realCoord = null;
                    throw e2;
                } catch (SystemException e3) {
                    realCoord = null;
                    throw e3;
                }
                realCoord = null;
            }
        }
        /*
			 * Now register the synchronization locally.
			 */
        super.register_synchronization(theSync);
    }
}
Also used : ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) SystemException(org.omg.CORBA.SystemException) ServerSynchronization(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.ServerSynchronization) Inactive(org.omg.CosTransactions.Inactive) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION) Coordinator(org.omg.CosTransactions.Coordinator) RecoveryCoordinator(org.omg.CosTransactions.RecoveryCoordinator) SynchronizationUnavailable(org.omg.CosTransactions.SynchronizationUnavailable)

Example 2 with ServerControl

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

the class ServerControlUnitTest method test.

@Test
public void test() throws Exception {
    ControlImple cont = new ControlImple(null, null);
    Control theControl = cont.getControl();
    ArjunaTransactionImple tx = cont.getImplHandle();
    ServerControl sc = new ServerControl(tx.get_uid(), theControl, tx, theControl.get_coordinator(), theControl.get_terminator());
    assertTrue(sc.isWrapper());
    assertTrue(sc.get_coordinator() != null);
    assertTrue(sc.get_terminator() != null);
    assertEquals(sc.getParentImple(), null);
    assertTrue(sc.forgetHeuristics());
    assertTrue(sc.toString() != null);
    sc.destroy();
}
Also used : Control(org.omg.CosTransactions.Control) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Example 3 with ServerControl

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

the class ServerNestedOSIActionUnitTest method testCommit.

@Test
public void testCommit() throws Exception {
    ControlImple cont = new ControlImple(null, null);
    Control theControl = cont.getControl();
    ArjunaTransactionImple tx = cont.getImplHandle();
    ServerControl sc = new ServerControl(tx.get_uid(), theControl, tx, theControl.get_coordinator(), theControl.get_terminator());
    ServerOSINestedAction act = new ServerOSINestedAction(sc, true);
    assertFalse(act.interposeResource());
    act.commit_subtransaction(null);
}
Also used : Control(org.omg.CosTransactions.Control) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) ServerOSINestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.osi.ServerOSINestedAction) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Example 4 with ServerControl

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

the class ServerFactory method create_subtransaction.

public static ServerControl create_subtransaction(Uid actUid, Coordinator realCoord, Terminator realTerm, ServerControl parent) {
    if (parent == null) {
        jtsLogger.i18NLogger.warn_interposition_sfnoparent("ServerFactory.create_subtransaction");
        return null;
    }
    ServerControl toReturn = null;
    try {
        Control handle = parent.getControl();
        ArjunaTransactionImple tranHandle = parent.getImplHandle();
        toReturn = new ServerControl(actUid, handle, tranHandle, realCoord, realTerm);
        handle = null;
        tranHandle = null;
    } catch (Exception e) {
        if (toReturn != null) {
            try {
                // will delete itself
                toReturn.destroy();
            } catch (Exception ex) {
            }
        }
    }
    return toReturn;
}
Also used : ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) Control(org.omg.CosTransactions.Control) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) SystemException(org.omg.CORBA.SystemException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 5 with ServerControl

use of com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl 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)

Aggregations

ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)33 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)21 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)20 Test (org.junit.Test)20 Control (org.omg.CosTransactions.Control)20 SystemException (org.omg.CORBA.SystemException)12 Coordinator (org.omg.CosTransactions.Coordinator)9 ServerTopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction)8 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)8 Terminator (org.omg.CosTransactions.Terminator)8 Uid (com.arjuna.ats.arjuna.common.Uid)6 ServerNestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerNestedAction)5 ServerOSITopLevelAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.osi.ServerOSITopLevelAction)5 ServerResource (com.arjuna.ats.internal.jts.interposition.resources.arjuna.ServerResource)4 ServerOSINestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.osi.ServerOSINestedAction)4 ServerStrictNestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.strict.ServerStrictNestedAction)4 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)4 TransIdentity (org.omg.CosTransactions.TransIdentity)4 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)3 ServerRestrictedNestedAction (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedNestedAction)3