Search in sources :

Example 1 with ServerSynchronization

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

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

the class ServerSynchronizationUnitTest method test.

@Test
public void test() throws Exception {
    ServerTransaction sc = new ServerTransaction(new Uid(), null);
    ServerSynchronization sync = new ServerSynchronization(sc);
    sync.before_completion();
    sync.after_completion(Status.StatusCommitted);
    assertTrue(sync.getSynchronization() != null);
    sync.destroy();
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ServerSynchronization(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.ServerSynchronization) ServerTransaction(com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction) Test(org.junit.Test)

Example 3 with ServerSynchronization

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

the class ServerSynchronizationUnitTest method testNull.

@Test
public void testNull() throws Exception {
    ServerSynchronization sync = new ServerSynchronization(null);
    try {
        sync.before_completion();
        fail();
    } catch (final BAD_OPERATION ex) {
    }
    try {
        sync.after_completion(Status.StatusCommitted);
        fail();
    } catch (final BAD_OPERATION ex) {
    }
}
Also used : ServerSynchronization(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.ServerSynchronization) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION) Test(org.junit.Test)

Aggregations

ServerSynchronization (com.arjuna.ats.internal.jts.orbspecific.interposition.resources.ServerSynchronization)3 Test (org.junit.Test)2 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)1 ServerTransaction (com.arjuna.ats.internal.jts.orbspecific.interposition.coordinator.ServerTransaction)1 SystemException (org.omg.CORBA.SystemException)1 Coordinator (org.omg.CosTransactions.Coordinator)1 Inactive (org.omg.CosTransactions.Inactive)1 RecoveryCoordinator (org.omg.CosTransactions.RecoveryCoordinator)1 SynchronizationUnavailable (org.omg.CosTransactions.SynchronizationUnavailable)1