Search in sources :

Example 56 with AtomicTransaction

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

the class AITMatrixImpl01 method get_value.

public void get_value(int x, int y, IntHolder value) throws InvocationException {
    if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) {
        throw new InvocationException(Reason.ReasonUnknown);
    }
    try {
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        try {
            atomicTransaction.begin();
            if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED) {
                value.value = _values[x][y];
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
                throw new InvocationException(Reason.ReasonConcurrencyControl);
            }
        } catch (InvocationException invocationException) {
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITMatrixImpl01.get_value: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            throw new InvocationException(Reason.ReasonUnknown);
        }
    } catch (InvocationException invocationException) {
        throw invocationException;
    } catch (Exception exception) {
        System.err.println("AITMatrixImpl01.get_value: " + exception);
        throw new InvocationException(Reason.ReasonUnknown);
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Lock(com.arjuna.ats.txoj.Lock)

Example 57 with AtomicTransaction

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

the class AITMatrixImpl01 method set_value.

public void set_value(int x, int y, int value) throws InvocationException {
    if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) {
        throw new InvocationException(Reason.ReasonUnknown);
    }
    try {
        AtomicTransaction atomicTransaction = new AtomicTransaction();
        try {
            atomicTransaction.begin();
            if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
                _values[x][y] = value;
                atomicTransaction.commit(true);
            } else {
                atomicTransaction.rollback();
                throw new InvocationException(Reason.ReasonConcurrencyControl);
            }
        } catch (InvocationException invocationException) {
            throw invocationException;
        } catch (Exception exception) {
            System.err.println("AITMatrixImpl01.set_value: " + exception);
            if (atomicTransaction.get_status() == Status.StatusActive) {
                atomicTransaction.rollback();
            }
            throw new InvocationException(Reason.ReasonUnknown);
        }
    } catch (InvocationException invocationException) {
        throw invocationException;
    } catch (Exception exception) {
        System.err.println("AITMatrixImpl01.set_value: " + exception);
        throw new InvocationException(Reason.ReasonUnknown);
    }
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Lock(com.arjuna.ats.txoj.Lock)

Example 58 with AtomicTransaction

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

the class AtomicTransactionUnitTest method test.

@Test
public void test() throws Exception {
    AtomicTransaction A = new AtomicTransaction();
    A.begin();
    assertTrue(A.get_transaction_name() != null);
    A.set_timeout(10);
    assertEquals(A.get_timeout(), 10);
    assertTrue(A.getTimeout() != -1);
    assertTrue(A.get_txcontext() != null);
    assertTrue(A.get_uid().notEquals(Uid.nullUid()));
    assertTrue(A.control() != null);
    assertFalse(A.equals(null));
    assertTrue(A.equals(A));
    assertFalse(A.equals(new AtomicTransaction()));
    A.rollback();
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Test(org.junit.Test)

Example 59 with AtomicTransaction

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

the class ThreadAssociationsUnitTest method test.

@Test
public void test() throws Exception {
    AtomicTransaction tx = new AtomicTransaction();
    SampleAssociation assoc = new SampleAssociation();
    ThreadAssociations.addGlobal(assoc);
    tx.begin();
    assertTrue(assoc.beginCalled);
    tx.commit(false);
    assertTrue(assoc.commitCalled);
    tx = new AtomicTransaction();
    tx.begin();
    tx.suspend();
    assertTrue(assoc.suspendCalled);
    tx.resume();
    assertTrue(assoc.resumeCalled);
    tx.rollback();
    assertTrue(assoc.rollbackCalled);
}
Also used : AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) Test(org.junit.Test)

Example 60 with AtomicTransaction

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

the class TopLevelTransactionUnitTest method testRollback.

@Test
public void testRollback() throws Exception {
    AtomicTransaction A = new AtomicTransaction();
    A.begin();
    assertTrue(A.get_txcontext() != null);
    A.registerResource(new DemoResource().getResource());
    TopLevelTransaction B = new TopLevelTransaction();
    DemoResource d = new DemoResource();
    B.begin();
    B.registerResource(d.getResource());
    B.commit(true);
    A.rollback();
    assertEquals(d.getResourceTrace().getTrace(), ResourceTrace.ResourceTraceCommitOnePhase);
}
Also used : DemoResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource) AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) TopLevelTransaction(com.arjuna.ats.jts.extensions.TopLevelTransaction) Test(org.junit.Test)

Aggregations

AtomicTransaction (com.arjuna.ats.jts.extensions.AtomicTransaction)101 Lock (com.arjuna.ats.txoj.Lock)38 Date (java.util.Date)36 IntHolder (org.omg.CORBA.IntHolder)12 JVMStats (org.jboss.jbossts.qa.Utils.JVMStats)9 Test (org.junit.Test)7 IOException (java.io.IOException)6 SystemException (org.omg.CORBA.SystemException)6 DemoResource (com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource)3 ExplicitInterposition (com.arjuna.ats.jts.ExplicitInterposition)2 TopLevelTransaction (com.arjuna.ats.jts.extensions.TopLevelTransaction)2 Control (org.omg.CosTransactions.Control)2 DemoSubTranResource (com.hp.mwtests.ts.jts.orbspecific.resources.DemoSubTranResource)1 com.hp.mwtests.ts.jts.orbspecific.resources.demosync (com.hp.mwtests.ts.jts.orbspecific.resources.demosync)1 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)1