use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.
the class ExplicitStackImple method push.
public int push(int 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 push interposed transaction: " + name);
name = null;
try {
A.begin();
if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
if (top < ARRAY_SIZE) {
array[top] = val;
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 ExplicitStackImple 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 StackImple method push.
public int push(int val) throws SystemException {
AtomicTransaction A = new AtomicTransaction();
int res = 0;
try {
A.begin();
if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
if (top < ARRAY_SIZE) {
array[top] = val;
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;
}
return res;
}
use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.
the class StackImple method pop.
public int pop(IntHolder val) throws SystemException {
AtomicTransaction A = new AtomicTransaction();
int res = 0;
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;
}
return res;
}
use of com.arjuna.ats.txoj.Lock in project narayana by jbosstm.
the class AtomicObject method get.
public synchronized int get() throws TestException {
CurrentImple current = OTSImpleManager.current();
int value = -1;
try {
current.begin();
if (setlock(new Lock(LockMode.READ), 5) == LockResult.GRANTED) {
value = _value;
current.commit(false);
return value;
} else {
current.rollback();
throw new TestException("Could not setlock");
}
} catch (Exception e) {
throw new TestException(e);
}
}
Aggregations