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);
}
}
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);
}
}
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();
}
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);
}
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);
}
Aggregations