use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class AITCounterImpl01 method get.
public void get(IntHolder 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.READ), 0) == LockResult.GRANTED) {
value.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.get: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
interposition.unregisterTransaction();
throw new InvocationException();
} catch (Error error) {
System.err.println("AITCounterImpl01.get: " + 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.get: " + exception);
throw new InvocationException();
}
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class AITPingPongImpl01 method get.
public void get(IntHolder 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.READ), 0) == LockResult.GRANTED) {
value.value = _value;
atomicTransaction.commit(true);
} else {
System.err.println("AITPingPongImpl01.get: failed to get lock");
atomicTransaction.rollback();
throw new InvocationException();
}
} catch (InvocationException invocationException) {
interposition.unregisterTransaction();
throw invocationException;
} catch (Exception exception) {
System.err.println("AITPingPongImpl01.get: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
interposition.unregisterTransaction();
throw new InvocationException();
} catch (Error error) {
System.err.println("AITPingPongImpl01.get: " + 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("AITPingPongImpl01.get: " + exception);
throw new InvocationException();
} catch (Error error) {
System.err.println("AITPingPongImpl01.get: " + error);
throw new InvocationException();
}
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class AITPingPongImpl01 method hit.
public void hit(int count, PingPong ponger, PingPong pinger, 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 (count != 0) {
ponger.hit(count - 1, pinger, ponger, OTS.current().get_control());
atomicTransaction.commit(true);
} else if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
_value++;
atomicTransaction.commit(true);
} else {
System.err.println("AITPingPongImpl01.hit: failed to get lock");
atomicTransaction.rollback();
throw new InvocationException();
}
} catch (InvocationException invocationException) {
interposition.unregisterTransaction();
throw invocationException;
} catch (Exception exception) {
System.err.println("AITPingPongImpl01.hit: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
interposition.unregisterTransaction();
throw new InvocationException();
} catch (Error error) {
System.err.println("AITPingPongImpl01.hit: " + 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("AITPingPongImpl01.hit: " + exception);
throw new InvocationException();
} catch (Error error) {
System.err.println("AITPingPongImpl01.hit: " + error);
throw new InvocationException();
}
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class Client16 method main.
public static void main(String[] args) {
try {
ORBInterface.initORB(args, null);
OAInterface.initOA();
String counterIOR = ServerIORStore.loadIOR(args[args.length - 3]);
Counter counter = CounterHelper.narrow(ORBInterface.orb().string_to_object(counterIOR));
int numberOfWorkers = Integer.parseInt(args[args.length - 2]);
int numberOfCalls = Integer.parseInt(args[args.length - 1]);
Worker[] workers = new Worker[numberOfWorkers];
for (int index = 0; index < workers.length; index++) {
workers[index] = new Worker(numberOfCalls, counter);
}
for (int index = 0; index < workers.length; index++) {
workers[index].start();
}
boolean correct = true;
for (int index = 0; index < workers.length; index++) {
workers[index].join();
correct = correct && workers[index].isCorrect();
}
IntHolder value = new IntHolder();
AtomicTransaction atomicTransaction = new AtomicTransaction();
atomicTransaction.begin();
counter.get(value);
atomicTransaction.commit(true);
correct = correct && (value.value == (numberOfWorkers * numberOfCalls));
if (correct) {
System.out.println("Passed");
} else {
System.out.println("Failed");
}
} catch (Exception exception) {
System.out.println("Failed");
System.err.println("Client16.main: " + exception);
exception.printStackTrace(System.err);
}
try {
OAInterface.shutdownOA();
ORBInterface.shutdownORB();
} catch (Exception exception) {
System.err.println("Client16.main: " + exception);
exception.printStackTrace(System.err);
}
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class AITCounterImpl04 method increase.
public void increase() throws InvocationException {
try {
AtomicTransaction atomicTransaction = new AtomicTransaction();
try {
atomicTransaction.begin();
if (setlock(new Lock(LockMode.WRITE), super.waitTotalTimeout) == LockResult.GRANTED) {
_value++;
atomicTransaction.commit(true);
} else {
atomicTransaction.rollback();
throw new InvocationException();
}
} catch (InvocationException invocationException) {
throw invocationException;
} catch (Exception exception) {
System.err.println("AITCounterImpl04.increase: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
throw new InvocationException();
}
} catch (InvocationException invocationException) {
throw invocationException;
} catch (Exception exception) {
System.err.println("AITCounterImpl04.increase: " + exception);
throw new InvocationException();
}
}
Aggregations