use of org.omg.CORBA.IntHolder in project narayana by jbosstm.
the class Client01 method operation.
private static boolean operation() throws Exception {
boolean successful = false;
try {
AtomicTransaction atomicTransaction = new AtomicTransaction();
try {
atomicTransaction.begin();
try {
int x0 = Math.abs(_random.nextInt() % _matrixWidth);
int y0 = Math.abs(_random.nextInt() % _matrixHeight);
int x1 = Math.abs(_random.nextInt() % _matrixWidth);
int y1 = Math.abs(_random.nextInt() % _matrixHeight);
IntHolder srcValue = new IntHolder();
IntHolder dstValue = new IntHolder();
Control control = OTS.current().get_control();
_matrix.get_value(x0, y0, srcValue, control);
if (srcValue.value == 1) {
_matrix.get_value(x1, y1, dstValue, control);
if (dstValue.value == 0) {
_matrix.set_value(x0, y0, 0, control);
_matrix.set_value(x1, y1, 1, control);
successful = true;
}
}
} catch (InvocationException invocationException) {
if (invocationException.myreason != Reason.ReasonConcurrencyControl) {
throw invocationException;
}
}
if (successful) {
atomicTransaction.commit(true);
} else {
atomicTransaction.rollback();
}
} catch (Exception exception) {
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
throw exception;
}
} catch (Exception exception) {
System.err.println("Client01.operation: " + exception);
exception.printStackTrace(System.err);
throw exception;
}
return successful;
}
use of org.omg.CORBA.IntHolder in project narayana by jbosstm.
the class Outcome01 method main.
public static void main(String[] args) {
try {
ORBInterface.initORB(args, null);
OAInterface.initOA();
int maxIndex = Integer.parseInt(args[args.length - 2]);
String numberTableIOR = ServerIORStore.loadIOR(args[args.length - 1]);
NumberTable numberTable = NumberTableHelper.narrow(ORBInterface.orb().string_to_object(numberTableIOR));
boolean correct = true;
OTS.current().begin();
for (int index = 0; correct && (index < maxIndex); index++) {
String name = "Name_" + index;
IntHolder valueHolder = new IntHolder();
numberTable.get(name, valueHolder);
correct = correct && (valueHolder.value == maxIndex);
}
OTS.current().commit(true);
if (correct) {
System.out.println("Passed");
} else {
System.out.println("Failed");
}
} catch (Exception exception) {
System.out.println("Failed");
System.err.println("Outcome01.main: " + exception);
exception.printStackTrace(System.err);
}
try {
OAInterface.shutdownOA();
ORBInterface.shutdownORB();
} catch (Exception exception) {
System.err.println("Outcome01.main: " + exception);
exception.printStackTrace(System.err);
}
}
use of org.omg.CORBA.IntHolder in project narayana by jbosstm.
the class Client11 method main.
public static void main(String[] args) {
try {
ORBInterface.initORB(args, null);
OAInterface.initOA();
String pingerIOR = ServerIORStore.loadIOR(args[args.length - 2]);
PingPong pinger = PingPongHelper.narrow(ORBInterface.orb().string_to_object(pingerIOR));
String pongerIOR = ServerIORStore.loadIOR(args[args.length - 1]);
PingPong ponger = PingPongHelper.narrow(ORBInterface.orb().string_to_object(pongerIOR));
int numberOfCalls = 10;
for (int index0 = 0; index0 < numberOfCalls; index0++) {
for (int index1 = 0; index1 <= index0; index1++) {
pinger.bad_hit(index0, index1, ponger, pinger);
}
}
IntHolder pingerValue = new IntHolder();
pinger.get(pingerValue);
IntHolder pongerValue = new IntHolder();
ponger.get(pongerValue);
if ((pingerValue.value == 0) && (pongerValue.value == 0)) {
System.out.println("Passed");
} else {
System.out.println("Failed");
}
} catch (Exception exception) {
System.out.println("Failed");
System.err.println("Client11.main: " + exception);
exception.printStackTrace(System.err);
}
try {
OAInterface.shutdownOA();
ORBInterface.shutdownORB();
} catch (Exception exception) {
System.err.println("Client11.main: " + exception);
exception.printStackTrace(System.err);
}
}
use of org.omg.CORBA.IntHolder 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();
if ((index % 2) == 0) {
atomicTransaction.commit(true);
} else {
atomicTransaction.rollback();
}
}
AtomicTransaction atomicTransaction = new AtomicTransaction();
atomicTransaction.begin();
IntHolder value = new IntHolder();
counter.get(value);
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);
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();
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);
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 org.omg.CORBA.IntHolder in project narayana by jbosstm.
the class Client02 method main.
public static void main(String[] args) {
try {
ORBInterface.initORB(args, null);
OAInterface.initOA();
String counterIOR = ServerIORStore.loadIOR(args[args.length - 1]);
Counter counter = CounterHelper.narrow(ORBInterface.orb().string_to_object(counterIOR));
int numberOfCalls = 1000;
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)) {
System.out.println("Passed");
} else {
System.out.println("Failed");
}
} catch (Exception exception) {
System.out.println("Failed");
System.err.println("Client02.main: " + exception);
exception.printStackTrace(System.err);
}
try {
OAInterface.shutdownOA();
ORBInterface.shutdownORB();
} catch (Exception exception) {
System.err.println("Client02.main: " + exception);
exception.printStackTrace(System.err);
}
}
Aggregations