Search in sources :

Example 1 with SynchronizationRecord

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

the class ArjunaTransactionImple method getSynchronizations.

public java.util.Map<Uid, String> getSynchronizations() {
    if (_synchs != null) {
        java.util.Map<Uid, String> synchMap = new java.util.HashMap<Uid, String>();
        SynchronizationRecord[] synchs = (SynchronizationRecord[]) _synchs.toArray(new SynchronizationRecord[] {});
        for (SynchronizationRecord synch : synchs) {
            Synchronization c = synch.contents();
            String cn;
            if (c._is_a(ManagedSynchronizationHelper.id())) {
                ManagedSynchronization mc = ManagedSynchronizationHelper.narrow(c);
                try {
                    // implementationType() ;
                    cn = mc.instanceName();
                } catch (Throwable t) {
                    cn = synch.getClass().getCanonicalName();
                }
            } else {
                cn = synch.getClass().getCanonicalName();
            }
            synchMap.put(synch.get_uid(), cn);
        }
        return synchMap;
    }
    return Collections.EMPTY_MAP;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ManagedSynchronization(com.arjuna.ArjunaOTS.ManagedSynchronization) Synchronization(org.omg.CosTransactions.Synchronization) ManagedSynchronization(com.arjuna.ArjunaOTS.ManagedSynchronization) SynchronizationRecord(com.arjuna.ats.internal.jts.resources.SynchronizationRecord)

Example 2 with SynchronizationRecord

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

the class ArjunaTransactionImple method doAfterCompletion.

protected void doAfterCompletion(org.omg.CosTransactions.Status myStatus) throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::doAfterCompletion for " + get_uid());
    }
    if (myStatus == Status.StatusActive) {
        jtsLogger.i18NLogger.warn_orbspecific_coordinator_txrun("ArjunaTransactionImple.doAfterCompletion");
        return;
    }
    boolean problem = false;
    SystemException exp = null;
    if (_synchs != null) {
        ControlWrapper cw = null;
        boolean doSuspend = false;
        try {
            // cw = OTSImpleManager.systemCurrent().getControlWrapper();
            cw = OTSImpleManager.current().getControlWrapper();
            if ((cw == null) || (!controlHandle.equals(cw.getImple()))) {
                // OTSImpleManager.systemCurrent().resumeImple(controlHandle);
                OTSImpleManager.current().resumeImple(controlHandle);
                doSuspend = true;
            }
        } catch (Exception ex) {
            /*
	             * It should still be OK to make the call without a context
	             * because a Synchronization can only be associated with a
	             * single transaction.
	             */
            problem = true;
        }
        /*
	         * Regardless of failures, we must tell all synchronizations what
	         * happened.
	         */
        // afterCompletions should run in reverse order compared to beforeCompletions
        Stack stack = new Stack();
        Iterator iterator = _synchs.iterator();
        while (iterator.hasNext()) {
            stack.push(iterator.next());
        }
        iterator = stack.iterator();
        /*
	         * Regardless of failures, we must tell all synchronizations what
	         * happened.
	         */
        while (!stack.isEmpty()) {
            SynchronizationRecord value = (SynchronizationRecord) stack.pop();
            Synchronization c = value.contents();
            try {
                c.after_completion(myStatus);
            } catch (SystemException e) {
                if (jtsLogger.logger.isTraceEnabled()) {
                    jtsLogger.logger.trace("ArjunaTransactionImple.doAfterCompletion - caught exception " + e);
                }
                problem = true;
                if (exp == null)
                    exp = e;
            }
        }
        if (doSuspend) {
            try {
                if (cw != null)
                    OTSImpleManager.current().resumeWrapper(cw);
                else
                    OTSImpleManager.current().suspend();
            } catch (Exception ex) {
            }
        }
        _synchs = null;
    }
    boolean superProblem = !super.afterCompletion(myStatus == Status.StatusCommitted ? ActionStatus.COMMITTED : ActionStatus.ABORTED);
    if (problem || superProblem) {
        if (exp != null)
            throw exp;
        else
            throw new UNKNOWN(ExceptionCodes.SYNCHRONIZATION_EXCEPTION, CompletionStatus.COMPLETED_NO);
    }
}
Also used : SystemException(org.omg.CORBA.SystemException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) Iterator(java.util.Iterator) UNKNOWN(org.omg.CORBA.UNKNOWN) Synchronization(org.omg.CosTransactions.Synchronization) ManagedSynchronization(com.arjuna.ArjunaOTS.ManagedSynchronization) SystemException(org.omg.CORBA.SystemException) SynchronizationRecord(com.arjuna.ats.internal.jts.resources.SynchronizationRecord) Stack(java.util.Stack)

Example 3 with SynchronizationRecord

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

the class ArjunaTransactionImple method doBeforeCompletion.

