use of com.arjuna.ats.jts.ExplicitInterposition 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.jts.ExplicitInterposition in project narayana by jbosstm.
the class HammerObject method get.
public boolean get(IntHolder value, Control control) throws SystemException {
boolean res = false;
ExplicitInterposition inter = new ExplicitInterposition();
try {
inter.registerTransaction(control);
} catch (Exception e) {
System.err.println("WARNING HammerObject.incr - could not do interposition");
return false;
}
CurrentImple current = OTSImpleManager.current();
try {
current.begin();
if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED) {
value.value = _value;
current.commit(true);
res = true;
} else
current.rollback();
} catch (Exception e) {
System.err.println("HammerObject.get: " + e);
res = false;
}
inter.unregisterTransaction();
return res;
}
use of com.arjuna.ats.jts.ExplicitInterposition in project narayana by jbosstm.
the class HammerObject method incr.
public boolean incr(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.incr - could not do interposition");
return false;
}
CurrentImple current = OTSImpleManager.current();
try {
current.begin();
if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
_value = _value + value;
current.commit(true);
res = true;
} else
current.rollback();
} catch (Exception e) {
System.err.println("HammerObject.incr: " + e);
res = false;
}
inter.unregisterTransaction();
return res;
}
use of com.arjuna.ats.jts.ExplicitInterposition in project narayana by jbosstm.
the class PropagationContextManager method importTransactionPropagationContext.
/**
* Import the transaction propagation context into the transaction manager,
* and return the resulting transaction. If this transaction propagation
* context has already been imported into the transaction manager, this
* method simply returns the <code>Transaction</code> representing the
* transaction propagation context in the local VM. Returns
* <code>null</code> if the transaction propagation context is
* <code>null</code>, or if it represents a <code>null</code> transaction.
*/
public Transaction importTransactionPropagationContext(Object tpc) {
if (jbossatxLogger.logger.isTraceEnabled()) {
jbossatxLogger.logger.trace("PropagationContextManager.importTransactionPropagationContext(Object) - called tpc = " + tpc);
}
javax.transaction.TransactionManager tm = TransactionManager.transactionManager();
if (tpc instanceof PropagationContextWrapper) {
try {
PropagationContext omgTpc = ((PropagationContextWrapper) tpc).getPropagationContext();
ExplicitInterposition ei = new ExplicitInterposition(omgTpc, true);
Transaction newTx = tm.getTransaction();
if (jbossatxLogger.logger.isTraceEnabled()) {
jbossatxLogger.logger.trace("PropagationContextManager.importTransactionPropagationContext(Object) - transaction = " + newTx);
}
ei.unregisterTransaction();
return newTx;
} catch (Exception e) {
jbossatxLogger.i18NLogger.error_jts_PropagationContextManager_exception(e);
return null;
}
} else {
jbossatxLogger.i18NLogger.error_jts_PropagationContextManager_unknownctx();
return null;
}
}
use of com.arjuna.ats.jts.ExplicitInterposition in project narayana by jbosstm.
the class ExplicitInterpositionUnitTest method test.
@Test
public void test() throws Exception {
ExplicitStackImple stack = new ExplicitStackImple();
OTSImpleManager.current().begin();
assertEquals(stack.push(10, OTSImpleManager.current().get_control()), 0);
OTSImpleManager.current().rollback();
OTSImpleManager.current().begin();
ExplicitInterposition inter = new ExplicitInterposition(OTSImpleManager.current().get_control().get_coordinator().get_txcontext(), true);
inter.unregisterTransaction();
OTSImpleManager.current().rollback();
}
Aggregations