use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class TopLevelTransactionUnitTest method testCommit.
@Test
public void testCommit() 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.commit(true);
assertEquals(d.getResourceTrace().getTrace(), ResourceTrace.ResourceTraceCommitOnePhase);
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class ExplicitStackImple method pop.
public int pop(IntHolder 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 pop interposed transaction: " + name);
name = null;
try {
A.begin();
if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
if (top > 0) {
top--;
val.value = array[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;
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class StackImple method printStack.
public void printStack() throws SystemException {
AtomicTransaction A = new AtomicTransaction();
try {
A.begin();
if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
if (top > 0) {
System.out.println("\nContents of stack:");
for (int i = 0; i < top; i++) System.out.println("\t" + array[i]);
} else
System.out.println("\nStack is empty.");
A.commit(false);
} else {
System.out.println("printStack: could not set WRITE lock.");
A.rollback();
}
} catch (Exception e1) {
try {
A.rollback();
} catch (Exception e2) {
System.err.println(e2);
}
}
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class Client18 method main.
public static void main(String[] args) {
try {
ORBInterface.initORB(args, null);
OAInterface.initOA();
int expectedResult = Integer.parseInt(args[args.length - 1]);
int numberOfCalls = Integer.parseInt(args[args.length - 2]);
String counterIOR = ServerIORStore.loadIOR(args[args.length - 3]);
Counter counter = CounterHelper.narrow(ORBInterface.orb().string_to_object(counterIOR));
int index = 0;
boolean expectingFailure;
/* Remove 2 from the number of calls and the expected result
* two transactions occur other than in this loop
* one in the implementation within the server and one
* at the end to return the number from the object
*/
numberOfCalls -= 2;
expectedResult -= 2;
expectingFailure = (numberOfCalls != expectedResult);
System.err.println("expectingFailure = " + expectingFailure);
try {
for (index = 0; index < numberOfCalls; index++) {
AtomicTransaction atomicTransaction = new AtomicTransaction();
atomicTransaction.begin();
counter.increase(OTS.current().get_control());
atomicTransaction.commit(true);
}
} catch (org.omg.CORBA.TRANSACTION_ROLLEDBACK e) {
/*
* If the number of transactions created is equal to the
* expected result then we are not expecting this exception
* to be thrown therefore the test has failed
*/
System.err.println("Performed " + index + " calls when exception thrown");
if (!expectingFailure) {
System.err.println("Got unexpected org.omg.CORBA.TRANSACTION_ROLLEDBACK exception");
throw e;
} else {
System.err.println("Got expected org.omg.CORBA.TRANSACTION_ROLLEDBACK exception");
}
} catch (Exception e) {
System.err.println("Performed " + index + " calls when exception thrown");
throw e;
}
AtomicTransaction atomicTransaction = new AtomicTransaction();
atomicTransaction.begin();
IntHolder value = new IntHolder();
counter.get(value, OTS.current().get_control());
try {
atomicTransaction.commit(true);
} catch (org.omg.CORBA.TRANSACTION_ROLLEDBACK e) {
if (!expectingFailure) {
System.err.println("Got unexpected org.omg.CORBA.TRANSACTION_ROLLEDBACK exception");
throw e;
} else {
System.err.println("Got expected org.omg.CORBA.TRANSACTION_ROLLEDBACK exception");
}
}
if (((!expectingFailure) && (value.value == expectedResult)) || ((expectingFailure) && (value.value != expectedResult))) {
System.out.println("Passed");
} else {
System.out.println("Failed");
}
} catch (Exception exception) {
System.out.println("Failed");
System.err.println("Client18.main: " + exception);
exception.printStackTrace(System.err);
}
try {
OAInterface.shutdownOA();
ORBInterface.shutdownORB();
} catch (Exception exception) {
System.err.println("Client18.main: " + exception);
exception.printStackTrace(System.err);
}
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class AITCounterImpl01 method set.
public void set(int value, Control ctrl) throws InvocationException {
try {
com.arjuna.ats.jts.ExplicitInterposition interposition = new com.arjuna.ats.jts.ExplicitInterposition();
interposition.registerTransaction(ctrl);
AtomicTransaction atomicTransaction = new AtomicTransaction();
try {
atomicTransaction.begin();
if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
_value = value;
atomicTransaction.commit(true);
} else {
atomicTransaction.rollback();
throw new InvocationException();
}
} catch (InvocationException invocationException) {
interposition.unregisterTransaction();
throw invocationException;
} catch (Exception exception) {
System.err.println("AITCounterImpl01.set: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
interposition.unregisterTransaction();
throw new InvocationException();
} catch (Error error) {
System.err.println("AITCounterImpl01.set: " + error);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
interposition.unregisterTransaction();
throw new InvocationException();
}
interposition.unregisterTransaction();
} catch (InvocationException invocationException) {
throw invocationException;
} catch (Exception exception) {
System.err.println("AITCounterImpl01.set: " + exception);
throw new InvocationException();
}
}
Aggregations