use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class AITCounterImpl01 method set.
public void set(int value) throws InvocationException {
try {
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) {
throw invocationException;
} catch (Exception exception) {
System.err.println("AITCounterImpl01.set: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
throw new InvocationException();
}
} catch (InvocationException invocationException) {
throw invocationException;
} catch (Exception exception) {
System.err.println("AITCounterImpl01.set: " + exception);
throw new InvocationException();
}
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class AITCounterImpl01 method get.
public void get(IntHolder value) throws InvocationException {
try {
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) {
throw invocationException;
} catch (Exception exception) {
System.err.println("AITCounterImpl01.get: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
throw new InvocationException();
}
} 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 Client19 method main.
public static void main(String[] args) {
boolean correct = true;
int numberOfCalls = 10;
Counter counter = null;
System.err.println("Starting first init");
try {
ORBInterface.initORB(args, null);
OAInterface.initOA();
} catch (Exception exception) {
correct = false;
System.err.println("exception in first start: " + exception);
exception.printStackTrace(System.err);
}
System.err.println("Starting first block");
try {
String counterIOR = ServerIORStore.loadIOR(args[args.length - 1]);
counter = CounterHelper.narrow(ORBInterface.orb().string_to_object(counterIOR));
for (int index = 0; index < numberOfCalls; index++) {
AtomicTransaction atomicTransaction = new AtomicTransaction();
atomicTransaction.begin();
counter.increase(OTS.current().get_control());
if ((index % 2) == 0) {
atomicTransaction.commit(true);
} else {
atomicTransaction.rollback();
}
}
AtomicTransaction atomicTransaction = new AtomicTransaction();
atomicTransaction.begin();
IntHolder value = new IntHolder();
counter.get(value, OTS.current().get_control());
atomicTransaction.commit(true);
if (value.value == (numberOfCalls / 2) && correct) {
correct = true;
} else {
correct = false;
}
} catch (Exception exception) {
correct = false;
System.err.println("exception in first block" + exception);
exception.printStackTrace(System.err);
}
System.err.println("Starting first shutdown");
try {
OAInterface.shutdownOA();
ORBInterface.shutdownORB();
} catch (Exception exception) {
correct = false;
System.err.println("exception in first shutdown" + exception);
exception.printStackTrace(System.err);
}
System.err.println("----Starting second block -------");
try {
ORBInterface.initORB(args, null);
OAInterface.initOA();
} catch (Exception exception) {
correct = false;
System.err.println("exception in second start " + exception);
exception.printStackTrace(System.err);
}
System.err.println("init done starting second block");
try {
String counterIOR = ServerIORStore.loadIOR(args[args.length - 1]);
counter = CounterHelper.narrow(ORBInterface.orb().string_to_object(counterIOR));
AtomicTransaction atomicTransaction = new AtomicTransaction();
atomicTransaction.begin();
counter.set(0, OTS.current().get_control());
atomicTransaction.commit(true);
} catch (Exception exception) {
correct = false;
System.err.println("exception in set operation " + exception);
exception.printStackTrace(System.err);
}
try {
for (int index = 0; index < numberOfCalls; index++) {
AtomicTransaction atomicTransaction = new AtomicTransaction();
atomicTransaction.begin();
counter.increase(OTS.current().get_control());
if ((index % 2) == 0) {
atomicTransaction.commit(true);
} else {
atomicTransaction.rollback();
}
}
} catch (Exception exception) {
correct = false;
System.err.println("exception in second loop block " + exception);
exception.printStackTrace(System.err);
}
try {
AtomicTransaction atomicTransaction = new AtomicTransaction();
atomicTransaction.begin();
IntHolder value = new IntHolder();
counter.get(value, OTS.current().get_control());
atomicTransaction.commit(true);
if (value.value == (numberOfCalls / 2) && correct) {
correct = true;
} else {
correct = false;
}
} catch (Exception exception) {
correct = false;
System.err.println("exception in second test " + exception);
exception.printStackTrace(System.err);
}
System.err.println("Starting second shutdown");
try {
OAInterface.shutdownOA();
ORBInterface.shutdownORB();
} catch (Exception exception) {
correct = false;
System.err.println("error in second shutdown" + exception);
exception.printStackTrace(System.err);
}
System.err.println("testing result");
if (correct) {
System.out.println("Passed");
} else {
System.out.println("Failed");
}
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class AITCounterImpl04 method increase.
public void increase(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), super.waitTotalTimeout) == LockResult.GRANTED) {
_value++;
atomicTransaction.commit(true);
} else {
atomicTransaction.rollback();
throw new InvocationException();
}
} catch (InvocationException invocationException) {
interposition.unregisterTransaction();
throw invocationException;
} catch (Exception exception) {
System.err.println("AITCounterImpl04.increase: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
interposition.unregisterTransaction();
throw new InvocationException();
} catch (Error error) {
System.err.println("AITCounterImpl04.increase: " + 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("AITCounterImpl04.increase: " + exception);
throw new InvocationException();
}
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class AITCounterImpl04 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), super.waitTotalTimeout) == 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("AITCounterImpl04.get: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
interposition.unregisterTransaction();
throw new InvocationException();
} catch (Error error) {
System.err.println("AITCounterImpl04.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("AITCounterImpl04.get: " + exception);
throw new InvocationException();
}
}
Aggregations