use of com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class CurrentImple method rollback.
/**
* If another thread has already terminated the transaction then: (i) if it
* rolled back, we do nothing - could throw TransactionRequired of
* INVALID_TRANSACTION, or NoTransaction. Probably not NoTransaction, since
* it would be better to distinguish between the situation where the
* transaction has already been terminated and there really is no
* transaction for this thread. (ii) if it committed, we throw
* INVALID_TRANSACTION.
*/
public void rollback() throws NoTransaction, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("CurrentImple::rollback ()");
}
ControlWrapper currentAction = _theManager.current();
if (currentAction != null) {
ThreadAssociationControl.updateAssociation(currentAction, TX_ABORTED);
try {
currentAction.rollback();
_theManager.popAction();
} catch (INVALID_TRANSACTION e1) {
/*
* If transaction has already terminated, then throw
* INVALID_TRANSACTION. Differentiates between this stat and not
* actually having a transaction associated with the thread.
*/
_theManager.popAction();
throw e1;
} catch (SystemException e2) {
_theManager.popAction();
throw e2;
} catch (Unavailable e) {
/*
* If no terminator then not allowed!
*/
_theManager.popAction();
throw new INVALID_TRANSACTION();
}
} else
throw new NoTransaction();
}
use of com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class CurrentImple method get_status.
public org.omg.CosTransactions.Status get_status() throws SystemException {
ControlWrapper currentAction = _theManager.current();
org.omg.CosTransactions.Status stat = ((currentAction == null) ? org.omg.CosTransactions.Status.StatusNoTransaction : currentAction.get_status());
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("CurrentImple::get_status - returning " + Utility.stringStatus(stat));
}
return stat;
}
use of com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class JTSInterpositionSynchronizationTest method test.
@Test
public void test() throws Exception {
InterpositionCreator creator = new InterpositionCreator();
jtaPropertyManager.getJTAEnvironmentBean().setTransactionManagerClassName(com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple.class.getName());
jtaPropertyManager.getJTAEnvironmentBean().setUserTransactionClassName(com.arjuna.ats.internal.jta.transaction.jts.UserTransactionImple.class.getName());
jtsPropertyManager.getJTSEnvironmentBean().setSupportInterposedSynchronization(true);
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.setTransactionTimeout(1000000);
tm.begin();
TransactionImple transaction = (TransactionImple) tm.getTransaction();
transaction.enlistResource(new XAResource() {
@Override
public int prepare(Xid arg0) throws XAException {
prepareCalled = true;
beforeCompletionCalledFirst = beforeCompletionCalled;
return 0;
}
@Override
public void commit(Xid arg0, boolean arg1) throws XAException {
}
@Override
public void end(Xid arg0, int arg1) throws XAException {
}
@Override
public void forget(Xid arg0) throws XAException {
}
@Override
public int getTransactionTimeout() throws XAException {
return 0;
}
@Override
public boolean isSameRM(XAResource arg0) throws XAException {
return false;
}
@Override
public Xid[] recover(int arg0) throws XAException {
return null;
}
@Override
public void rollback(Xid arg0) throws XAException {
}
@Override
public boolean setTransactionTimeout(int arg0) throws XAException {
return false;
}
@Override
public void start(Xid arg0, int arg1) throws XAException {
}
});
ControlWrapper controlWrapper = transaction.getControlWrapper();
Uid get_uid = transaction.get_uid();
ControlImple cont = controlWrapper.getImple();
ArjunaTransactionImple tx = cont.getImplHandle();
CurrentImple current = OTSImpleManager.current();
Control get_control = current.get_control();
PropagationContext ctx = cont.get_coordinator().get_txcontext();
ControlImple recreateLocal = creator.recreateLocal(ctx);
assertTrue(recreateLocal != null);
Control recreate = creator.recreate(ctx);
assertTrue(recreate != null);
Object remove = ControlImple.allControls.remove(get_uid);
ServerControl sc = new ServerControl(get_uid, get_control, null, cont.get_coordinator(), cont.get_terminator());
ControlImple.allControls.put(get_uid, remove);
ServerTopLevelAction serverTopLevelAction = new ServerTopLevelAction(sc);
sc.getImplHandle().register_synchronization(new ManagedSynchronizationImple(new Synchronization() {
@Override
public void beforeCompletion() {
beforeCompletionCalled = true;
}
@Override
public void afterCompletion(int status) {
afterCompletionCalled = true;
}
}).getSynchronization());
transaction.commit();
assertTrue(prepareCalled == true);
assertTrue(beforeCompletionCalled);
assertTrue(afterCompletionCalled);
assertTrue(beforeCompletionCalledFirst == jtsPropertyManager.getJTSEnvironmentBean().isSupportInterposedSynchronization());
}
use of com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class ContextManager method createProxy.
public final ControlWrapper createProxy(org.omg.CORBA.Any ctx) throws SystemException {
String stringRef = null;
try {
stringRef = ctx.extract_string();
if (stringRef.startsWith(IORTag)) {
org.omg.CORBA.Object obj = ORBManager.getORB().orb().string_to_object(stringRef);
Coordinator theCoordinator = org.omg.CosTransactions.CoordinatorHelper.narrow(obj);
if (theCoordinator == null)
throw new BAD_PARAM();
return new ControlWrapper(TransactionFactoryImple.createProxy(theCoordinator, null));
} else
return null;
} catch (BAD_PARAM e1) {
jtsLogger.i18NLogger.warn_context_genfail("ContextManager " + stringRef, e1);
} catch (Exception e2) {
jtsLogger.i18NLogger.warn_context_genfail("ContextManager", e2);
throw new UNKNOWN(e2.toString());
}
return null;
}
use of com.arjuna.ats.internal.jts.ControlWrapper in project narayana by jbosstm.
the class InterpositionServerRequestInterceptorImpl method suspendContext.
/*
* If there is a thread id associated with PICurrent then it will
* have been placed there by a server-side thread which executed in
* the application object and needed to associate an imported
* transaction with itself. In which case we need to do the
* equivalent of a suspend to remove the thread from Current and
* from the current transaction.
*/
private void suspendContext(ServerRequestInfo request_info) throws SystemException, InvalidSlot {
if (jtsLogger.logger.isTraceEnabled()) {
trace_request("suspendContext", request_info);
}
Any data = request_info.get_slot(_dataSlot);
if ((data != null) && (data.type().kind().value() != TCKind._tk_null)) {
String threadId = null;
try {
if ((threadId = data.extract_string()) != null) {
// ControlWrapper ctx = OTSImpleManager.systemCurrent().contextManager().popAction(threadId);
ControlWrapper ctx = OTSImpleManager.current().contextManager().popAction(threadId);
// OTSImpleManager.systemCurrent().contextManager().purgeActions(threadId);
OTSImpleManager.current().contextManager().purgeActions(threadId);
}
} catch (BAD_OPERATION bex) {
// not a string, so still a pgcts
}
request_info.set_slot(_dataSlot, null);
}
}
Aggregations