Search in sources :

Example 1 with ExplicitInterposition

use of com.arjuna.ats.jts.ExplicitInterposition in project narayana by jbosstm.

the class ExplicitStackImple method push.

public int push(int val, Control action) throws SystemException {
    AtomicTransaction A = new AtomicTransaction();
    int res = 0;
    ExplicitInterposition inter = new ExplicitInterposition();
    try {
        inter.registerTransaction(action);
    } catch (Exception e) {
        System.err.println("WARNING ExplicitStackImple::push - could not create interposition.");
        return -1;
    }
    String name = OTSImpleManager.current().get_transaction_name();
    System.out.println("Created push interposed transaction: " + name);
    name = null;
    try {
        A.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            if (top < ARRAY_SIZE) {
                array[top] = val;
                top++;
            } else
                res = -1;
            if (res == 0) {
                A.commit(false);
            } else
                A.rollback();
        } else
            A.rollback();
    } catch (Exception e1) {
        try {
            A.rollback();
        } catch (Exception e2) {
            System.err.println(e2);
        }
        res = -1;
    }
    inter.unregisterTransaction();
    return res;
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) ExplicitInterposition(com.arjuna.ats.jts.ExplicitInterposition) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) Lock(com.arjuna.ats.txoj.Lock)

Example 2 with ExplicitInterposition

use of com.arjuna.ats.jts.ExplicitInterposition in project narayana by jbosstm.

the class HammerObject method get.

public boolean get(IntHolder value, Control control) throws SystemException {
    boolean res = false;
    ExplicitInterposition inter = new ExplicitInterposition();
    try {
        inter.registerTransaction(control);
    } catch (Exception e) {
        System.err.println("WARNING HammerObject.incr - could not do interposition");
        return false;
    }
    CurrentImple current = OTSImpleManager.current();
    try {
        current.begin();
        if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED) {
            value.value = _value;
            current.commit(true);
            res = true;
        } else
            current.rollback();
    } catch (Exception e) {
        System.err.println("HammerObject.get: " + e);
        res = false;
    }
    inter.unregisterTransaction();
    return res;
}
Also used : ExplicitInterposition(com.arjuna.ats.jts.ExplicitInterposition) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) Lock(com.arjuna.ats.txoj.Lock)

Example 3 with ExplicitInterposition

use of com.arjuna.ats.jts.ExplicitInterposition in project narayana by jbosstm.

the class HammerObject method incr.

public boolean incr(int value, Control control) throws SystemException {
    boolean res = false;
    ExplicitInterposition inter = new ExplicitInterposition();
    try {
        inter.registerTransaction(control);
    } catch (Exception e) {
        System.err.println("WARNING HammerObject.incr - could not do interposition");
        return false;
    }
    CurrentImple current = OTSImpleManager.current();
    try {
        current.begin();
        if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
            _value = _value + value;
            current.commit(true);
            res = true;
        } else
            current.rollback();
    } catch (Exception e) {
        System.err.println("HammerObject.incr: " + e);
        res = false;
    }
    inter.unregisterTransaction();
    return res;
}
Also used : ExplicitInterposition(com.arjuna.ats.jts.ExplicitInterposition) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) Lock(com.arjuna.ats.txoj.Lock)

Example 4 with ExplicitInterposition

use of com.arjuna.ats.jts.ExplicitInterposition in project narayana by jbosstm.

the class PropagationContextManager method importTransactionPropagationContext.

/**
 * Import the transaction propagation context into the transaction manager,
 * and return the resulting transaction. If this transaction propagation
 * context has already been imported into the transaction manager, this
 * method simply returns the <code>Transaction</code> representing the
 * transaction propagation context in the local VM. Returns
 * <code>null</code> if the transaction propagation context is
 * <code>null</code>, or if it represents a <code>null</code> transaction.
 */
public Transaction importTransactionPropagationContext(Object tpc) {
    if (jbossatxLogger.logger.isTraceEnabled()) {
        jbossatxLogger.logger.trace("PropagationContextManager.importTransactionPropagationContext(Object) - called tpc = " + tpc);
    }
    javax.transaction.TransactionManager tm = TransactionManager.transactionManager();
    if (tpc instanceof PropagationContextWrapper) {
        try {
            PropagationContext omgTpc = ((PropagationContextWrapper) tpc).getPropagationContext();
            ExplicitInterposition ei = new ExplicitInterposition(omgTpc, true);
            Transaction newTx = tm.getTransaction();
            if (jbossatxLogger.logger.isTraceEnabled()) {
                jbossatxLogger.logger.trace("PropagationContextManager.importTransactionPropagationContext(Object) - transaction = " + newTx);
            }
            ei.unregisterTransaction();
            return newTx;
        } catch (Exception e) {
            jbossatxLogger.i18NLogger.error_jts_PropagationContextManager_exception(e);
            return null;
        }
    } else {
        jbossatxLogger.i18NLogger.error_jts_PropagationContextManager_unknownctx();
        return null;
    }
}
Also used : Transaction(javax.transaction.Transaction) ExplicitInterposition(com.arjuna.ats.jts.ExplicitInterposition)

Example 5 with ExplicitInterposition

use of com.arjuna.ats.jts.ExplicitInterposition in project narayana by jbosstm.

the class ExplicitInterpositionUnitTest method test.

@Test
public void test() throws Exception {
    ExplicitStackImple stack = new ExplicitStackImple();
    OTSImpleManager.current().begin();
    assertEquals(stack.push(10, OTSImpleManager.current().get_control()), 0);
    OTSImpleManager.current().rollback();
    OTSImpleManager.current().begin();
    ExplicitInterposition inter = new ExplicitInterposition(OTSImpleManager.current().get_control().get_coordinator().get_txcontext(), true);
    inter.unregisterTransaction();
    OTSImpleManager.current().rollback();
}
Also used : ExplicitStackImple(com.hp.mwtests.ts.jts.orbspecific.resources.ExplicitStackImple) ExplicitInterposition(com.arjuna.ats.jts.ExplicitInterposition) Test(org.junit.Test)

Aggregations

ExplicitInterposition (com.arjuna.ats.jts.ExplicitInterposition)8 Lock (com.arjuna.ats.txoj.Lock)5 IOException (java.io.IOException)5 SystemException (org.omg.CORBA.SystemException)5 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)4 AtomicTransaction (com.arjuna.ats.jts.extensions.AtomicTransaction)2 InterpositionFailed (com.arjuna.ArjunaOTS.InterpositionFailed)1 ExplicitStackImple (com.hp.mwtests.ts.jts.orbspecific.resources.ExplicitStackImple)1 Transaction (javax.transaction.Transaction)1 Test (org.junit.Test)1 UNKNOWN (org.omg.CORBA.UNKNOWN)1 Control (org.omg.CosTransactions.Control)1 Coordinator (org.omg.CosTransactions.Coordinator)1