use of com.arjuna.ArjunaOTS.UidCoordinator in project narayana by jbosstm.
the class ArjunaTransactionImple method is_related_transaction.
public boolean is_related_transaction(Coordinator tc) throws SystemException {
if (tc == null)
return false;
boolean result = false;
try {
UidCoordinator ptr = com.arjuna.ArjunaOTS.UidCoordinatorHelper.narrow(tc);
if (ptr != null) {
/*
* Must be an Arjuna coordinator.
*/
/*
* If they have the same parent, then they must be related.
*/
String myTLUid = topLevelUid();
String compareTLUid = ptr.topLevelUid();
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::is_related_transaction comparing uids < " + compareTLUid + ", " + myTLUid + " >");
}
if (myTLUid.compareTo(compareTLUid) == 0)
result = true;
myTLUid = null;
compareTLUid = null;
ptr = null;
} else
throw new BAD_PARAM();
} catch (SystemException e) {
/*
* Narrow failed, so can't be an Arjuna Uid. Therefore, the answer
* must be false.
*/
}
return result;
}
use of com.arjuna.ArjunaOTS.UidCoordinator in project narayana by jbosstm.
the class Helper method localControl.
public static final ControlImple localControl(org.omg.CosTransactions.Control control) {
if (control == null)
return null;
if (control instanceof ControlImple)
return (ControlImple) control;
try {
UidCoordinator uidCoord = Helper.getUidCoordinator(control);
if (uidCoord != null) {
Uid u = Helper.getUid(uidCoord);
ControlImple toReturn = null;
uidCoord = null;
if (ControlImple.allControls != null) {
synchronized (ControlImple.allControls) {
toReturn = (ControlImple) ControlImple.allControls.get(u);
}
}
if (toReturn == null) {
if (ServerControl.allServerControls != null) {
synchronized (ServerControl.allServerControls) {
toReturn = (ControlImple) ServerControl.allServerControls.get(u);
}
}
}
u = null;
return toReturn;
} else
throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
} catch (Exception e) {
/*
* Can't be an Arjuna action, so ignore.
*/
}
return null;
}
use of com.arjuna.ArjunaOTS.UidCoordinator in project narayana by jbosstm.
the class Helper method getUidCoordinator.
public static final UidCoordinator getUidCoordinator(org.omg.CosTransactions.Control control) {
if (control == null)
return null;
UidCoordinator toReturn = null;
try {
Coordinator coord = control.get_coordinator();
if (coord != null) {
toReturn = getUidCoordinator(coord);
coord = null;
} else
throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
} catch (Exception e) {
/*
* Can't be an Arjuna action, so ignore.
*/
toReturn = null;
}
return toReturn;
}
use of com.arjuna.ArjunaOTS.UidCoordinator 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 com.arjuna.ArjunaOTS.UidCoordinator in project narayana by jbosstm.
the class ArjunaTransactionImple method is_descendant_transaction.
/**
* Is this transaction a descendant of tc?
*/
public boolean is_descendant_transaction(Coordinator tc) throws SystemException {
if (tc == null)
return false;
try {
UidCoordinator ptr = com.arjuna.ArjunaOTS.UidCoordinatorHelper.narrow(tc);
if (ptr != null) {
/*
* Must be an Arjuna coordinator.
*/
Uid lookingFor = new Uid(ptr.uid());
BasicAction lookingAt = this;
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::is_descendant_transaction - looking for " + lookingFor);
}
while (lookingAt != null) {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::is_descendant_transaction - looking for " + lookingAt.get_uid());
}
if (lookingAt.get_uid().equals(lookingFor))
return true;
else
lookingAt = lookingAt.parent();
}
ptr = null;
} else
throw new BAD_PARAM();
} catch (SystemException e) {
/*
* Narrow failed, so can't be an Arjuna Uid. Therefore, the answer
* must be false.
*/
}
return false;
}
Aggregations