use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction in project narayana by jbosstm.
the class Interposition method createHierarchy.
protected synchronized ControlImple createHierarchy(PropagationContext ctx, Uid tlUid) throws SystemException {
/*
* Start at the parent and work our way down to "current". The current
* transaction is not in the IDL sequence, but sent as separate field
* of the propagation context. This tends to make the code more
* complex than it would be if the entire hierarchy was represented in
* one place.
*/
int depth = ctx.parents.length;
ServerResource action = null;
Coordinator tmpCoord = null;
Terminator tmpTerm = null;
if (depth == 0) {
tmpCoord = ctx.current.coord;
tmpTerm = ctx.current.term;
} else {
tmpCoord = ctx.parents[depth - 1].coord;
tmpTerm = ctx.parents[depth - 1].term;
}
if (// terminator may correctly be null
tmpCoord == null) {
return null;
}
ServerControl control = ServerFactory.create_transaction(tlUid, null, null, tmpCoord, tmpTerm, ctx.timeout);
action = new ServerTopLevelAction(control);
if (!action.valid()) {
try {
// does dispose as well!
((ServerTopLevelAction) action).rollback();
} catch (Exception e) {
}
if (((ServerTopLevelAction) action).isTransactionInactive()) {
throw new TRANSACTION_UNAVAILABLE(jtsLogger.i18NLogger.get_transaction_was_inactive(), 1, CompletionStatus.COMPLETED_NO);
} else {
throw new TRANSACTION_ROLLEDBACK();
}
}
ServerTopLevelAction newElement = (ServerTopLevelAction) action;
_head.add(newElement);
if (// current is a nested transaction
depth > 0) {
/*
* Now deal with any nested transactions.
* As we create, register with the original transactions.
*/
ServerResource nestedAction = null;
for (int i = depth - 2; i >= 0; i--) {
tmpCoord = ctx.parents[i].coord;
tmpTerm = ctx.parents[i].term;
control = ServerFactory.create_subtransaction(Utility.otidToUid(ctx.parents[i].otid), tmpCoord, tmpTerm, control);
nestedAction = new ServerNestedAction(control);
if (!nestedAction.valid()) {
try {
// does dispose as well!
((ServerNestedAction) nestedAction).rollback_subtransaction();
nestedAction = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
/*
* Add transaction resource to list.
*/
action.addChild((ServerNestedAction) nestedAction);
action = nestedAction;
}
/*
* Now deal with current transaction. If there is
* only one transaction we do nothing.
*/
tmpCoord = ctx.current.coord;
tmpTerm = ctx.current.term;
control = ServerFactory.create_subtransaction(Utility.otidToUid(ctx.current.otid), tmpCoord, tmpTerm, control);
nestedAction = new ServerNestedAction(control);
if (!nestedAction.valid()) {
try {
// does dispose as well!
((ServerNestedAction) nestedAction).rollback_subtransaction();
nestedAction = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
action.addChild((ServerNestedAction) nestedAction);
}
if (jtsLogger.logger.isTraceEnabled())
compareHierarchies(ctx, newElement);
return control;
}
use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction in project narayana by jbosstm.
the class RestrictedInterposition method setupHierarchy.
/*
* Assume that all actions in the imported hierarchy are of the same type,
* i.e., all JBoss transactions. Because of the way garbage collection works
* in the ORB we have to run an explicit garbage collection phase for
* finished hierarchies.
*/
public synchronized ControlImple setupHierarchy(PropagationContext context) throws SystemException {
ControlImple controlPtr = null;
Uid theUid = null;
ServerTopLevelAction proxyAction = null;
if (context.parents.length == 0)
theUid = Utility.otidToUid(context.current.otid);
else
theUid = Utility.otidToUid(context.parents[context.parents.length - 1].otid);
proxyAction = super.present(theUid);
if (proxyAction == null) {
/*
* Create a new proxyAction element and return the "current"
* transaction.
*/
controlPtr = createHierarchy(context, theUid);
} else {
/*
* Check hierarchy of existing element.
*/
controlPtr = checkHierarchy(proxyAction, context);
}
return controlPtr;
}
use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction in project narayana by jbosstm.
the class OSIInterposition method createHierarchy.
protected synchronized ControlImple createHierarchy(PropagationContext ctx, Uid currentUid) throws SystemException {
/*
* Start at the parent and work our way down to "current". The current
* transaction is not in the IDL sequence, but sent as separate field
* of the propagation context. This tends to make the code more
* complex than it would be if the entire hierarchy was represented in
* one place.
*/
/*
* We only ever register the current transaction with its parent, and
* as each transaction commits, it registers its parent with the
* "real" parent.
*/
int depth = ctx.parents.length;
ServerResource action = null;
Coordinator tmpCoord = null;
Terminator tmpTerm = null;
if (depth == 0) {
tmpCoord = ctx.current.coord;
tmpTerm = ctx.current.term;
} else {
tmpCoord = ctx.parents[depth - 1].coord;
tmpTerm = ctx.parents[depth - 1].term;
}
if (// terminator may correctly be NULL
tmpCoord == null) {
return null;
}
ServerControl control = ServerFactory.create_transaction(currentUid, null, null, tmpCoord, tmpTerm, ctx.timeout);
action = new ServerOSITopLevelAction(control, ((depth == 0) ? true : false));
if (!action.valid()) {
try {
// does dispose as well!
((ServerOSITopLevelAction) action).rollback();
action = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
ServerTopLevelAction newElement = (ServerOSITopLevelAction) action;
_head.add(newElement);
if (// current is a nested transaction
depth > 0) {
/*
* Now deal with any nested transactions.
* As we create, register with the original transactions.
*/
ServerResource nestedAction = null;
for (int i = depth - 2; i >= 0; i--) {
tmpCoord = ctx.parents[i].coord;
tmpTerm = ctx.parents[i].term;
control = ServerFactory.create_subtransaction(OTIDMap.find(ctx.parents[i].otid), tmpCoord, tmpTerm, control);
// not current, so don't register
nestedAction = new ServerOSINestedAction(control, false);
if (!nestedAction.valid()) {
try {
// does dispose as well!
((ServerOSINestedAction) nestedAction).rollback_subtransaction();
nestedAction = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
/*
* Add transaction resource to list.
*/
action.addChild((ServerOSINestedAction) nestedAction);
action = nestedAction;
}
/*
* Now deal with current transaction. If there is
* only one transaction we do nothing.
*/
tmpCoord = ctx.current.coord;
tmpTerm = ctx.current.term;
control = ServerFactory.create_subtransaction(OTIDMap.find(ctx.current.otid), tmpCoord, tmpTerm, control);
// current, so register
nestedAction = new ServerOSINestedAction(control, true);
if (!nestedAction.valid()) {
try {
// does dispose as well!
((ServerOSINestedAction) nestedAction).rollback_subtransaction();
nestedAction = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
action.addChild((ServerOSINestedAction) nestedAction);
}
if (jtsLogger.logger.isTraceEnabled())
compareHierarchies(ctx, newElement);
return control;
}
use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction in project narayana by jbosstm.
the class OSIInterposition method setupHierarchy.
/*
* Currently assume that formatID and otid are not a unique combination,
* i.e., if we see the same otid but with a different formatID it's
* really the same transaction.
*/
public synchronized ControlImple setupHierarchy(PropagationContext context) throws SystemException {
/*
* Map otid to a Uid.
*/
Uid theUid = OTIDMap.find(context.current.otid);
ServerTopLevelAction proxyAction = present(theUid);
ControlImple controlPtr = null;
if (proxyAction == null) {
/*
* Create a new proxyAction element and return the "current" transaction.
*/
controlPtr = createHierarchy(context, theUid);
} else {
controlPtr = checkHierarchy(proxyAction, context);
}
return controlPtr;
}
use of com.arjuna.ats.internal.jts.orbspecific.interposition.resources.arjuna.ServerTopLevelAction 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());
}
Aggregations