protected void doBeforeCompletion() throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::doBeforeCompletion for " + get_uid());
    }
    boolean problem = false;
    SystemException exp = null;
    /*
	     * If we have a synchronization list then we must be top-level.
	     */
    if (_synchs != null) {
        boolean doSuspend = false;
        ControlWrapper cw = null;
        try {
            try {
                // cw = OTSImpleManager.systemCurrent().getControlWrapper();
                cw = OTSImpleManager.current().getControlWrapper();
                if ((cw == null) || (!controlHandle.equals(cw.getImple()))) {
                    // OTSImpleManager.systemCurrent().resumeImple(controlHandle);
                    OTSImpleManager.current().resumeImple(controlHandle);
                    doSuspend = true;
                }
            } catch (Exception ex) {
            /*
	                 * It should be OK to continue with the invocations even if
	                 * we couldn't resume, because a Synchronization is only
	                 * supposed to be associated with a single transaction. So,
	                 * it should be able to infer the transaction.
	                 */
            }
            /*
	             * Since Synchronizations may add register other Synchronizations, we can't simply
	             * iterate the collection. Instead we work from an ordered copy, which we periodically
	             * check for freshness. The addSynchronization method uses _currentRecord to disallow
	             * adding records in the part of the array we have already traversed, thus all
	             * Synchronization will be called and the (jta only) rules on ordering of interposed
	             * Synchronization will be respected.
	             */
            int lastIndexProcessed = -1;
            SynchronizationRecord[] copiedSynchs = (SynchronizationRecord[]) _synchs.toArray(new SynchronizationRecord[] {});
            while ((lastIndexProcessed < _synchs.size() - 1) && !problem) {
                // if new Synchronization have been registered, refresh our copy of the collection:
                if (copiedSynchs.length != _synchs.size()) {
                    copiedSynchs = (SynchronizationRecord[]) _synchs.toArray(new SynchronizationRecord[] {});
                }
                lastIndexProcessed = lastIndexProcessed + 1;
                _currentRecord = copiedSynchs[lastIndexProcessed];
                Synchronization c = _currentRecord.contents();
                c.before_completion();
            }
        } catch (SystemException e) {
            jtsLogger.i18NLogger.warn_orbspecific_coordinator_generror("ArjunaTransactionImple.doBeforeCompletion", e);
            if (!problem) {
                exp = e;
                problem = true;
                try {
                    rollback_only();
                } catch (Inactive ex) {
                    /*
	                     * This should not happen. If it does, continue with
	                     * commit to tidy-up.
	                     */
                    jtsLogger.i18NLogger.warn_orbspecific_coordinator_rbofail("ArjunaTransactionImple.doBeforeCompletion", get_uid(), ex);
                }
            }
        } finally {
            if (doSuspend) {
                try {
                    if (cw != null)
                        OTSImpleManager.current().resumeWrapper(cw);
                    else
                        OTSImpleManager.current().suspend();
                } catch (Exception ex) {
                }
            // OTSImpleManager.systemCurrent().suspend();
            }
        }
    }
    if (!problem)
        problem = !super.beforeCompletion();
    if (problem) {
        if (exp != null)
            throw exp;
        else
            throw new UNKNOWN(ExceptionCodes.SYNCHRONIZATION_EXCEPTION, CompletionStatus.COMPLETED_NO);
    }
}
Also used : SystemException(org.omg.CORBA.SystemException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) Inactive(org.omg.CosTransactions.Inactive) UNKNOWN(org.omg.CORBA.UNKNOWN) Synchronization(org.omg.CosTransactions.Synchronization) ManagedSynchronization(com.arjuna.ArjunaOTS.ManagedSynchronization) SystemException(org.omg.CORBA.SystemException) SynchronizationRecord(com.arjuna.ats.internal.jts.resources.SynchronizationRecord)

Example 4 with SynchronizationRecord

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

the class SynchronizationRecordUnitTest method testCompare.

@Test
public void testCompare() throws Exception {
    demosync theSync = new demosync();
    SynchronizationRecord sync1 = new SynchronizationRecord(theSync.getReference(), false);
    SynchronizationRecord sync2 = new SynchronizationRecord(theSync.getReference(), true);
    assertEquals(sync1.compareTo(sync2), -1);
    assertEquals(sync2.compareTo(sync1), 1);
    assertEquals(sync1.compareTo(sync1), 0);
    sync2 = new SynchronizationRecord(theSync.getReference(), false);
    assertEquals(sync1.compareTo(sync2), -1);
}
Also used : com.hp.mwtests.ts.jts.orbspecific.resources.demosync(com.hp.mwtests.ts.jts.orbspecific.resources.demosync) SynchronizationRecord(com.arjuna.ats.internal.jts.resources.SynchronizationRecord) Test(org.junit.Test)

Example 5 with SynchronizationRecord

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

the class SynchronizationRecordUnitTest method test.

@Test
public void test() throws Exception {
    demosync theSync = new demosync();
    SynchronizationRecord sync = new SynchronizationRecord(theSync.getReference(), false);
    assertTrue(sync.contents() == theSync.getReference());
    assertTrue(sync.get_uid() != Uid.nullUid());
}
Also used : com.hp.mwtests.ts.jts.orbspecific.resources.demosync(com.hp.mwtests.ts.jts.orbspecific.resources.demosync) SynchronizationRecord(com.arjuna.ats.internal.jts.resources.SynchronizationRecord) Test(org.junit.Test)

Aggregations

SynchronizationRecord (com.arjuna.ats.internal.jts.resources.SynchronizationRecord)5 ManagedSynchronization (com.arjuna.ArjunaOTS.ManagedSynchronization)3 Synchronization (org.omg.CosTransactions.Synchronization)3 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)2 com.hp.mwtests.ts.jts.orbspecific.resources.demosync (com.hp.mwtests.ts.jts.orbspecific.resources.demosync)2 Test (org.junit.Test)2 SystemException (org.omg.CORBA.SystemException)2 UNKNOWN (org.omg.CORBA.UNKNOWN)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 Iterator (java.util.Iterator)1 Stack (java.util.Stack)1 Inactive (org.omg.CosTransactions.Inactive)1