use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.
the class ExplicitStackImple method pop.
public int pop(IntHolder val, Control action) throws SystemException {
AtomicTransaction A = new AtomicTransaction();
int res = 0;
ExplicitInterposition inter = new ExplicitInterposition();
try {
inter.registerTransaction(action);
} catch (Exception e) {
System.err.println("WARNING ExplicitStackImple::push - could not create interposition.");
return -1;
}
String name = OTSImpleManager.current().get_transaction_name();
System.out.println("Created pop interposed transaction: " + name);
name = null;
try {
A.begin();
if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
if (top > 0) {
top--;
val.value = array[top];
} else
res = -1;
if (res == 0) {
A.commit(false);
} else
A.rollback();
} else {
A.rollback();
}
} catch (Exception e1) {
try {
A.rollback();
} catch (Exception e2) {
System.err.println(e2);
}
res = -1;
}
inter.unregisterTransaction();
return res;
}
use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.
the class StackImple method printStack.
public void printStack() throws SystemException {
AtomicTransaction A = new AtomicTransaction();
try {
A.begin();
if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
if (top > 0) {
System.out.println("\nContents of stack:");
for (int i = 0; i < top; i++) System.out.println("\t" + array[i]);
} else
System.out.println("\nStack is empty.");
A.commit(false);
} else {
System.out.println("printStack: could not set WRITE lock.");
A.rollback();
}
} catch (Exception e1) {
try {
A.rollback();
} catch (Exception e2) {
System.err.println(e2);
}
}
}
use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.
the class AtomicObject method set.
public synchronized boolean set(int value) {
boolean res = false;
CurrentImple current = OTSImpleManager.current();
try {
current.begin();
if (setlock(new Lock(LockMode.WRITE), 5) == LockResult.GRANTED) {
_value = value;
current.commit(false);
res = true;
} else
current.rollback();
} catch (Exception e) {
logger.info(e);
logger.warn(e.getMessage(), e);
res = false;
}
return res;
}
use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.
the class HammerObject method set.
public boolean set(int value, Control control) throws SystemException {
boolean res = false;
ExplicitInterposition inter = new ExplicitInterposition();
try {
inter.registerTransaction(control);
} catch (Exception e) {
System.err.println("WARNING HammerObject.set - could not do interposition");
return false;
}
CurrentImple current = OTSImpleManager.current();
try {
current.begin();
if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
_value = value;
current.commit(true);
res = true;
} else
current.rollback();
} catch (Exception e) {
System.err.println("HammerObject.set: " + e);
res = false;
}
inter.unregisterTransaction();
return res;
}
use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.
the class LockManagerProxyUnitTest method testTransactionalUpdate.
public void testTransactionalUpdate() {
ExtendedLockable sample = new ExtendedLockable();
LockManagerProxy<ExtendedLockable> proxy = new LockManagerProxy<ExtendedLockable>(sample);
assertNotNull(proxy.type());
AtomicAction A = new AtomicAction();
A.begin();
sample._isState = new Double(1.0);
assertEquals(proxy.setlock(new Lock(LockMode.WRITE)), LockResult.GRANTED);
sample._isState = new Double(4.0);
A.abort();
assertEquals(sample._isState, new Double(1.0));
}
Aggregations