use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.
the class TXBasicLockRecord method increase.
/**
* We will start a subtrancastion during the increase to see what effet this has.
*
* @return +1 if tx was committed, 0 if tx was not committed
*/
public int increase(int retry, int wait_time) {
int returnValue = 0;
AtomicAction a = new AtomicAction();
a.begin();
try {
int locking_result = LockResult.REFUSED;
int locking_attempt_count = 0;
do {
locking_result = setlock(new Lock(LockMode.WRITE), retry, wait_time);
if (locking_result == LockResult.GRANTED) {
mValue++;
} else {
locking_attempt_count++;
}
if (timeOfLastWaiting < (System.currentTimeMillis() - 15000)) {
System.out.println("Thread: [" + Thread.currentThread() + "]");
timeOfLastWaiting = System.currentTimeMillis();
}
} while ((locking_result != LockResult.GRANTED) && (locking_attempt_count < mLimit));
if (locking_result != LockResult.GRANTED) {
qautil.qadebug("trying to get lock for " + mLimit + "th time");
a.abort();
} else {
a.commit();
returnValue = 1;
}
} catch (Exception e) {
a.abort();
qautil.debug("exception in increase method ", e);
}
return returnValue;
}
use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.
the class TXBasicLockRecord method getValue.
public int getValue(int retry, int wait_time) {
int return_value = 0;
AtomicAction a = new AtomicAction();
a.begin();
try {
int locking_result = LockResult.REFUSED;
int locking_attempt_count = 0;
do {
locking_result = setlock(new Lock(LockMode.READ), retry, wait_time);
if (locking_result == LockResult.GRANTED) {
return_value = mValue;
} else {
locking_attempt_count++;
}
} while ((locking_result != LockResult.GRANTED) && (locking_attempt_count < mLimit));
if (locking_result != LockResult.GRANTED) {
qautil.qadebug("trying to get lock for " + mLimit + "th time");
}
a.commit();
} catch (Exception e) {
a.abort();
qautil.debug("exception in get method ", e);
}
return return_value;
}
use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.
the class BasicLockRecord2 method increase.
public int increase(int retry, int wait_time) {
int returnValue = 0;
int locking_result = LockResult.REFUSED;
int locking_attempt_count = 0;
Lock lck = new Lock(LockMode.WRITE);
do {
locking_result = setlock(lck, retry, wait_time);
if (locking_result == LockResult.GRANTED) {
mValue++;
} else {
locking_attempt_count++;
}
} while ((locking_result != LockResult.GRANTED) && (locking_attempt_count < mLimit));
if (locking_result != LockResult.GRANTED) {
qautil.qadebug("trying to get lock for " + mLimit + "th time");
} else {
returnValue = 1;
}
return returnValue;
}
use of com.arjuna.ats.txoj.Lock 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.txoj.Lock 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);
}
}
Aggregations