use of com.arjuna.ats.jts.ExplicitInterposition 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.jts.ExplicitInterposition in project narayana by jbosstm.
the class setget_i method set.
public void set(short n, Control control) throws SystemException {
System.out.println("setget_i.set " + n);
try {
if (control != null) {
ExplicitInterposition manager = new ExplicitInterposition();
manager.registerTransaction(control);
System.out.println("setget_i.set - managed to set up interposition hierarchy");
CurrentImple current = OTSImpleManager.current();
Control cont = current.get_control();
if (cont == null)
System.err.println("setget_i.set error - current returned no control!");
else {
System.out.println("setget_i.set - current returned a control!");
cont = null;
}
System.out.println("setget_i.set - beginning nested action");
current.begin();
cont = current.get_control();
if (cont != null) {
Coordinator coord = cont.get_coordinator();
System.out.println("setget_i.set - registering self");
coord.register_resource(ref);
coord = null;
cont = null;
} else
System.err.println("setget_i.set - current did not return control after begin!");
value = n;
System.out.println("setget_i.set - committing nested action");
current.commit(true);
manager.unregisterTransaction();
manager = null;
} else
System.err.println("setget_i::set error - no control!");
} catch (InterpositionFailed ex) {
System.err.println("setget_i.set - error in setting up hierarchy");
throw new UNKNOWN();
} catch (Throwable e) {
System.err.println("setget_i::set - caught exception: " + e);
}
System.out.println("setget_i.set - finished");
}
use of com.arjuna.ats.jts.ExplicitInterposition 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;
}
Aggregations