use of com.arjuna.ArjunaOTS.ActionControl in project narayana by jbosstm.
the class OTSManager method destroyControl.
/**
* Destroy the transaction control.
*/
public static void destroyControl(Control control) throws ActiveTransaction, ActiveThreads, BadControl, Destroyed, SystemException {
if (control == null)
throw new BadControl();
ControlImple lCont = Helper.localControl(control);
if (lCont != null) {
destroyControl(lCont);
} else {
/*
* Just in case control is a top-level transaction, and has
* been registered with the reaper, we need to get it removed.
*
*/
Coordinator coord = null;
try {
coord = control.get_coordinator();
} catch (Exception e) {
// nothing else we can do!
coord = null;
}
if (coord != null) {
try {
if (coord.is_top_level_transaction()) {
// wrap the control so it gets compared against reaper list entries using the correct test
PseudoControlWrapper wrapper = new PseudoControlWrapper(control);
TransactionReaper.transactionReaper().remove(wrapper);
}
} catch (Exception e) {
}
coord = null;
}
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("OTS::destroyControl - remote control.");
}
/*
* Remote transaction, so memory management is different!
*/
ActionControl action = null;
try {
action = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(control);
if (action == null)
throw new BAD_PARAM();
} catch (Exception e) {
action = null;
}
if (action != null) {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("OTS::destroyControl - Arjuna control.");
}
/*
* Is an Arjuna control, so we can call destroy on it?
*/
action.destroy();
action = null;
control = null;
} else {
/*
* Just call release on the control.
*
* We could throw a BadControl exception, but
* what would that do for the programmer?
*/
control = null;
}
}
}
use of com.arjuna.ArjunaOTS.ActionControl in project narayana by jbosstm.
the class ContextManagerUnitTest method testContextManager.
@Test
public void testContextManager() throws Exception {
ContextManager manager = new ContextManager();
assertEquals(manager.current(Thread.currentThread().getName()), null);
assertEquals(manager.current(), null);
OTSImpleManager.current().begin();
manager.associate();
OTSImpleManager.current().suspend();
OTSImpleManager.current().begin();
Control ct = OTSImpleManager.current().suspend();
manager.addRemoteHierarchy(ct);
manager.popAction();
OTSImpleManager.current().suspend();
OTSImpleManager.current().begin();
ActionControl cont = (ActionControl) OTSImpleManager.current().getControlWrapper().getImple().getControl();
manager.addActionControlHierarchy(cont);
manager.purgeActions();
OTSImpleManager.current().suspend();
OTSImpleManager.current().begin();
manager.addControlImpleHierarchy(OTSImpleManager.current().getControlWrapper().getImple());
manager.purgeActions();
OTSImpleManager.current().suspend();
}
use of com.arjuna.ArjunaOTS.ActionControl in project narayana by jbosstm.
the class ContextManager method addActionControlHierarchy.
/*
* All OTSArjuna controls have a method for getting their parent.
*/
public final boolean addActionControlHierarchy(ActionControl cont) {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ContextManager::addActionControlHierarchy ()");
}
boolean isError = false;
try {
ActionControl actControl = cont;
Control parentControl = actControl.getParentControl();
Stack hier = new Stack();
while (parentControl != null) {
hier.push(new ControlWrapper(parentControl));
actControl = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(parentControl);
if (actControl != null)
parentControl = actControl.getParentControl();
else
parentControl = null;
}
actControl = null;
try {
ControlWrapper wrapper = (ControlWrapper) hier.pop();
while (wrapper != null) {
pushAction(wrapper);
wrapper = null;
wrapper = (ControlWrapper) hier.pop();
}
} catch (EmptyStackException e) {
}
} catch (Exception e) {
jtsLogger.i18NLogger.warn_context_genfail("ContextManager.addActionControlHierarchy", e);
isError = true;
}
return isError;
}
use of com.arjuna.ArjunaOTS.ActionControl in project narayana by jbosstm.
the class CurrentImple method resume.
/**
* To support checked transactions we can only resume if the action is local
* or we received it implicitly.
*
* If the control refers to a nested transaction then we must recreate the
* entire hierarchy, i.e., the effect of a suspend/resume on the same
* control should be the same as never calling suspend in the first place.
*
* If the control is for a local transaction then it is simple to recreate
* the hierarchy. Otherwise we rely upon the PropagationContext to recreate
* it.
*
* If this control is a "proxy" then create a new proxy instance, so we can
* delete proxies whenever suspend is called.
*
* Should check if "new" transaction is not actually the current one anyway.
* If so, just return. The spec. doesn't mention what to do in this case, so
* for now we go to the overhead of the work regardless.
*/
public void resume(Control which) throws InvalidControl, SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("CurrentImple::resume ( " + which + " )");
}
/*
* We must now "forget" any current transaction information. This is
* because when we end this transaction we must be associated with no
* transaction.
*/
_theManager.purgeActions();
if (// if null then return
which == null) {
ThreadAssociationControl.updateAssociation(null, TX_RESUMED);
return;
}
/*
* Must duplicate because it is an 'in' parameter which we want to keep.
*/
org.omg.CosTransactions.Control cont = which;
boolean invalidControl = false;
try {
Coordinator coord = cont.get_coordinator();
if (!coord.is_top_level_transaction()) {
/*
* Is the Control an ActionControl? If so then it has methods to
* allow us to get the parent directly. Otherwise, rely on the
* PropagationContext.
*/
ActionControl actControl = null;
try {
actControl = com.arjuna.ArjunaOTS.ActionControlHelper.narrow(cont);
if (actControl == null)
throw new BAD_PARAM();
} catch (Exception e) {
/*
* Not an ActionControl.
*/
actControl = null;
}
if (actControl != null) {
invalidControl = _theManager.addActionControlHierarchy(actControl);
} else {
invalidControl = _theManager.addRemoteHierarchy(cont);
}
}
coord = null;
} catch (OBJECT_NOT_EXIST one) {
// throw new InvalidControl();
} catch (// JacORB 1.4.5 bug
UNKNOWN ue) {
} catch (// JacORB 2.0 beta 2 bug
org.omg.CORBA.OBJ_ADAPTER oae) {
} catch (SystemException sysEx) {
throw new InvalidControl();
} catch (UserException usrEx) {
throw new InvalidControl();
} catch (NullPointerException npx) {
throw new InvalidControl();
} catch (Exception ex) {
throw new BAD_OPERATION("CurrentImple.resume: " + ex.toString());
}
try {
if (!invalidControl) {
ControlWrapper wrap = new ControlWrapper(cont);
ThreadAssociationControl.updateAssociation(wrap, TX_RESUMED);
_theManager.pushAction(wrap);
}
} catch (NullPointerException npx) {
invalidControl = true;
}
cont = null;
if (invalidControl)
throw new InvalidControl();
}
use of com.arjuna.ArjunaOTS.ActionControl 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;
}
Aggregations