use of com.arjuna.ats.txoj.Lock 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.txoj.Lock 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.txoj.Lock 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.txoj.Lock 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();
}
}
use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.
the class TXBasicLockRecord2 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;
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");
a.abort();
} else {
a.commit();
returnValue = 1;
}
} catch (Exception e) {
a.abort();
qautil.debug("exception in increase method ", e);
}
return returnValue;
}
Aggregations