use of org.omg.CORBA.IntHolder in project narayana by jbosstm.
the class Client02 method operation.
private static boolean operation() throws Exception {
boolean successful = false;
try {
AtomicTransaction atomicTransaction = new AtomicTransaction();
try {
atomicTransaction.begin();
try {
int d = Math.abs(_random.nextInt() % 10) + 1;
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 location0Value = new IntHolder();
IntHolder location1Value = new IntHolder();
Control control = OTS.current().get_control();
_matrix.get_value(x0, y0, location0Value, control);
_matrix.get_value(x1, y1, location1Value, control);
_matrix.set_value(x0, y0, location1Value.value + d, control);
_matrix.set_value(x1, y1, location0Value.value - d, control);
successful = (x0 != x1) || (y0 != y1);
} 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("Client02.operation: " + exception);
exception.printStackTrace(System.err);
throw exception;
}
return successful;
}
use of org.omg.CORBA.IntHolder in project narayana by jbosstm.
the class Client02 method operation.
private static boolean operation() throws Exception {
boolean successful = false;
try {
AtomicTransaction atomicTransaction = new AtomicTransaction();
try {
atomicTransaction.begin();
try {
int d = Math.abs(_random.nextInt() % 10) + 1;
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 location0Value = new IntHolder();
IntHolder location1Value = new IntHolder();
_matrix.get_value(x0, y0, location0Value);
_matrix.get_value(x1, y1, location1Value);
_matrix.set_value(x0, y0, location1Value.value + d);
_matrix.set_value(x1, y1, location0Value.value - d);
successful = (x0 != x1) || (y0 != y1);
} 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("Client02.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, OTS.current().get_control());
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 Client01 method main.
public static void main(String[] args) {
try {
ORBInterface.initORB(args, null);
OAInterface.initOA();
String numberTableIOR = ServerIORStore.loadIOR(args[args.length - 1]);
NumberTable numberTable = NumberTableHelper.narrow(ORBInterface.orb().string_to_object(numberTableIOR));
boolean correct = true;
OTS.current().begin();
IntHolder valueHolder1 = new IntHolder();
IntHolder valueHolder2 = new IntHolder();
IntHolder valueHolder3 = new IntHolder();
IntHolder valueHolder4 = new IntHolder();
numberTable.get("Name_0", valueHolder1, OTS.current().get_control());
numberTable.get("Name_1", valueHolder2, OTS.current().get_control());
System.err.println("Phase 0, Name_0: " + valueHolder1.value);
System.err.println("Phase 0, Name_1: " + valueHolder2.value);
numberTable.increase("Name_0", OTS.current().get_control());
Thread.sleep(15000);
numberTable.increase("Name_1", OTS.current().get_control());
numberTable.get("Name_0", valueHolder3, OTS.current().get_control());
numberTable.get("Name_1", valueHolder4, OTS.current().get_control());
System.err.println("Phase 1, Name_0: " + valueHolder3.value);
System.err.println("Phase 1, Name_1: " + valueHolder4.value);
OTS.current().commit(true);
correct = (valueHolder1.value == valueHolder2.value) && (valueHolder3.value == valueHolder4.value) && (valueHolder1.value == (valueHolder3.value - 1)) && (valueHolder2.value == (valueHolder4.value - 1));
if (correct) {
System.out.println("Passed");
} else {
System.out.println("Failed");
}
} catch (InvocationException exception) {
if (exception.myreason == Reason.ReasonCantSerializeAccess) {
System.out.println("Passed");
} else {
System.out.println("Failed");
}
System.err.println("Client01.main: " + exception);
exception.printStackTrace(System.err);
} catch (Exception exception) {
System.out.println("Failed");
System.err.println("Client01.main: " + exception);
exception.printStackTrace(System.err);
} finally {
// code change to stop database locking
try {
if (OTS.current().get_control() != null) {
OTS.current().rollback();
}
} catch (Exception e) {
System.err.println("Finally has caught exception");
e.printStackTrace(System.err);
}
}
try {
OAInterface.shutdownOA();
ORBInterface.shutdownORB();
} catch (Exception exception) {
System.err.println("Client01.main: " + exception);
exception.printStackTrace(System.err);
}
}
use of org.omg.CORBA.IntHolder in project alliance by codice.
the class NsiliSource method getHitCount.
/**
* Obtains the number of hits that the given query has received from the server.
*
* @param query - a BQS query
* @param properties - a list of properties for the query
* @return - the hit count
*/
private int getHitCount(org.codice.alliance.nsili.common.GIAS.Query query, NameValue[] properties) {
IntHolder intHolder = new IntHolder();
try {
synchronized (queryLockObj) {
HitCountRequest hitCountRequest = catalogMgr.hit_count(query, properties);
hitCountRequest.complete(intHolder);
}
} catch (ProcessingFault | SystemFault | InvalidInputParameter e) {
LOGGER.debug("{} : Unable to get hit count for query. : {}", getId(), NsilCorbaExceptionUtil.getExceptionDetails(e), e);
}
LOGGER.debug("{} : Received {} hit(s) from query.", getId(), intHolder.value);
return intHolder.value;
}
Aggregations