use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class AITMatrixImpl01 method get_value.
public void get_value(int x, int y, IntHolder value, Control ctrl) throws InvocationException {
if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) {
throw new InvocationException(Reason.ReasonUnknown);
}
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 = _values[x][y];
atomicTransaction.commit(true);
} else {
atomicTransaction.rollback();
throw new InvocationException(Reason.ReasonConcurrencyControl);
}
} catch (InvocationException invocationException) {
interposition.unregisterTransaction();
throw invocationException;
} catch (Exception exception) {
System.err.println("AITMatrixImpl01.get_value: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
interposition.unregisterTransaction();
throw new InvocationException(Reason.ReasonUnknown);
} catch (Error error) {
System.err.println("AITMatrixImpl01.get_value: " + error);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
interposition.unregisterTransaction();
throw new InvocationException(Reason.ReasonUnknown);
}
interposition.unregisterTransaction();
} catch (InvocationException invocationException) {
throw invocationException;
} catch (Exception exception) {
System.err.println("AITMatrixImpl01.get_value: " + exception);
throw new InvocationException(Reason.ReasonUnknown);
}
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class AITMatrixImpl03 method get_value.
public void get_value(int x, int y, IntHolder value) throws InvocationException {
if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) {
throw new InvocationException(Reason.ReasonUnknown);
}
try {
AtomicTransaction atomicTransaction = new AtomicTransaction();
try {
atomicTransaction.begin();
if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED) {
try {
_values[x][y].get_value(value);
atomicTransaction.commit(true);
} catch (InvocationException invocationException) {
atomicTransaction.rollback();
throw invocationException;
}
} else {
atomicTransaction.rollback();
throw new InvocationException(Reason.ReasonConcurrencyControl);
}
} catch (InvocationException invocationException) {
throw invocationException;
} catch (Exception exception) {
System.err.println("AITMatrixImpl03.get_value: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
throw new InvocationException(Reason.ReasonUnknown);
}
} catch (InvocationException invocationException) {
throw invocationException;
} catch (Exception exception) {
System.err.println("AITMatrixImpl03.get_value: " + exception);
throw new InvocationException(Reason.ReasonUnknown);
}
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction 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 com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class CounterImpl0001 method increase.
public void increase() throws InvocationException {
try {
AtomicTransaction atomicTransaction = new AtomicTransaction();
try {
atomicTransaction.begin();
if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
_value++;
atomicTransaction.commit(true);
} else {
atomicTransaction.rollback();
throw new InvocationException();
}
} catch (InvocationException invocationException) {
throw invocationException;
} catch (Exception exception) {
System.err.println("CounterImpl0001.increase: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
throw new InvocationException();
}
} catch (InvocationException invocationException) {
throw invocationException;
} catch (Exception exception) {
System.err.println("CounterImpl0001.increase: " + exception);
throw new InvocationException();
}
throw new InvocationException();
}
use of com.arjuna.ats.jts.extensions.AtomicTransaction in project narayana by jbosstm.
the class CounterImpl0001 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("CounterImpl0001.set: " + exception);
if (atomicTransaction.get_status() == Status.StatusActive) {
atomicTransaction.rollback();
}
throw new InvocationException();
}
} catch (InvocationException invocationException) {
throw invocationException;
} catch (Exception exception) {
System.err.println("CounterImpl0001.set: " + exception);
throw new InvocationException();
}
}
Aggregations