use of org.omg.CosTransactions.TransIdentity 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;
}
use of org.omg.CosTransactions.TransIdentity in project narayana by jbosstm.
the class RestrictedInterposition method checkHierarchy.
/*
* Work our way down the hierarchy, aborting any actions which are no longer
* valid, and creating any new ones. These new actions must be nested
* actions.
*/
protected synchronized ControlImple checkHierarchy(ServerTopLevelAction hier, PropagationContext context) throws SystemException {
ServerRestrictedTopLevelAction tlAction = (ServerRestrictedTopLevelAction) hier;
// top-level's control
ServerControl control = tlAction.control();
int depth = context.parents.length;
// index of the new transactions in the
int differenceIndex = -1;
// hierarchy
// top-level
ServerRestrictedNestedAction nestedAction = tlAction.child();
if (depth == 0) {
if (nestedAction != null) {
// automatically removed from
tlAction.abortChild(nestedAction);
// resource list
nestedAction = null;
control = tlAction.deepestControl();
}
} else {
for (int i = depth - 2; (i >= 0) && (nestedAction != null); i--) {
if (nestedAction.get_uid().equals(Utility.otidToUid(context.parents[i].otid))) {
/*
* nestedActionalways points to the next transaction in the
* hierarchy when we leave this loop.
*/
nestedAction = nestedAction.child();
if ((nestedAction == null) && (i > 0)) {
differenceIndex = i - 1;
control = tlAction.deepestControl();
}
} else {
/*
* Uids not equal, so abort. No need to continue down the
* hierarchy, as aborting from this point will implicitly
* abort out children.
*/
// remember for later so that we can
differenceIndex = i;
// add new actions.
tlAction.abortChild(nestedAction);
nestedAction = null;
control = tlAction.deepestControl();
break;
}
}
if (differenceIndex != -1) {
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 ServerRestrictedNestedAction(control);
if (!nestedAction.valid()) {
try {
// does dispose as well!
nestedAction.rollback();
nestedAction = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
tlAction.addChild(nestedAction);
}
nestedAction = null;
} else {
if (nestedAction != null) {
/*
* If current transaction has a child then we should abort
* it, since it does not exist in the hierarchy we have just
* received.
*/
nestedAction = nestedAction.child();
if (nestedAction != null) {
tlAction.abortChild(nestedAction);
nestedAction = null;
control = tlAction.deepestControl();
}
}
}
}
boolean newCurrent = false;
Uid sentCurrent = Utility.otidToUid(context.current.otid);
if (differenceIndex == -1) {
/*
* Now determine whether we have to create any new nested actions.
*/
Uid currentUid = null;
if (nestedAction == null) {
nestedAction = tlAction.child();
if (nestedAction != null) {
while (nestedAction.child() != null) nestedAction = nestedAction.child();
currentUid = nestedAction.get_uid();
} else
currentUid = tlAction.get_uid();
} else
currentUid = nestedAction.get_uid();
if (currentUid.notEquals(sentCurrent)) {
newCurrent = true;
}
} else
newCurrent = true;
if (newCurrent) {
if (depth == 1) {
/*
* Old current is gone.
*/
nestedAction = tlAction.child();
if (nestedAction != null) {
tlAction.abortChild(nestedAction);
nestedAction = null;
}
control = (ServerControl) tlAction.control();
} else
control = tlAction.deepestControl();
TransIdentity currentID = context.current;
control = ServerFactory.create_subtransaction(sentCurrent, currentID.coord, currentID.term, control);
nestedAction = new ServerRestrictedNestedAction(control);
if (!nestedAction.valid()) {
try {
// does dispose as well!
nestedAction.rollback();
nestedAction = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
tlAction.addChild(nestedAction);
nestedAction = null;
}
return control;
}
use of org.omg.CosTransactions.TransIdentity in project narayana by jbosstm.
the class ArjunaTransactionImple method propagationContext.
/*
* The caller should delete the context.
*
* The propagation context is specified on a per client thread basis.
* Therefore, at the server side we must maintain a hierarchy for each
* thread. However, the server cannot simply tear down this hierarchy
* whenever it receives a completely new one from the same thread, since the
* OTS lets a thread suspend/resume contexts at will. Potential for memory
* leaks in C++ version, but not Java!!
*
* Currently we assume that the hierarchy will be JBoss transactions so we
* can get the parents of transactions. If it is not then we could simply
* just call get_txcontext on the control!
*/
private final PropagationContext propagationContext() throws Unavailable, Inactive, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::propagationContext for " + get_uid());
}
String theUid = null;
Control currentControl = controlHandle.getControl();
PropagationContext context = new PropagationContext();
// most transactions will be top-level
int sequenceThreshold = 1;
int sequenceIncrement = 5;
context.parents = null;
context.current = new TransIdentity();
// uughh!!
context.implementation_specific_data = ORBManager.getORB().orb().create_any();
/*
* Some ORBs (e.g., JBroker) don't like to pass round an unused Any,
* i.e., one which has only been created and had nothing put in it! So
* we have to put something in it!!
*/
context.implementation_specific_data.insert_short((short) 0);
try {
context.current.coord = controlHandle.get_coordinator();
// will reset later!
context.timeout = 0;
if (ArjunaTransactionImple._propagateTerminator) {
context.current.term = controlHandle.get_terminator();
} else
context.current.term = null;
} catch (Exception e) {
return null;
}
/*
* We send the Uid hierarchy as the otid_t part of the TransIdentity.
*/
// the sequence should do the memory management for us.
theUid = controlHandle.get_uid().stringForm();
context.current.otid = Utility.uidToOtid(theUid);
context.current.otid.formatID = ArjunaTransactionImple._ipType;
int index = 0;
while (currentControl != null) {
try {
ActionControl control = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(currentControl);
if (control != null) {
/*
* Must be an Arjuna control.
*/
currentControl = control.getParentControl();
if (currentControl != null) {
if (// first time
index == 0) {
// initial
context.parents = new TransIdentity[sequenceThreshold];
for (int ii = 0; ii < sequenceThreshold; ii++) context.parents[ii] = null;
}
context.parents[index] = new TransIdentity();
context.parents[index].coord = currentControl.get_coordinator();
if (ArjunaTransactionImple._propagateTerminator)
context.parents[index].term = currentControl.get_terminator();
else
context.parents[index].term = null;
/*
* Don't bother checking whether narrow works because we
* can't cope with mixed transaction types anyway! If we
* got here then the root transaction must be an Arjuna
* transaction, so the nested transactions *must* also
* be JBoss transactions!
*/
UidCoordinator uidCoord = Helper.getUidCoordinator(context.parents[index].coord);
theUid = uidCoord.uid();
context.parents[index].otid = Utility.uidToOtid(theUid);
context.parents[index].otid.formatID = ArjunaTransactionImple._ipType;
theUid = null;
uidCoord = null;
index++;
if (index >= sequenceThreshold) {
sequenceThreshold = index + sequenceIncrement;
context.parents = resizeHierarchy(context.parents, index + sequenceIncrement);
}
} else {
if (_propagateRemainingTimeout) {
long timeInMills = TransactionReaper.transactionReaper().getRemainingTimeoutMills(control);
context.timeout = (int) (timeInMills / 1000L);
} else {
context.timeout = TransactionReaper.transactionReaper().getTimeout(control);
}
}
control = null;
} else
throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
} catch (SystemException e) {
/*
* Not an Arjuna control!! Should not happen!!
*/
currentControl = null;
} catch (Exception e) {
e.printStackTrace();
currentControl = null;
}
}
try {
context.parents = resizeHierarchy(context.parents, index);
} catch (Exception e) {
jtsLogger.i18NLogger.warn_orbspecific_coordinator_generror("ArjunaTransactionImple.resizeHierarchy", e);
context = null;
}
return context;
}
use of org.omg.CosTransactions.TransIdentity in project narayana by jbosstm.
the class OSIInterposition 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.
*/
/*
* Also we would like to just register one resource to represent the entire
* hierarchy, but this has problems: since threads can invoke operations at
* any point in a hierarchy, we end up with multiple resources at top-level
* for the same transaction. Each will try to commit the top-level
* transaction!
* In this implementation, the first to do so will garbage collect the root
* of the hierarchy, and probably cause the subsequent ones to fail! There
* is also the problem with many cross-process calls for the *same*
* transaction.
* So, we register *one* resource for each level of the hierarchy *when it
* is required*, i.e., as the previous transaction terminates, and remove
* terminated transaction resources when they occur. This means that at
* top-level we only have a single resource to commit. There are the same
* number of cross-process invocations. However, we also maintain the
* entire hierarchy at the server, so if it makes subsequent invocations,
* the right hierarchy gets sent out!
*/
protected synchronized ControlImple checkHierarchy(ServerTopLevelAction hier, PropagationContext context) {
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. However, make sure it has registered
* itself with the "real" transaction.
*/
ServerOSITopLevelAction tx = (ServerOSITopLevelAction) hier;
tx.interposeResource();
// top-level transaction's control
control = tx.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(OTIDMap.find(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 = null;
Terminator tmpTerm = null;
for (int j = differenceIndex; j >= 0; j--) {
tmpCoord = context.parents[j].coord;
tmpTerm = context.parents[j].term;
control = ServerFactory.create_subtransaction(OTIDMap.find(context.parents[j].otid), tmpCoord, tmpTerm, control);
nestedAction = new ServerOSINestedAction(control, false);
if (!nestedAction.valid()) {
try {
// does dispose as well!
((ServerOSINestedAction) nestedAction).rollback();
nestedAction = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
currentAction.addChild((ServerOSINestedAction) nestedAction);
currentAction = nestedAction;
}
} else {
/*
* Hierarchies may be identical.
* Remember to check!
*/
}
Uid currentUid = OTIDMap.find(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 ServerOSINestedAction(control, true);
if (!nestedAction.valid()) {
try {
// does dispose as well!
((ServerOSINestedAction) nestedAction).rollback();
nestedAction = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
currentAction.addChild((ServerOSINestedAction) nestedAction);
} else {
/*
* Same current, so get its control and return it.
* Remember to make sure it has registered itself with
* the "real" transaction.
*/
nestedAction.interposeResource();
control = nestedAction.control();
}
}
if (jtsLogger.logger.isTraceEnabled())
compareHierarchies(context, hier);
return control;
}
use of org.omg.CosTransactions.TransIdentity in project narayana by jbosstm.
the class StrictInterposition 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.
*/
/*
* Also we would like to just register one resource to represent the entire
* hierarchy, but this has problems: since threads can invoke operations at
* any point in a hierarchy, we end up with multiple resources at top-level
* for the same transaction. Each will try to commit the top-level transaction!
* In this implementation, the first to do so will garbage collect the root
* of the hierarchy, and probably cause the subsequent ones to fail! There is
* also the problem with many cross-process calls for the *same* transaction.
* So, we register *one* resource for each level of the hierarchy *when it is
* required*, i.e., as the previous transaction terminates, and remove
* terminated transaction resources when they occur. This means that at
* top-level we only have a single resource to commit. There are the same
* number of cross-process invocations. However, we also maintain the entire
* hierarchy at the server, so if it makes subsequent invocations, the right
* hierarchy gets sent out!
*/
protected synchronized ControlImple checkHierarchy(ServerTopLevelAction hier, PropagationContext context) {
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. However, make sure it has registered
* itself with the "real" transaction.
*/
ServerStrictTopLevelAction tx = (ServerStrictTopLevelAction) hier;
tx.interposeResource();
// top-level transaction's control
control = tx.control();
} else {
ServerResource nestedAction = null;
for (// don't check depth-1 as it is current action!
int i = (int) 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 = null;
Terminator tmpTerm = null;
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 ServerStrictNestedAction(control, false);
if (!nestedAction.valid()) {
try {
// does dispose as well!
((ServerStrictNestedAction) nestedAction).rollback();
nestedAction = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
currentAction.addChild((ServerStrictNestedAction) 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 ServerStrictNestedAction(control, true);
if (!nestedAction.valid()) {
try {
// does dispose as well!
((ServerStrictNestedAction) nestedAction).rollback();
nestedAction = null;
} catch (Exception e) {
}
throw new TRANSACTION_ROLLEDBACK();
}
currentAction.addChild((ServerStrictNestedAction) nestedAction);
} else {
/*
* Same current, so get its control and return it.
* Remember to make sure it has registered itself with
* the "real" transaction.
*/
nestedAction.interposeResource();
control = nestedAction.control();
}
}
if (jtsLogger.logger.isTraceEnabled())
compareHierarchies(context, hier);
return control;
}
Aggregations