use of com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl in project narayana by jbosstm.
the class ServerTransaction method register_synchronization.
/**
* Registering a synchronization with interposition is a bit complicated!
* Synchronizations must be called prior to prepare; if no
* interposed-synchronization is used then either synchronizations would be
* registered locally (and then ignored by the commit protocol) or they
* would need to be registered remotely, which would mean a cross-address
* space call for each synchronization!
*
* The first time a synchronization is registered locally, we register a
* proxy back with the real coordinator. When that transaction commits, it
* will call this proxy, which will then drive the locally registered
* synchronizations (actually it calls appropriate on the transaction to do
* this.)
*
* However, one-phase commit complicates matters even more since we call
* commit on the interposed coordinator, which runs through the commit and
* then the after_completion code before returning to the real coordinator's
* commit call. Rather than separate commit and synchronization code
* completely from the transaction (in which case we could just call the
* commit portion here) we let after_completion get called before returning
* the commit response, and simply ignore the real coordinator's subsequent
* call to after_completion.
*/
public synchronized void register_synchronization(Synchronization theSync) throws Inactive, SynchronizationUnavailable, SystemException {
if (// are we a top-level transaction?
!is_top_level_transaction()) {
throw new SynchronizationUnavailable();
} else {
if (_interposedSynch) {
if (_sync == null) {
_sync = new ServerSynchronization(this);
Coordinator realCoord = null;
try {
ServerControl control = (ServerControl) super.controlHandle;
if (controlHandle != null) {
realCoord = control.originalCoordinator();
if (realCoord != null) {
realCoord.register_synchronization(_sync.getSynchronization());
} else
throw new BAD_OPERATION(ExceptionCodes.NO_TRANSACTION, CompletionStatus.COMPLETED_NO);
} else
throw new BAD_OPERATION(ExceptionCodes.NO_TRANSACTION, CompletionStatus.COMPLETED_NO);
} catch (Inactive e1) {
realCoord = null;
throw e1;
} catch (SynchronizationUnavailable e2) {
realCoord = null;
throw e2;
} catch (SystemException e3) {
realCoord = null;
throw e3;
}
realCoord = null;
}
}
/*
* Now register the synchronization locally.
*/
super.register_synchronization(theSync);
}
}
use of com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl in project narayana by jbosstm.
the class ServerControlUnitTest method test.
@Test
public void test() throws Exception {
ControlImple cont = new ControlImple(null, null);
Control theControl = cont.getControl();
ArjunaTransactionImple tx = cont.getImplHandle();
ServerControl sc = new ServerControl(tx.get_uid(), theControl, tx, theControl.get_coordinator(), theControl.get_terminator());
assertTrue(sc.isWrapper());
assertTrue(sc.get_coordinator() != null);
assertTrue(sc.get_terminator() != null);
assertEquals(sc.getParentImple(), null);
assertTrue(sc.forgetHeuristics());
assertTrue(sc.toString() != null);
sc.destroy();
}
use of com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl in project narayana by jbosstm.
the class ServerNestedOSIActionUnitTest method testCommit.
@Test
public void testCommit() throws Exception {
ControlImple cont = new ControlImple(null, null);
Control theControl = cont.getControl();
ArjunaTransactionImple tx = cont.getImplHandle();
ServerControl sc = new ServerControl(tx.get_uid(), theControl, tx, theControl.get_coordinator(), theControl.get_terminator());
ServerOSINestedAction act = new ServerOSINestedAction(sc, true);
assertFalse(act.interposeResource());
act.commit_subtransaction(null);
}
use of com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl in project narayana by jbosstm.
the class ServerFactory method create_subtransaction.
public static ServerControl create_subtransaction(Uid actUid, Coordinator realCoord, Terminator realTerm, ServerControl parent) {
if (parent == null) {
jtsLogger.i18NLogger.warn_interposition_sfnoparent("ServerFactory.create_subtransaction");
return null;
}
ServerControl toReturn = null;
try {
Control handle = parent.getControl();
ArjunaTransactionImple tranHandle = parent.getImplHandle();
toReturn = new ServerControl(actUid, handle, tranHandle, realCoord, realTerm);
handle = null;
tranHandle = null;
} catch (Exception e) {
if (toReturn != null) {
try {
// will delete itself
toReturn.destroy();
} catch (Exception ex) {
}
}
}
return toReturn;
}
use of com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl in project narayana by jbosstm.
the class Interposition method checkHierarchy.
/*
* In a single threaded environment we could walk down the hierarchy,
* aborting any actions which are no longer valid, and creating any new
* ones. However, in a multi-threaded environment, a thread can make a
* call from any point in the client's hierarchy, and multiple client
* threads can invoke the same server object. So, in general we cannot do
* this optimisation. We must maintain the entire tree until portions of
* it have explicitly been termined.
*
* Once we find the point in the new hierarchy which deviates from our
* current representation, we begin to assemble a new subtree in much the
* same way as we did for creating a completely new hierarchy.
*/
protected synchronized ControlImple checkHierarchy(ServerTopLevelAction hier, PropagationContext context) throws SystemException {
ServerControl control = null;
// top-level transaction
ServerResource currentAction = hier;
int depth = context.parents.length;
// index of the new transactions in the hierarchy
int differenceIndex = -1;
if (depth == 0) {
/*
* There are no transactions in the context other than the current
* transaction, which must therefore be top-level. We already have
* the control to return.
*/
// top-level transaction's control
control = hier.control();
} else {
ServerResource nestedAction = null;
for (// don't check depth-1 as it is current action!
int i = depth - 2; // don't check depth-1 as it is current action!
i >= 0; // don't check depth-1 as it is current action!
i--) {
nestedAction = currentAction.getChild(Utility.otidToUid(context.parents[i].otid));
if (// point of difference, so stop trawling hierarchy
nestedAction == null) {
// remember for later so that we can add new actions.
differenceIndex = i;
break;
} else {
/*
* currentAction *always* points to the last known
* good transaction in our hierarchy.
*/
currentAction = nestedAction;
}
}
if (differenceIndex != -1) {
control = currentAction.control();
Coordinator tmpCoord;
Terminator tmpTerm;
for (int j = differenceIndex; j >= 0; j--) {
tmpCoord = context.parents[j].coord;
tmpTerm = context.parents[j].term;
control = ServerFactory.create_subtransaction(Utility.otidToUid(context.parents[j].otid), tmpCoord, tmpTerm, control);
nestedAction = new ServerNestedAction(control);
if (!nestedAction.valid()) {
try {
// does dispose as well!
((ServerNestedAction) nestedAction).rollback();
nestedAction = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
currentAction.addChild((ServerNestedAction) nestedAction);
currentAction = nestedAction;
}
} else {
/*
* Hierarchies may be identical.
* Remember to check!
*/
}
Uid currentUid = Utility.otidToUid(context.current.otid);
/*
* currentAction points to the parent of the 'current'
* transaction, i.e., the last element in the TransIdentity
* structure. So, ask it if the sent hierarchy's child is
* one of its children.
*/
nestedAction = currentAction.getChild(currentUid);
if (nestedAction == null) {
/*
* Different notion of current in sent hierarchy.
* So, add it to the hierarchy here.
*/
control = currentAction.control();
/*
* Now deal with the current transaction.
*/
TransIdentity currentID = context.current;
control = ServerFactory.create_subtransaction(currentUid, currentID.coord, currentID.term, control);
nestedAction = new ServerNestedAction(control);
if (!nestedAction.valid()) {
try {
// does dispose as well!
((ServerNestedAction) nestedAction).rollback();
nestedAction = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
currentAction.addChild((ServerNestedAction) nestedAction);
} else {
/*
* Same current, so get its control and return it.
*/
control = nestedAction.control();
}
}
if (jtsLogger.logger.isTraceEnabled())
compareHierarchies(context, hier);
return control;
}
Aggregations